mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
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
This commit is contained in:
parent
5e416d6b72
commit
cc10f4effa
4 changed files with 17 additions and 24 deletions
|
|
@ -7,24 +7,23 @@ namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_2
|
|||
public class BlockStateComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
|
||||
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
|
||||
{
|
||||
public int NumberOfProperties { get; set; }
|
||||
public List<(string, string)> Properties { get; set; } = [];
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
NumberOfProperties = dataTypes.ReadNextVarInt(data);
|
||||
for(var i = 0; i < NumberOfProperties; i++)
|
||||
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(NumberOfProperties));
|
||||
for (var i = 0; i < NumberOfProperties; i++)
|
||||
data.AddRange(DataTypes.GetVarInt(Properties.Count));
|
||||
foreach (var (key, value) in Properties)
|
||||
{
|
||||
data.AddRange(DataTypes.GetString(Properties[i].Item1));
|
||||
data.AddRange(DataTypes.GetString(Properties[i].Item2));
|
||||
data.AddRange(DataTypes.GetString(key));
|
||||
data.AddRange(DataTypes.GetString(value));
|
||||
}
|
||||
|
||||
return new Queue<byte>(data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue