2024-10-05 13:37:52 +02:00
|
|
|
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 InstrumentComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
|
|
|
|
|
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
|
|
|
|
|
{
|
2026-03-19 01:44:23 +08:00
|
|
|
// holder ID: 0 = inline instrument data, N>0 = registry reference (id = N-1)
|
|
|
|
|
public int InstrumentHolderId { get; set; }
|
|
|
|
|
|
|
|
|
|
// Inline instrument fields (only when InstrumentHolderId == 0):
|
|
|
|
|
// holder ID for SoundEvent: 0 = inline sound, N>0 = registry reference (id = N-1)
|
|
|
|
|
public int SoundEventHolderId { get; set; }
|
|
|
|
|
// Inline SoundEvent fields (only when SoundEventHolderId == 0):
|
|
|
|
|
public string? SoundLocation { get; set; }
|
2024-10-05 13:37:52 +02:00
|
|
|
public bool HasFixedRange { get; set; }
|
|
|
|
|
public float FixedRange { get; set; }
|
2026-03-19 01:44:23 +08:00
|
|
|
|
|
|
|
|
public int UseDuration { get; set; }
|
2024-10-05 13:37:52 +02:00
|
|
|
public float Range { get; set; }
|
|
|
|
|
|
|
|
|
|
public override void Parse(Queue<byte> data)
|
|
|
|
|
{
|
2026-03-24 01:16:05 +00:00
|
|
|
InstrumentHolderId = DataTypes.ReadNextVarInt(data);
|
2024-10-05 13:37:52 +02:00
|
|
|
|
2026-03-19 01:44:23 +08:00
|
|
|
if (InstrumentHolderId == 0)
|
2024-10-05 13:37:52 +02:00
|
|
|
{
|
2026-03-24 01:16:05 +00:00
|
|
|
SoundEventHolderId = DataTypes.ReadNextVarInt(data);
|
2024-10-05 13:37:52 +02:00
|
|
|
|
2026-03-19 01:44:23 +08:00
|
|
|
if (SoundEventHolderId == 0)
|
2024-10-05 13:37:52 +02:00
|
|
|
{
|
2026-03-24 01:16:05 +00:00
|
|
|
SoundLocation = DataTypes.ReadNextString(data);
|
|
|
|
|
HasFixedRange = DataTypes.ReadNextBool(data);
|
2026-03-19 01:44:23 +08:00
|
|
|
if (HasFixedRange)
|
2026-03-24 01:16:05 +00:00
|
|
|
FixedRange = DataTypes.ReadNextFloat(data);
|
2024-10-05 13:37:52 +02:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 01:16:05 +00:00
|
|
|
UseDuration = DataTypes.ReadNextVarInt(data);
|
|
|
|
|
Range = DataTypes.ReadNextFloat(data);
|
2024-10-05 13:37:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Queue<byte> Serialize()
|
|
|
|
|
{
|
|
|
|
|
var data = new List<byte>();
|
2026-03-19 01:44:23 +08:00
|
|
|
data.AddRange(DataTypes.GetVarInt(InstrumentHolderId));
|
2024-10-05 13:37:52 +02:00
|
|
|
|
2026-03-19 01:44:23 +08:00
|
|
|
if (InstrumentHolderId == 0)
|
2024-10-05 13:37:52 +02:00
|
|
|
{
|
2026-03-19 01:44:23 +08:00
|
|
|
data.AddRange(DataTypes.GetVarInt(SoundEventHolderId));
|
2024-10-05 13:37:52 +02:00
|
|
|
|
2026-03-19 01:44:23 +08:00
|
|
|
if (SoundEventHolderId == 0)
|
2024-10-05 13:37:52 +02:00
|
|
|
{
|
2026-03-19 01:44:23 +08:00
|
|
|
data.AddRange(DataTypes.GetString(SoundLocation ?? ""));
|
2024-10-05 13:37:52 +02:00
|
|
|
data.AddRange(DataTypes.GetBool(HasFixedRange));
|
2026-03-19 01:44:23 +08:00
|
|
|
if (HasFixedRange)
|
|
|
|
|
data.AddRange(DataTypes.GetFloat(FixedRange));
|
2024-10-05 13:37:52 +02:00
|
|
|
}
|
2026-03-19 01:44:23 +08:00
|
|
|
|
|
|
|
|
data.AddRange(DataTypes.GetVarInt(UseDuration));
|
2024-10-05 13:37:52 +02:00
|
|
|
data.AddRange(DataTypes.GetFloat(Range));
|
|
|
|
|
}
|
2026-03-19 01:44:23 +08:00
|
|
|
|
2024-10-05 13:37:52 +02:00
|
|
|
return new Queue<byte>(data);
|
|
|
|
|
}
|
2026-03-19 01:44:23 +08:00
|
|
|
}
|