From c43b157b554d6d0d9b37ed144a86dab25bcdeaf7 Mon Sep 17 00:00:00 2001 From: Anon Date: Wed, 25 Mar 2026 02:08:59 +0100 Subject: [PATCH] More fixed for 1.21.5, 1.21.9, 1.21.11, stress tested against everything from 1.20.6 - 1.21.11 --- .../1_21_5/InstrumentComponent1215.cs | 7 +-- .../1_21_5/PaintingVariantHolderComponent.cs | 4 +- .../1_21_5/ProvidesTrimMaterialComponent.cs | 4 +- .../Components/1_21_9/BeesComponent1219.cs | 50 +++++++++++++++++++ .../StructuredComponentsRegistry12111.cs | 3 +- .../StructuredComponentsRegistry1215.cs | 19 +++++-- 6 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_9/BeesComponent1219.cs diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/InstrumentComponent1215.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/InstrumentComponent1215.cs index e8780324..beba31d8 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/InstrumentComponent1215.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/InstrumentComponent1215.cs @@ -16,7 +16,7 @@ public class InstrumentComponent1215(DataTypes dataTypes, ItemPalette itemPalett var holderId = DataTypes.ReadNextVarInt(data); if (holderId == 0) { - // Inline Instrument: SoundEvent holder + VarInt useDuration + Float range + Component description + // Inline Instrument: SoundEvent holder + Float useDuration + Float range + Component description var soundHolderId = DataTypes.ReadNextVarInt(data); if (soundHolderId == 0) { @@ -25,9 +25,10 @@ public class InstrumentComponent1215(DataTypes dataTypes, ItemPalette itemPalett if (hasFixedRange) DataTypes.ReadNextFloat(data); } - DataTypes.ReadNextVarInt(data); // useDuration + DataTypes.ReadNextFloat(data); // useDuration DataTypes.ReadNextFloat(data); // range - DataTypes.ReadNextString(data); // description (Component as JSON string) + // ComponentSerialization.STREAM_CODEC is NBT-backed, not a plain string. + DataTypes.ReadNextNbt(data); } } else diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/PaintingVariantHolderComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/PaintingVariantHolderComponent.cs index 0065441a..4e061f13 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/PaintingVariantHolderComponent.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/PaintingVariantHolderComponent.cs @@ -20,11 +20,11 @@ public class PaintingVariantHolderComponent(DataTypes dataTypes, ItemPalette ite // Optional title if (DataTypes.ReadNextBool(data)) - DataTypes.ReadNextString(data); + DataTypes.ReadNextNbt(data); // Optional author if (DataTypes.ReadNextBool(data)) - DataTypes.ReadNextString(data); + DataTypes.ReadNextNbt(data); } } diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/ProvidesTrimMaterialComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/ProvidesTrimMaterialComponent.cs index a8e5725a..f3ad9fac 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/ProvidesTrimMaterialComponent.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_5/ProvidesTrimMaterialComponent.cs @@ -25,8 +25,8 @@ public class ProvidesTrimMaterialComponent(DataTypes dataTypes, ItemPalette item DataTypes.ReadNextString(data); // ResourceKey DataTypes.ReadNextString(data); // override suffix } - // description Component - DataTypes.ReadNextString(data); + // ComponentSerialization.STREAM_CODEC is NBT-backed, not a plain string. + DataTypes.ReadNextNbt(data); } } else diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_9/BeesComponent1219.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_9/BeesComponent1219.cs new file mode 100644 index 00000000..b8142caa --- /dev/null +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21_9/BeesComponent1219.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using MinecraftClient.Inventory.ItemPalettes; +using MinecraftClient.Protocol.Handlers.StructuredComponents.Core; + +namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_9; + +public class BeesComponent1219(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry) + : StructuredComponent(dataTypes, itemPalette, subComponentRegistry) +{ + public int NumberOfBees { get; set; } + public List Bees { get; set; } = []; + + public override void Parse(Queue data) + { + NumberOfBees = DataTypes.ReadNextVarInt(data); + Bees = new List(NumberOfBees); + + for (var i = 0; i < NumberOfBees; i++) + { + Bees.Add( + new TypedBee( + DataTypes.ReadNextVarInt(data), + DataTypes.ReadNextNbt(data), + DataTypes.ReadNextVarInt(data), + DataTypes.ReadNextVarInt(data))); + } + } + + public override Queue Serialize() + { + var data = new List(); + data.AddRange(DataTypes.GetVarInt(NumberOfBees)); + + if (NumberOfBees != Bees.Count) + throw new InvalidOperationException("Can't serialize the BeesComponent1219 because NumberOfBees and Bees.Count differ!"); + + foreach (var bee in Bees) + { + data.AddRange(DataTypes.GetVarInt(bee.EntityTypeId)); + data.AddRange(DataTypes.GetNbt(bee.EntityDataNbt)); + data.AddRange(DataTypes.GetVarInt(bee.TicksInHive)); + data.AddRange(DataTypes.GetVarInt(bee.MinTicksInHive)); + } + + return new Queue(data); + } +} + +public sealed record TypedBee(int EntityTypeId, Dictionary? EntityDataNbt, int TicksInHive, int MinTicksInHive); diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Registries/StructuredComponentsRegistry12111.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Registries/StructuredComponentsRegistry12111.cs index 4c310f8e..7e9ec9c7 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Registries/StructuredComponentsRegistry12111.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Registries/StructuredComponentsRegistry12111.cs @@ -5,6 +5,7 @@ using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21; using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_2; using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_5; using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_8; +using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_9; using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_11; using MinecraftClient.Protocol.Handlers.StructuredComponents.Core; @@ -90,7 +91,7 @@ public class StructuredComponentsRegistry12111 : StructuredComponentRegistry RegisterComponent(72, "minecraft:pot_decorations"); RegisterComponent(73, "minecraft:container"); RegisterComponent(74, "minecraft:block_state"); - RegisterComponent(75, "minecraft:bees"); + RegisterComponent(75, "minecraft:bees"); RegisterComponent(76, "minecraft:lock"); RegisterComponent(77, "minecraft:container_loot"); diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Registries/StructuredComponentsRegistry1215.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Registries/StructuredComponentsRegistry1215.cs index 7649bcbf..3980e34d 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Registries/StructuredComponentsRegistry1215.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Registries/StructuredComponentsRegistry1215.cs @@ -5,6 +5,7 @@ using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21; using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_2; using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_5; using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_8; +using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_9; using MinecraftClient.Protocol.Handlers.StructuredComponents.Core; namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Registries; @@ -14,6 +15,9 @@ public class StructuredComponentsRegistry1215 : StructuredComponentRegistry public StructuredComponentsRegistry1215(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry) : base(dataTypes, itemPalette, subComponentRegistry) { + var uses1218AttributeAndEquippableFormats = dataTypes.ProtocolVersion >= Protocol18Handler.MC_1_21_6_Version; + var usesTypedBeesFormat = dataTypes.ProtocolVersion >= Protocol18Handler.MC_1_21_9_Version; + RegisterComponent(0, "minecraft:custom_data"); RegisterComponent(1, "minecraft:max_stack_size"); RegisterComponent(2, "minecraft:max_damage"); @@ -27,7 +31,10 @@ public class StructuredComponentsRegistry1215 : StructuredComponentRegistry RegisterComponent(10, "minecraft:enchantments"); RegisterComponent(11, "minecraft:can_place_on"); RegisterComponent(12, "minecraft:can_break"); - RegisterComponent(13, "minecraft:attribute_modifiers"); + if (uses1218AttributeAndEquippableFormats) + RegisterComponent(13, "minecraft:attribute_modifiers"); + else + RegisterComponent(13, "minecraft:attribute_modifiers"); RegisterComponent(14, "minecraft:custom_model_data"); // 15: tooltip_display (NEW, replaces hide_additional_tooltip + hide_tooltip) RegisterComponent(15, "minecraft:tooltip_display"); @@ -43,7 +50,10 @@ public class StructuredComponentsRegistry1215 : StructuredComponentRegistry RegisterComponent(25, "minecraft:tool"); RegisterComponent(26, "minecraft:weapon"); // NEW RegisterComponent(27, "minecraft:enchantable"); - RegisterComponent(28, "minecraft:equippable"); + if (uses1218AttributeAndEquippableFormats) + RegisterComponent(28, "minecraft:equippable"); + else + RegisterComponent(28, "minecraft:equippable"); RegisterComponent(29, "minecraft:repairable"); RegisterComponent(30, "minecraft:glider"); RegisterComponent(31, "minecraft:tooltip_style"); @@ -83,7 +93,10 @@ public class StructuredComponentsRegistry1215 : StructuredComponentRegistry RegisterComponent(65, "minecraft:pot_decorations"); RegisterComponent(66, "minecraft:container"); RegisterComponent(67, "minecraft:block_state"); - RegisterComponent(68, "minecraft:bees"); // Wire format unchanged in 1.21.5 + if (usesTypedBeesFormat) + RegisterComponent(68, "minecraft:bees"); + else + RegisterComponent(68, "minecraft:bees"); RegisterComponent(69, "minecraft:lock"); RegisterComponent(70, "minecraft:container_loot");