Fixed 1.13 crashing in ReadNextItemSlot

This commit is contained in:
Anon 2023-03-24 14:06:50 +01:00
parent 750295b1e3
commit b65b3afc3c

View file

@ -418,13 +418,18 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns>The item that was read or NULL for an empty slot</returns> /// <returns>The item that was read or NULL for an empty slot</returns>
public Item? ReadNextItemSlot(Queue<byte> cache, ItemPalette itemPalette) public Item? ReadNextItemSlot(Queue<byte> cache, ItemPalette itemPalette)
{ {
// MC 1.13.2 and greater
if (protocolversion > Protocol18Handler.MC_1_13_Version) if (protocolversion > Protocol18Handler.MC_1_13_Version)
{ {
// MC 1.13 and greater
bool itemPresent = ReadNextBool(cache); bool itemPresent = ReadNextBool(cache);
if (itemPresent) if (itemPresent)
{ {
ItemType type = itemPalette.FromId(ReadNextVarInt(cache)); int itemID = ReadNextVarInt(cache);
if (itemID == -1)
return null;
ItemType type = itemPalette.FromId(itemID);
byte itemCount = ReadNextByte(cache); byte itemCount = ReadNextByte(cache);
Dictionary<string, object> nbt = ReadNextNbt(cache); Dictionary<string, object> nbt = ReadNextNbt(cache);
return new Item(type, itemCount, nbt); return new Item(type, itemCount, nbt);
@ -433,12 +438,17 @@ namespace MinecraftClient.Protocol.Handlers
} }
else else
{ {
// MC 1.12.2 and lower // MC 1.13 and lower
short itemID = ReadNextShort(cache); short itemID = ReadNextShort(cache);
if (itemID == -1) if (itemID == -1)
return null; return null;
byte itemCount = ReadNextByte(cache); byte itemCount = ReadNextByte(cache);
short itemDamage = ReadNextShort(cache);
if(protocolversion < Protocol18Handler.MC_1_13_Version)
ReadNextShort(cache);
Dictionary<string, object> nbt = ReadNextNbt(cache); Dictionary<string, object> nbt = ReadNextNbt(cache);
return new Item(itemPalette.FromId(itemID), itemCount, nbt); return new Item(itemPalette.FromId(itemID), itemCount, nbt);
} }