2024-09-11 20:35:23 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using MinecraftClient.Inventory.ItemPalettes;
|
|
|
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
|
|
|
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
|
|
|
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
|
|
|
|
|
2026-06-04 11:42:41 +02:00
|
|
|
public class ToolComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
|
2024-09-11 20:35:23 +02:00
|
|
|
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
|
|
|
|
|
{
|
|
|
|
|
public int NumberOfRules { get; set; }
|
2024-10-05 13:37:52 +02:00
|
|
|
public List<RuleSubComponent> Rules { get; set; } = new();
|
2024-09-11 20:35:23 +02:00
|
|
|
public float DefaultMiningSpeed { get; set; }
|
|
|
|
|
public int DamagePerBlock { get; set; }
|
2026-06-04 11:42:41 +02:00
|
|
|
|
2024-09-11 20:35:23 +02:00
|
|
|
public override void Parse(Queue<byte> data)
|
|
|
|
|
{
|
2026-03-24 01:16:05 +00:00
|
|
|
NumberOfRules = DataTypes.ReadNextVarInt(data);
|
2024-09-11 20:35:23 +02:00
|
|
|
|
|
|
|
|
for (var i = 0; i < NumberOfRules; i++)
|
2026-03-24 01:16:05 +00:00
|
|
|
Rules.Add((RuleSubComponent)SubComponentRegistry.ParseSubComponent(SubComponents.Rule, data));
|
2024-09-11 20:35:23 +02:00
|
|
|
|
2026-03-24 01:16:05 +00:00
|
|
|
DefaultMiningSpeed = DataTypes.ReadNextFloat(data);
|
|
|
|
|
DamagePerBlock = DataTypes.ReadNextVarInt(data);
|
2024-09-11 20:35:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Queue<byte> Serialize()
|
|
|
|
|
{
|
|
|
|
|
var data = new List<byte>();
|
|
|
|
|
data.AddRange(DataTypes.GetVarInt(NumberOfRules));
|
2026-06-04 11:42:41 +02:00
|
|
|
|
|
|
|
|
if (Rules.Count != NumberOfRules)
|
2024-09-11 20:35:23 +02:00
|
|
|
throw new ArgumentNullException($"Can not serialize a ToolComponent1206 when the Rules count != NumberOfRules!");
|
2026-06-04 11:42:41 +02:00
|
|
|
|
2024-09-11 20:35:23 +02:00
|
|
|
foreach (var rule in Rules)
|
|
|
|
|
data.AddRange(rule.Serialize());
|
2026-06-04 11:42:41 +02:00
|
|
|
|
2024-09-11 20:35:23 +02:00
|
|
|
data.AddRange(DataTypes.GetFloat(DefaultMiningSpeed));
|
|
|
|
|
data.AddRange(DataTypes.GetVarInt(DamagePerBlock));
|
|
|
|
|
return new Queue<byte>(data);
|
|
|
|
|
}
|
|
|
|
|
}
|