Minecraft-Console-Client/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/BlockStateComponent.cs
BruceChen cc10f4effa refactor: StructuredComponents batch 5 audit — remove redundant count fields
Audited batch 5 components (ChargedProjectiles, BundleContents, Container,
WritableBookContent, BlockState, PotDecorations) against official 1.20.6
decompiled STREAM_CODEC definitions. All network encodings were correct.

Removed redundant NumberOfItems/NumberOfPages/NumberOfProperties fields from
ContainerComponent, WritableBlookContentComponent, BlockStateComponent, and
PotDecorationsComponent. Serialize now uses the actual collection .Count
instead of a potentially stale cached value, matching the pattern already
used by ContainerComponent's Serialize and other components.

Also modernized loop style (foreach with deconstruction where applicable)
and fixed a typo in an exception message ("setialize" -> "serialize").

Made-with: Cursor
2026-03-20 00:45:50 +08:00

31 lines
No EOL
1.1 KiB
C#

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 BlockStateComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public List<(string, string)> Properties { get; set; } = [];
public override void Parse(Queue<byte> data)
{
var count = dataTypes.ReadNextVarInt(data);
for(var i = 0; i < count; i++)
Properties.Add((dataTypes.ReadNextString(data), dataTypes.ReadNextString(data)));
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(Properties.Count));
foreach (var (key, value) in Properties)
{
data.AddRange(DataTypes.GetString(key));
data.AddRange(DataTypes.GetString(value));
}
return new Queue<byte>(data);
}
}