mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
40 lines
No EOL
1.5 KiB
C#
40 lines
No EOL
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using MinecraftClient.Inventory.ItemPalettes;
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
|
|
|
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
|
|
|
public class AttributeModifiersComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
|
|
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
|
|
{
|
|
public int NumberOfAttributes { get; set; }
|
|
public List<SubComponent> Attributes { get; set; } = new();
|
|
public bool ShowInTooltip { get; set; }
|
|
|
|
public override void Parse(Queue<byte> data)
|
|
{
|
|
NumberOfAttributes = DataTypes.ReadNextVarInt(data);
|
|
|
|
for (var i = 0; i < NumberOfAttributes; i++)
|
|
Attributes.Add(SubComponentRegistry.ParseSubComponent(SubComponents.Attribute, data));
|
|
|
|
ShowInTooltip = DataTypes.ReadNextBool(data);
|
|
}
|
|
|
|
public override Queue<byte> Serialize()
|
|
{
|
|
var data = new List<byte>();
|
|
data.AddRange(DataTypes.GetVarInt(NumberOfAttributes));
|
|
|
|
if (Attributes.Count != NumberOfAttributes)
|
|
throw new ArgumentNullException($"Can not serialize a AttributeModifiersComponent when the Attributes count != NumberOfAttributes!");
|
|
|
|
foreach (var attribute in Attributes)
|
|
data.AddRange(attribute.Serialize());
|
|
|
|
data.AddRange(DataTypes.GetBool(ShowInTooltip));
|
|
return new Queue<byte>(data);
|
|
}
|
|
} |