From 7f8052c3cd7edb7c9b41d76f9ed596ed7781fa15 Mon Sep 17 00:00:00 2001 From: RK_01 <50594595+RaphiMC@users.noreply.github.com> Date: Thu, 4 Mar 2021 15:05:27 +0100 Subject: [PATCH] Fix handling of unknown container ids (#2384) --- .../packets/InventoryPackets.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java index c93b973f8..5b1638eeb 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java @@ -1,10 +1,6 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.github.steveice10.opennbt.tag.builtin.DoubleTag; -import com.github.steveice10.opennbt.tag.builtin.ListTag; -import com.github.steveice10.opennbt.tag.builtin.StringTag; -import com.github.steveice10.opennbt.tag.builtin.Tag; +import com.github.steveice10.opennbt.tag.builtin.*; import com.google.common.collect.Sets; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -55,7 +51,7 @@ public class InventoryPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - Short windowsId = wrapper.read(Type.UNSIGNED_BYTE); + Short windowId = wrapper.read(Type.UNSIGNED_BYTE); String type = wrapper.read(Type.STRING); JsonElement title = wrapper.read(Type.COMPONENT); COMPONENT_REWRITER.processText(title); @@ -64,19 +60,15 @@ public class InventoryPackets { if (type.equals("EntityHorse")) { wrapper.setId(0x1F); int entityId = wrapper.read(Type.INT); - wrapper.write(Type.UNSIGNED_BYTE, windowsId); + wrapper.write(Type.UNSIGNED_BYTE, windowId); wrapper.write(Type.VAR_INT, slots.intValue()); wrapper.write(Type.INT, entityId); } else { wrapper.setId(0x2E); - wrapper.write(Type.VAR_INT, windowsId.intValue()); + wrapper.write(Type.VAR_INT, windowId.intValue()); int typeId = -1; switch (type) { - case "minecraft:container": - case "minecraft:chest": - typeId = slots / 9 - 1; - break; case "minecraft:crafting_table": typeId = 11; break; @@ -108,6 +100,13 @@ public class InventoryPackets { case "minecraft:shulker_box": typeId = 19; break; + case "minecraft:container": + case "minecraft:chest": + default: + if (slots > 0 && slots <= 54) { + typeId = slots / 9 - 1; + } + break; } if (typeId == -1) {