fix: StructuredComponents batch 4 audit — CustomName, ItemName, Lore use NBT encoding

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
This commit is contained in:
BruceChen 2026-03-20 00:33:50 +08:00
parent c689343371
commit 5e416d6b72
3 changed files with 17 additions and 10 deletions

View file

@ -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<string, object>? CustomNameNbt { get; set; }
public override void Parse(Queue<byte> data)
{
CustomName = ChatParser.ParseText(dataTypes.ReadNextString(data));
CustomNameNbt = dataTypes.ReadNextNbt(data);
CustomName = ChatParser.ParseText(CustomNameNbt);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetString(CustomName));
data.AddRange(DataTypes.GetNbt(CustomNameNbt));
return new Queue<byte>(data);
}
}

View file

@ -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<string, object>? ItemNameNbt { get; set; }
public override void Parse(Queue<byte> data)
{
ItemName = ChatParser.ParseText(dataTypes.ReadNextString(data));
ItemNameNbt = dataTypes.ReadNextNbt(data);
ItemName = ChatParser.ParseText(ItemNameNbt);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetString(ItemName));
data.AddRange(DataTypes.GetNbt(ItemNameNbt));
return new Queue<byte>(data);
}
}

View file

@ -10,6 +10,7 @@ public class LoreNameComponent1206(DataTypes dataTypes, ItemPalette itemPalette,
{
public int NumberOfLines { get; set; }
public List<string> Lines { get; set; } = [];
public List<Dictionary<string, object>> LinesNbt { get; set; } = [];
public override void Parse(Queue<byte> 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<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(Lines.Count));
data.AddRange(DataTypes.GetVarInt(LinesNbt.Count));
if (Lines.Count <= 0) return new Queue<byte>(data);
foreach (var line in Lines)
data.AddRange(DataTypes.GetString(line));
foreach (var lineNbt in LinesNbt)
data.AddRange(DataTypes.GetNbt(lineNbt));
return new Queue<byte>(data);
}