Slot and NBT reading for 1.8+

This commit is contained in:
Bixilon 2020-06-22 22:30:29 +02:00
parent 36a4ab26a8
commit fa5b9a2f08
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 32 additions and 12 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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()) {