From 5e416d6b72440e7a0242f692619de06b2ec5ebf1 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Fri, 20 Mar 2026 00:33:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20StructuredComponents=20batch=204=20audit?= =?UTF-8?q?=20=E2=80=94=20CustomName,=20ItemName,=20Lore=20use=20NBT=20enc?= =?UTF-8?q?oding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 1.20.6+, ComponentSerialization.STREAM_CODEC uses ByteBufCodecs.fromCodecWithRegistries (NBT tag format), not plain string. The previous implementation incorrectly used ReadNextString/GetString for custom_name (5), item_name (6), and lore (7) components. Fixed all three to use ReadNextNbt/GetNbt, preserving raw NBT data for round-trip serialization while still extracting readable text via ChatParser.ParseText(Dictionary). Other batch 4 components (custom_data, entity_data, bucket_entity_data, block_entity_data, debug_stick_state, map_decorations, recipes, lock, container_loot, intangible_projectile — all NBT; hide_additional_tooltip, hide_tooltip, fire_resistant, creative_slot_lock — all Unit/Empty; note_block_sound — ResourceLocation string) were verified correct. Made-with: Cursor --- .../Components/1_20_6/CustomNameComponent.cs | 6 ++++-- .../Components/1_20_6/ItemNameComponent.cs | 6 ++++-- .../Components/1_20_6/LoreComponent.cs | 15 +++++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/CustomNameComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/CustomNameComponent.cs index 024b7a43..f4f2fc92 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/CustomNameComponent.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/CustomNameComponent.cs @@ -9,16 +9,18 @@ public class CustomNameComponent(DataTypes dataTypes, ItemPalette itemPalette, S : StructuredComponent(dataTypes, itemPalette, subComponentRegistry) { public string CustomName { get; set; } = string.Empty; + public Dictionary? CustomNameNbt { get; set; } public override void Parse(Queue data) { - CustomName = ChatParser.ParseText(dataTypes.ReadNextString(data)); + CustomNameNbt = dataTypes.ReadNextNbt(data); + CustomName = ChatParser.ParseText(CustomNameNbt); } public override Queue Serialize() { var data = new List(); - data.AddRange(DataTypes.GetString(CustomName)); + data.AddRange(DataTypes.GetNbt(CustomNameNbt)); return new Queue(data); } } \ No newline at end of file diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ItemNameComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ItemNameComponent.cs index a7c8bda3..6fc8ae3e 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ItemNameComponent.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/ItemNameComponent.cs @@ -9,16 +9,18 @@ public class ItemNameComponent(DataTypes dataTypes, ItemPalette itemPalette, Sub : StructuredComponent(dataTypes, itemPalette, subComponentRegistry) { public string ItemName { get; set; } = string.Empty; + public Dictionary? ItemNameNbt { get; set; } public override void Parse(Queue data) { - ItemName = ChatParser.ParseText(dataTypes.ReadNextString(data)); + ItemNameNbt = dataTypes.ReadNextNbt(data); + ItemName = ChatParser.ParseText(ItemNameNbt); } public override Queue Serialize() { var data = new List(); - data.AddRange(DataTypes.GetString(ItemName)); + data.AddRange(DataTypes.GetNbt(ItemNameNbt)); return new Queue(data); } } \ No newline at end of file diff --git a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/LoreComponent.cs b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/LoreComponent.cs index 8aa711ef..aaca1b72 100644 --- a/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/LoreComponent.cs +++ b/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/LoreComponent.cs @@ -10,6 +10,7 @@ public class LoreNameComponent1206(DataTypes dataTypes, ItemPalette itemPalette, { public int NumberOfLines { get; set; } public List Lines { get; set; } = []; + public List> LinesNbt { get; set; } = []; public override void Parse(Queue data) { @@ -18,18 +19,20 @@ public class LoreNameComponent1206(DataTypes dataTypes, ItemPalette itemPalette, if (NumberOfLines <= 0) return; for (var i = 0; i < NumberOfLines; i++) - Lines.Add(ChatParser.ParseText(dataTypes.ReadNextString(data))); + { + var lineNbt = dataTypes.ReadNextNbt(data); + LinesNbt.Add(lineNbt); + Lines.Add(ChatParser.ParseText(lineNbt)); + } } public override Queue Serialize() { var data = new List(); - data.AddRange(DataTypes.GetVarInt(Lines.Count)); + data.AddRange(DataTypes.GetVarInt(LinesNbt.Count)); - if (Lines.Count <= 0) return new Queue(data); - - foreach (var line in Lines) - data.AddRange(DataTypes.GetString(line)); + foreach (var lineNbt in LinesNbt) + data.AddRange(DataTypes.GetNbt(lineNbt)); return new Queue(data); }