diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/inventory/Slot.java b/src/main/java/de/bixilon/minosoft/game/datatypes/inventory/Slot.java index ba6de555a..4661d9ee8 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/inventory/Slot.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/inventory/Slot.java @@ -29,7 +29,7 @@ public class Slot { this.nbt = nbt; } - public Slot(short itemId, byte itemCount, short itemMetadata, CompoundTag nbt) { + public Slot(int itemId, byte itemCount, short itemMetadata, CompoundTag nbt) { this.itemId = itemId; this.itemMetadata = itemMetadata; this.itemCount = itemCount; diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java index dabd5a6fe..20f6e2854 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java @@ -263,32 +263,22 @@ public class InByteBuffer { public Slot readSlot() { switch (version) { - case VERSION_1_7_10: { - short id = readShort(); - if (id != -1) { - return new Slot(id, readByte(), readShort(), readNBT(true)); - } - break; - } + case VERSION_1_7_10: case VERSION_1_8: case VERSION_1_9_4: case VERSION_1_10: case VERSION_1_11_2: - case VERSION_1_12_2: { + case VERSION_1_12_2: short id = readShort(); if (id == -1) { return null; } - return new Slot(id, readByte(), readShort(), readNBT()); - } - /* - - if (readBoolean()) { - return new Slot(readVarInt(), readByte(), readNBT()); - } - //else no data - return null; - */ + return new Slot(id, readByte(), readShort(), readNBT(version == ProtocolVersion.VERSION_1_7_10)); // compression + case VERSION_1_13_2: + if (!readBoolean()) { + // nothing here + return new Slot(readVarInt(), readByte(), readNBT()); // ToDo: item metadata + } } return null; } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.java index fcf502243..c41eb4c60 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.java @@ -33,14 +33,27 @@ public class OutByteBuffer { this.version = version; } - public void writeByte(byte b) { - bytes.add(b); - } - public static void writeByte(byte b, List write) { write.add(b); } + public static void writeVarInt(int value, List write) { + // thanks https://wiki.vg/Protocol#VarInt_and_VarLong + do { + byte temp = (byte) (value & 0b01111111); + // Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone + value >>>= 7; + if (value != 0) { + temp |= 0b10000000; + } + writeByte(temp, write); + } while (value != 0); + } + + public void writeByte(byte b) { + bytes.add(b); + } + public void writeBytes(byte[] b) { for (byte value : b) { bytes.add(value); @@ -59,19 +72,6 @@ public class OutByteBuffer { } } - public static void writeVarInt(int value, List write) { - // thanks https://wiki.vg/Protocol#VarInt_and_VarLong - do { - byte temp = (byte) (value & 0b01111111); - // Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone - value >>>= 7; - if (value != 0) { - temp |= 0b10000000; - } - writeByte(temp, write); - } while (value != 0); - } - public void writeLong(Long l) { ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.putLong(l); @@ -180,6 +180,16 @@ public class OutByteBuffer { writeByte((byte) slot.getItemCount()); writeShort(slot.getItemMetadata()); writeNBT(slot.getNbt()); + break; + case VERSION_1_13_2: + if (slot == null) { + writeBoolean(false); + return; + } + writeVarInt(slot.getItemId()); + writeByte((byte) slot.getItemCount()); + writeNBT(slot.getNbt()); + } } diff --git a/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java b/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java index 2d739829d..7cc266735 100644 --- a/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java +++ b/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java @@ -145,7 +145,8 @@ public class ChunkUtil { case VERSION_1_9_4: case VERSION_1_10: case VERSION_1_11_2: - case VERSION_1_12_2: { + case VERSION_1_12_2: + case VERSION_1_13_2: { // really big thanks to: https://wiki.vg/index.php?title=Chunk_Format&oldid=13712 HashMap nibbleMap = new HashMap<>(); for (byte c = 0; c < 16; c++) { // max sections per chunks in chunk column