Added more components + added item palette reference

This commit is contained in:
Anon 2024-09-11 20:35:23 +02:00
parent 76e873ed54
commit 49319fe781
44 changed files with 667 additions and 29 deletions

View file

@ -445,18 +445,20 @@ namespace MinecraftClient.Protocol.Handlers
{
var componentTypeId = ReadNextVarInt(cache);
var strcuturedComponentHandler = new StructuredComponentsHandler(protocolversion, this);
var strcuturedComponentHandler = new StructuredComponentsHandler(protocolversion, this, itemPalette);
strcturedComponentsToAdd.Add(strcuturedComponentHandler.Parse(componentTypeId, cache));
}
for (var i = 0; i < numberofComponentsToRemove; i++)
{
// TODO
// TODO: Check what this does exactly
ReadNextVarInt(cache); // The type of component to remove
}
// TODO: Wire up the strctured components in the Item class (extract info, update fields, etc..)
// Use strcturedComponentsToAdd
// Look at: https://wiki.vg/index.php?title=Slot_Data&oldid=19350#Structured_components
return item;
case >= Protocol18Handler.MC_1_13_Version:
{
@ -1537,6 +1539,8 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns>Item slot representation</returns>
public byte[] GetItemSlot(Item? item, ItemPalette itemPalette)
{
// TODO: Wire up Structured components for 1.20.6
List<byte> slotData = new();
if (protocolversion > Protocol18Handler.MC_1_13_Version)
{

View file

@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class AttributeModifiersComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class AttributeModifiersComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int NumberOfAttributes { get; set; }
public List<AttributeSubComponent1206> Attributes { get; set; } = new();
@ -27,8 +29,8 @@ public class AttributeModifiersComponent1206(DataTypes dataTypes, SubComponentRe
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(NumberOfAttributes));
if(NumberOfAttributes > 0 && Attributes.Count == 0)
throw new ArgumentNullException($"Can not serialize a AttributeModifiersComponent when the Attributes is empty but NumberOfAttributes is > 0!");
if(Attributes.Count != NumberOfAttributes)
throw new ArgumentNullException($"Can not serialize a AttributeModifiersComponent when the Attributes count != NumberOfAttributes!");
foreach (var attribute in Attributes)
data.AddRange(attribute.Serialize());

View file

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MinecraftClient.Inventory;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class BundleContentsComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int NumberOfItems { get; set; }
public List<Item?> Items { get; set; } = [];
public override void Parse(Queue<byte> data)
{
NumberOfItems = dataTypes.ReadNextVarInt(data);
for (var i = 0; i < NumberOfItems; i++)
Items.Add(dataTypes.ReadNextItemSlot(data, itemPalette));
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(NumberOfItems));
if (NumberOfItems != Items.Count)
throw new ArgumentNullException($"Cannot serialize BundleContentsComponent1206 because NumberOfItems != Items.Count!");
foreach (var item in Items.OfType<Item>())
data.AddRange(DataTypes.GetItemSlot(item, itemPalette));
return new Queue<byte>(data);
}
}

View file

@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class CanBreakComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class CanBreakComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int NumberOfPredicates { get; set; }
public List<BlockPredicateSubcomponent1206> BlockPredicates { get; set; } = new();

View file

@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class CanPlaceOnComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class CanPlaceOnComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int NumberOfPredicates { get; set; }
public List<BlockPredicateSubcomponent1206> BlockPredicates { get; set; } = new();

View file

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MinecraftClient.Inventory;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class ChargedProjectilesComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int NumberOfItems { get; set; }
public List<Item?> Items { get; set; } = [];
public override void Parse(Queue<byte> data)
{
NumberOfItems = dataTypes.ReadNextVarInt(data);
for (var i = 0; i < NumberOfItems; i++)
Items.Add(dataTypes.ReadNextItemSlot(data, itemPalette));
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(NumberOfItems));
if (NumberOfItems != Items.Count)
throw new ArgumentNullException($"Cannot serialize ChargedProjectilesComponent1206 because NumberOfItems != Items.Count!");
foreach (var item in Items.OfType<Item>())
data.AddRange(DataTypes.GetItemSlot(item, itemPalette));
return new Queue<byte>(data);
}
}

View file

@ -0,0 +1,8 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class CreativeSlotLockComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: EmptyComponent(dataTypes, itemPalette, subComponentRegistry);

View file

@ -1,9 +1,11 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class CustomDataComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class CustomDataComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public Dictionary<string, object>? Nbt { get; set; } = new();

View file

@ -1,9 +1,10 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class CustomModelDataComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class CustomModelDataComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int Value { get; set; }

View file

@ -1,10 +1,12 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
using MinecraftClient.Protocol.Message;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class CustomNameComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class CustomNameComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public string CustomName { get; set; } = string.Empty;

View file

@ -1,9 +1,11 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class DamageComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class DamageComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int Damage { get; set; }

View file

@ -0,0 +1,26 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class DyeColorComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int Color { get; set; }
public bool ShowInTooltip { get; set; }
public override void Parse(Queue<byte> data)
{
Color = dataTypes.ReadNextInt(data);
ShowInTooltip = dataTypes.ReadNextBool(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetInt(Color));
data.AddRange(DataTypes.GetBool(ShowInTooltip));
return new Queue<byte>(data);
}
}

View file

@ -0,0 +1,23 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class EnchantmentGlintOverrideComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int HasGlint { get; set; }
public override void Parse(Queue<byte> data)
{
HasGlint = dataTypes.ReadNextVarInt(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(HasGlint));
return new Queue<byte>(data);
}
}

View file

@ -1,10 +1,12 @@
using System.Collections.Generic;
using MinecraftClient.Inventory;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class EnchantmentsComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class EnchantmentsComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int NumberOfEnchantments { get; set; }
public List<Enchantment> Enchantments { get; set; } = new();

View file

@ -0,0 +1,7 @@
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class FireResistantComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: EmptyComponent(dataTypes, itemPalette, subComponentRegistry);

View file

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class FoodComponentComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int Nutrition { get; set; }
public bool Saturation { get; set; }
public bool CanAlwaysEat { get; set; }
public float SecondsToEat { get; set; }
public int NumberOfEffects { get; set; }
public List<EffectSubComponent1206> Effects { get; set; } = new();
public override void Parse(Queue<byte> data)
{
Nutrition = dataTypes.ReadNextVarInt(data);
Saturation = dataTypes.ReadNextBool(data);
CanAlwaysEat = dataTypes.ReadNextBool(data);
SecondsToEat = dataTypes.ReadNextFloat(data);
NumberOfEffects = dataTypes.ReadNextVarInt(data);
for(var i = 0; i < NumberOfEffects; i++)
Effects.Add((EffectSubComponent1206)subComponentRegistry.ParseSubComponent(SubComponents.Effect, data));
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(Nutrition));
data.AddRange(DataTypes.GetBool(Saturation));
data.AddRange(DataTypes.GetBool(CanAlwaysEat));
data.AddRange(DataTypes.GetFloat(SecondsToEat));
data.AddRange(DataTypes.GetFloat(NumberOfEffects));
if (NumberOfEffects > 0)
{
if(Effects.Count != NumberOfEffects)
throw new ArgumentNullException($"Can not serialize FoodComponent1206 due to NumberOfEffcets being different from the count of elements in the Effects list!");
foreach(var effect in Effects)
data.AddRange(effect.Serialize());
}
return new Queue<byte>(data);
}
}

View file

@ -1,5 +1,7 @@
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class HideAdditionalTooltipComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : EmptyComponent(dataTypes, subComponentRegistry);
public class HideAdditionalTooltipComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: EmptyComponent(dataTypes, itemPalette, subComponentRegistry);

View file

@ -1,5 +1,7 @@
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class HideTooltipComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : EmptyComponent(dataTypes, subComponentRegistry);
public class HideTooltipComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: EmptyComponent(dataTypes, itemPalette, subComponentRegistry);

View file

@ -0,0 +1,23 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class IntangibleProjectileComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public Dictionary<string, object>? Nbt { get; set; } = new();
public override void Parse(Queue<byte> data)
{
Nbt = dataTypes.ReadNextNbt(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetNbt(Nbt));
return new Queue<byte>(data);
}
}

View file

@ -1,10 +1,12 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
using MinecraftClient.Protocol.Message;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class ItemNameComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class ItemNameComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public string ItemName { get; set; } = string.Empty;

View file

@ -1,10 +1,12 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
using MinecraftClient.Protocol.Message;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class LoreNameComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class LoreNameComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int NumberOfLines { get; set; }
public List<string> Lines { get; set; } = [];

View file

@ -0,0 +1,23 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class MapColorComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int Id { get; set; }
public override void Parse(Queue<byte> data)
{
Id = dataTypes.ReadNextInt(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetInt(Id));
return new Queue<byte>(data);
}
}

View file

@ -0,0 +1,23 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class MapDecorationsComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public Dictionary<string, object>? Nbt { get; set; } = new();
public override void Parse(Queue<byte> data)
{
Nbt = dataTypes.ReadNextNbt(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetNbt(Nbt));
return new Queue<byte>(data);
}
}

View file

@ -0,0 +1,23 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class MapIdComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int Id { get; set; }
public override void Parse(Queue<byte> data)
{
Id = dataTypes.ReadNextVarInt(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(Id));
return new Queue<byte>(data);
}
}

View file

@ -0,0 +1,23 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class MapPostProcessingComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int Type { get; set; }
public override void Parse(Queue<byte> data)
{
Type = dataTypes.ReadNextVarInt(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(Type));
return new Queue<byte>(data);
}
}

View file

@ -1,9 +1,11 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class MaxDamageComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class MaxDamageComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int MaxDamage { get; set; }

View file

@ -1,9 +1,11 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class MaxStackSizeComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class MaxStackSizeComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int MaxStackSize { get; set; }

View file

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class PotionContentsComponentComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int PotiononId { get; set; }
public bool HasCustomColor { get; set; }
public int CustomColor { get; set; }
public int NumberOfCustomEffects { get; set; }
public List<PotionEffectSubComponent1206> Effects { get; set; } = new();
public override void Parse(Queue<byte> data)
{
PotiononId = dataTypes.ReadNextVarInt(data);
HasCustomColor = dataTypes.ReadNextBool(data);
CustomColor = dataTypes.ReadNextInt(data);
NumberOfCustomEffects = dataTypes.ReadNextVarInt(data);
for(var i = 0; i < NumberOfCustomEffects; i++)
Effects.Add((PotionEffectSubComponent1206)subComponentRegistry.ParseSubComponent(SubComponents.PotionEffect, data));
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(PotiononId));
data.AddRange(DataTypes.GetBool(HasCustomColor));
data.AddRange(DataTypes.GetInt(CustomColor));
if (NumberOfCustomEffects > 0)
{
if(Effects.Count != NumberOfCustomEffects)
throw new ArgumentNullException($"Can not serialize PotionContentsComponentComponent1206 due to NumberOfCustomEffects being different from the count of elements in the Effects list!");
foreach(var effect in Effects)
data.AddRange(effect.Serialize());
}
return new Queue<byte>(data);
}
}

View file

@ -1,10 +1,12 @@
using System.Collections.Generic;
using MinecraftClient.Inventory;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class RarityComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class RarityComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public ItemRarity Rarity { get; set; }

View file

@ -0,0 +1,23 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class RepairCostComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int Cost { get; set; }
public override void Parse(Queue<byte> data)
{
Cost = dataTypes.ReadNextVarInt(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(Cost));
return new Queue<byte>(data);
}
}

View file

@ -0,0 +1,9 @@
using System.Collections.Generic;
using MinecraftClient.Inventory;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class StoredEnchantmentsComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: EnchantmentsComponent1206(dataTypes, itemPalette, subComponentRegistry);

View file

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class ToolComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public int NumberOfRules { get; set; }
public List<RuleSubComponent1206> Rules { get; set; } = new();
public float DefaultMiningSpeed { get; set; }
public int DamagePerBlock { get; set; }
public override void Parse(Queue<byte> data)
{
NumberOfRules = dataTypes.ReadNextVarInt(data);
for (var i = 0; i < NumberOfRules; i++)
Rules.Add((RuleSubComponent1206)subComponentRegistry.ParseSubComponent(SubComponents.Rule, data));
DefaultMiningSpeed = dataTypes.ReadNextFloat(data);
DamagePerBlock = dataTypes.ReadNextVarInt(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(NumberOfRules));
if(Rules.Count != NumberOfRules)
throw new ArgumentNullException($"Can not serialize a ToolComponent1206 when the Rules count != NumberOfRules!");
foreach (var rule in Rules)
data.AddRange(rule.Serialize());
data.AddRange(DataTypes.GetFloat(DefaultMiningSpeed));
data.AddRange(DataTypes.GetVarInt(DamagePerBlock));
return new Queue<byte>(data);
}
}

View file

@ -1,9 +1,11 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class UnbrekableComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class UnbrekableComponent1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public bool Unbrekable { get; set; }

View file

@ -1,9 +1,10 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components;
public class EmptyComponent(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
public class EmptyComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public override void Parse(Queue<byte> data)
{

View file

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
public class DetailsSubComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry)
{
public int Amplifier { get; set; }
public int Duration { get; set; }
public bool Ambient { get; set; }
public bool ShowParticles { get; set; }
public bool ShowIcon { get; set; }
public bool HasHiddenEffects { get; set; }
public DetailsSubComponent1206? Detail { get; set; }
protected override void Parse(Queue<byte> data)
{
Amplifier = dataTypes.ReadNextVarInt(data);
Duration = dataTypes.ReadNextVarInt(data);
Ambient = dataTypes.ReadNextBool(data);
ShowParticles = dataTypes.ReadNextBool(data);
ShowIcon = dataTypes.ReadNextBool(data);
HasHiddenEffects = dataTypes.ReadNextBool(data);
if(HasHiddenEffects)
Detail = (DetailsSubComponent1206)subComponentRegistry.ParseSubComponent(SubComponents.Details, data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(Amplifier));
data.AddRange(DataTypes.GetVarInt(Duration));
data.AddRange(DataTypes.GetBool(Ambient));
data.AddRange(DataTypes.GetBool(ShowParticles));
data.AddRange(DataTypes.GetBool(ShowIcon));
data.AddRange(DataTypes.GetBool(HasHiddenEffects));
if (HasHiddenEffects)
{
if(Detail is null)
throw new ArgumentNullException($"Can not serialize a DetailSubComponent1206 when the Detail is empty but HasHiddenEffects is true!");
data.AddRange(Detail.Serialize());
}
return new Queue<byte>(data);
}
}

View file

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
public class EffectSubComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry)
{
public PotionEffectSubComponent1206 TypeId { get; set; }
public float Probability { get; set; }
protected override void Parse(Queue<byte> data)
{
TypeId = (PotionEffectSubComponent1206)subComponentRegistry.ParseSubComponent(SubComponents.PotionEffect, data);
Probability = dataTypes.ReadNextFloat(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(TypeId.Serialize());
data.AddRange(DataTypes.GetFloat(Probability));
return new Queue<byte>(data);
}
}

View file

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
public class PotionEffectSubComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry)
{
public int TypeId { get; set; }
public DetailsSubComponent1206 Details { get; set; }
protected override void Parse(Queue<byte> data)
{
TypeId = dataTypes.ReadNextVarInt(data);
Details = (DetailsSubComponent1206)subComponentRegistry.ParseSubComponent(SubComponents.Details, data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(TypeId));
data.AddRange(Details.Serialize());
return new Queue<byte>(data);
}
}

View file

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
public class RuleSubComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry)
{
public BlockSetSubcomponent1206 Blocks { get; set; }
public bool HasSpeed { get; set; }
public float Speed { get; set; }
public bool HasCorrectDropForBlocks { get; set; }
public bool CorrectDropForBlocks { get; set; }
protected override void Parse(Queue<byte> data)
{
Blocks = (BlockSetSubcomponent1206)subComponentRegistry.ParseSubComponent(SubComponents.BlockSet, data);
HasSpeed = dataTypes.ReadNextBool(data);
if(HasSpeed)
Speed = dataTypes.ReadNextFloat(data);
HasCorrectDropForBlocks = dataTypes.ReadNextBool(data);
if(HasCorrectDropForBlocks)
CorrectDropForBlocks = dataTypes.ReadNextBool(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(Blocks.Serialize());
data.AddRange(DataTypes.GetBool(HasSpeed));
if(HasSpeed)
data.AddRange(DataTypes.GetFloat(Speed));
data.AddRange(DataTypes.GetBool(HasCorrectDropForBlocks));
if(HasCorrectDropForBlocks)
data.AddRange(DataTypes.GetBool(CorrectDropForBlocks));
return new Queue<byte>(data);
}
}

View file

@ -6,4 +6,8 @@ public class SubComponents
public const string BlockSet = "BlockSet";
public const string Property = "Property";
public const string Attribute = "Attribute";
public const string Effect = "Effect";
public const string PotionEffect = "PotionEffect";
public const string Details = "Details";
public const string Rule = "Rule";
}

View file

@ -1,11 +1,13 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
public abstract class StructuredComponent(DataTypes dataTypes, SubComponentRegistry subComponentRegistry)
public abstract class StructuredComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
{
protected DataTypes DataTypes { get; private set; } = dataTypes;
protected SubComponentRegistry SubComponentRegistry { get; private set; } = subComponentRegistry;
protected ItemPalette ItemPalette { get; private set; } = itemPalette;
public abstract void Parse(Queue<byte> data);
public abstract Queue<byte> Serialize();

View file

@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
public abstract class StructuredComponentRegistry(SubComponentRegistry subComponentRegistry, DataTypes dataTypes)
public abstract class StructuredComponentRegistry(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
{
private Dictionary<string, Type> ComponentParsers { get; } = new();
private Dictionary<int, string> IdToComponent { get; } = new();
@ -32,7 +33,7 @@ public abstract class StructuredComponentRegistry(SubComponentRegistry subCompon
if (ComponentParsers.TryGetValue(name, out var type))
{
var component =
Activator.CreateInstance(type, dataTypes, subComponentRegistry) as StructuredComponent
Activator.CreateInstance(type, dataTypes, itemPalette, subComponentRegistry) as StructuredComponent
?? throw new InvalidOperationException($"Could not instantiate a parser for a structured component type {name}");
component.Parse(data);

View file

@ -1,3 +1,4 @@
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
@ -5,8 +6,8 @@ namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Registries;
public class StructuredComponentsRegistry1206 : StructuredComponentRegistry
{
public StructuredComponentsRegistry1206(SubComponentRegistry subComponentRegistry, DataTypes dataTypes) : base(
subComponentRegistry, dataTypes)
public StructuredComponentsRegistry1206(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: base(dataTypes, itemPalette, subComponentRegistry)
{
RegisterComponent<CustomDataComponent1206>(0, "minecraft:custom_data");
RegisterComponent<MaxStackSizeComponent1206>(1, "minecraft:max_stack_size");
@ -24,5 +25,22 @@ public class StructuredComponentsRegistry1206 : StructuredComponentRegistry
RegisterComponent<CustomModelDataComponent1206>(13, "minecraft:custom_model_data");
RegisterComponent<HideAdditionalTooltipComponent1206>(14, "minecraft:hide_additional_tooltip");
RegisterComponent<HideTooltipComponent1206>(15, "minecraft:hide_tooltip");
RegisterComponent<HideTooltipComponent1206>(16, "minecraft:repair_cost");
RegisterComponent<CreativeSlotLockComponent1206>(17, "minecraft:creative_slot_lock");
RegisterComponent<EnchantmentGlintOverrideComponent1206>(18, "minecraft:enchantment_glint_override");
RegisterComponent<IntangibleProjectileComponent1206>(19, "minecraft:intangible_projectile");
RegisterComponent<FoodComponentComponent1206>(20, "minecraft:food");
RegisterComponent<FireResistantComponent1206>(21, "minecraft:fire_resistant");
RegisterComponent<ToolComponent1206>(22, "minecraft:tool");
RegisterComponent<StoredEnchantmentsComponent1206>(23, "minecraft:stored_enchantments");
RegisterComponent<DyeColorComponent1206>(24, "minecraft:dyed_color");
RegisterComponent<MapColorComponent1206>(25, "minecraft:map_color");
RegisterComponent<MapIdComponent1206>(26, "minecraft:map_id");
RegisterComponent<MapDecorationsComponent1206>(27, "minecraft:map_decorations");
RegisterComponent<MapPostProcessingComponent1206>(28, "minecraft:map_post_processing");
RegisterComponent<ChargedProjectilesComponent1206>(29, "minecraft:charged_projectiles");
RegisterComponent<BundleContentsComponent1206>(30, "minecraft:bundle_contents");
RegisterComponent<PotionContentsComponentComponent1206>(31, "minecraft:potion_contents");
}
}

View file

@ -12,5 +12,9 @@ public class SubComponentRegistry1206 : SubComponentRegistry
RegisterSubComponent<BlockSetSubcomponent1206>(SubComponents.BlockSet);
RegisterSubComponent<PropertySubComponent1206>(SubComponents.Property);
RegisterSubComponent<AttributeSubComponent1206>(SubComponents.Attribute);
RegisterSubComponent<EffectSubComponent1206>(SubComponents.Effect);
RegisterSubComponent<PotionEffectSubComponent1206>(SubComponents.PotionEffect);
RegisterSubComponent<DetailsSubComponent1206>(SubComponents.Details);
RegisterSubComponent<RuleSubComponent1206>(SubComponents.Rule);
}
}

View file

@ -13,7 +13,8 @@ public class StructuredComponentsHandler
public StructuredComponentsHandler(
int protocolVersion,
DataTypes dataTypes)
DataTypes dataTypes,
ItemPalette itemPalette)
{
// Get the appropriate subcomponent registry type based on the protocol version and then instantiate it
var subcomponentRegistryType = protocolVersion switch
@ -32,7 +33,7 @@ public class StructuredComponentsHandler
_ => throw new NotSupportedException($"Protocol version {protocolVersion} is not supported for structured component registries!")
};
ComponentRegistry = Activator.CreateInstance(registryType, subcomponentRegistry, dataTypes) as StructuredComponentRegistry
ComponentRegistry = Activator.CreateInstance(registryType, dataTypes, itemPalette, subcomponentRegistry) as StructuredComponentRegistry
?? throw new InvalidOperationException($"Failed to instantiate a component registry for type {nameof(registryType)}");
}