2024-09-11 19:12:31 +02:00
|
|
|
using System.Collections.Generic;
|
2024-09-11 20:35:23 +02:00
|
|
|
using MinecraftClient.Inventory.ItemPalettes;
|
2024-09-11 19:12:31 +02:00
|
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
|
|
|
|
using MinecraftClient.Protocol.Message;
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
|
|
|
|
|
2024-10-05 13:37:52 +02:00
|
|
|
public class CustomNameComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
|
2024-09-11 20:35:23 +02:00
|
|
|
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
|
2024-09-11 19:12:31 +02:00
|
|
|
{
|
|
|
|
|
public string CustomName { get; set; } = string.Empty;
|
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
2026-03-20 00:33:50 +08:00
|
|
|
public Dictionary<string, object>? CustomNameNbt { get; set; }
|
2024-09-11 19:12:31 +02:00
|
|
|
|
|
|
|
|
public override void Parse(Queue<byte> data)
|
|
|
|
|
{
|
2026-03-24 01:16:05 +00:00
|
|
|
CustomNameNbt = DataTypes.ReadNextNbt(data);
|
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
2026-03-20 00:33:50 +08:00
|
|
|
CustomName = ChatParser.ParseText(CustomNameNbt);
|
2024-09-11 19:12:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Queue<byte> Serialize()
|
|
|
|
|
{
|
|
|
|
|
var data = new List<byte>();
|
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
2026-03-20 00:33:50 +08:00
|
|
|
data.AddRange(DataTypes.GetNbt(CustomNameNbt));
|
2024-09-11 19:12:31 +02:00
|
|
|
return new Queue<byte>(data);
|
|
|
|
|
}
|
|
|
|
|
}
|