Fix handling of unknown container ids (#2384)

This commit is contained in:
RK_01 2021-03-04 15:05:27 +01:00 committed by GitHub
parent 08763a92ab
commit 7f8052c3cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,6 @@
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets; 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.*;
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.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -55,7 +51,7 @@ public class InventoryPackets {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { 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); String type = wrapper.read(Type.STRING);
JsonElement title = wrapper.read(Type.COMPONENT); JsonElement title = wrapper.read(Type.COMPONENT);
COMPONENT_REWRITER.processText(title); COMPONENT_REWRITER.processText(title);
@ -64,19 +60,15 @@ public class InventoryPackets {
if (type.equals("EntityHorse")) { if (type.equals("EntityHorse")) {
wrapper.setId(0x1F); wrapper.setId(0x1F);
int entityId = wrapper.read(Type.INT); 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.VAR_INT, slots.intValue());
wrapper.write(Type.INT, entityId); wrapper.write(Type.INT, entityId);
} else { } else {
wrapper.setId(0x2E); wrapper.setId(0x2E);
wrapper.write(Type.VAR_INT, windowsId.intValue()); wrapper.write(Type.VAR_INT, windowId.intValue());
int typeId = -1; int typeId = -1;
switch (type) { switch (type) {
case "minecraft:container":
case "minecraft:chest":
typeId = slots / 9 - 1;
break;
case "minecraft:crafting_table": case "minecraft:crafting_table":
typeId = 11; typeId = 11;
break; break;
@ -108,6 +100,13 @@ public class InventoryPackets {
case "minecraft:shulker_box": case "minecraft:shulker_box":
typeId = 19; typeId = 19;
break; break;
case "minecraft:container":
case "minecraft:chest":
default:
if (slots > 0 && slots <= 54) {
typeId = slots / 9 - 1;
}
break;
} }
if (typeId == -1) { if (typeId == -1) {