diff --git a/src/main/java/de/bixilon/minosoft/nbt/tag/CompoundTag.java b/src/main/java/de/bixilon/minosoft/nbt/tag/CompoundTag.java index 1290c86ec..f6c11d158 100644 --- a/src/main/java/de/bixilon/minosoft/nbt/tag/CompoundTag.java +++ b/src/main/java/de/bixilon/minosoft/nbt/tag/CompoundTag.java @@ -29,6 +29,14 @@ public class CompoundTag implements Tag { } public CompoundTag(boolean subTag, InByteBuffer buffer) { + if (buffer.readByte() == 0) { + // no nbt + name = null; + data = new HashMap<>(); + return; + } else { + buffer.setPosition(buffer.getPosition() - 1); + } if (!subTag) { if (buffer.readByte() != TagTypes.COMPOUND.getId()) { // will be a Compound Tag // decompressed but still bad.... :( @@ -86,6 +94,11 @@ public class CompoundTag implements Tag { this(false, buffer); } + public CompoundTag() { + name = null; + data = new HashMap<>(); + } + @Override public TagTypes getType() { return TagTypes.COMPOUND; diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockEntityMetadata.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockEntityMetadata.java index dba1092b0..f6ff79589 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockEntityMetadata.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockEntityMetadata.java @@ -33,7 +33,7 @@ public class PacketBlockEntityMetadata implements ClientboundPacket { case VERSION_1_7_10: position = buffer.readBlockPositionShort(); action = Action.byId(buffer.readByte()); - nbt = buffer.readNBT(); + nbt = buffer.readNBT(true); break; case VERSION_1_8: position = buffer.readPosition(); 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 ccc310dbf..418c7fbd6 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java @@ -21,7 +21,6 @@ import de.bixilon.minosoft.game.datatypes.inventory.Slot; import de.bixilon.minosoft.game.datatypes.particle.*; import de.bixilon.minosoft.game.datatypes.world.BlockPosition; import de.bixilon.minosoft.nbt.tag.CompoundTag; -import de.bixilon.minosoft.nbt.tag.TagTypes; import de.bixilon.minosoft.util.BitByte; import de.bixilon.minosoft.util.Util; import org.json.JSONObject; @@ -234,15 +233,12 @@ public class InByteBuffer { return null; } - public CompoundTag readNBT() { - - if (readByte() != TagTypes.COMPOUND.getId()) { // will be a Compound Tag - // maybe compressed - setPosition(getPosition() - 1); + public CompoundTag readNBT(boolean compressed) { + if (compressed) { short length = readShort(); if (length == -1) { // no nbt data here... - return null; + return new CompoundTag(); } try { return new CompoundTag(new InByteBuffer(Util.decompressGzip(readBytes(length)))); @@ -253,18 +249,29 @@ public class InByteBuffer { } // try again } - setPosition(getPosition() - 1); return new CompoundTag(this); } + public CompoundTag readNBT() { + return readNBT(false); + } + public Slot readSlot(ProtocolVersion v) { switch (v) { - case VERSION_1_7_10: + case VERSION_1_7_10: { short id = readShort(); if (id != -1) { - return new Slot(id, readByte(), readShort(), readNBT()); + return new Slot(id, readByte(), readShort(), readNBT(true)); } - return null; + break; + } + case VERSION_1_8: { + short id = readShort(); + if (id == -1) { + return null; + } + return new Slot(id, readByte(), readShort(), readNBT()); + } /* if (readBoolean()) {