mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Fixed shulker crashing on 26.1 (Structured Components)
This commit is contained in:
parent
ba04636d06
commit
d55fd75520
7 changed files with 205 additions and 13 deletions
|
|
@ -0,0 +1,34 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Inventory;
|
||||
using MinecraftClient.Inventory.ItemPalettes;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._26_1;
|
||||
|
||||
public class ContainerComponent261(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
|
||||
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
|
||||
{
|
||||
public List<Item?> Items { get; set; } = [];
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
var count = DataTypes.ReadNextVarInt(data);
|
||||
for (var i = 0; i < count; i++)
|
||||
Items.Add(DataTypes.ReadNextBool(data) ? DataTypes.ReadNextItemStackTemplate(data, ItemPalette) : null);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(Items.Count));
|
||||
foreach (var item in Items)
|
||||
{
|
||||
var hasItem = item is not null && !item.IsEmpty;
|
||||
data.AddRange(DataTypes.GetBool(hasItem));
|
||||
if (hasItem)
|
||||
data.AddRange(DataTypes.GetItemStackTemplate(item!, ItemPalette));
|
||||
}
|
||||
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue