From b65b3afc3c93b82a7d2c61abc4f124eb7d9fed4b Mon Sep 17 00:00:00 2001 From: Anon Date: Fri, 24 Mar 2023 14:06:50 +0100 Subject: [PATCH] Fixed 1.13 crashing in ReadNextItemSlot --- MinecraftClient/Protocol/Handlers/DataTypes.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index e34f1b3d..961512da 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -418,13 +418,18 @@ namespace MinecraftClient.Protocol.Handlers /// The item that was read or NULL for an empty slot public Item? ReadNextItemSlot(Queue cache, ItemPalette itemPalette) { + // MC 1.13.2 and greater if (protocolversion > Protocol18Handler.MC_1_13_Version) { - // MC 1.13 and greater bool itemPresent = ReadNextBool(cache); 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); Dictionary nbt = ReadNextNbt(cache); return new Item(type, itemCount, nbt); @@ -433,12 +438,17 @@ namespace MinecraftClient.Protocol.Handlers } else { - // MC 1.12.2 and lower + // MC 1.13 and lower short itemID = ReadNextShort(cache); + if (itemID == -1) return null; + byte itemCount = ReadNextByte(cache); - short itemDamage = ReadNextShort(cache); + + if(protocolversion < Protocol18Handler.MC_1_13_Version) + ReadNextShort(cache); + Dictionary nbt = ReadNextNbt(cache); return new Item(itemPalette.FromId(itemID), itemCount, nbt); }