Slot, Chunk reading and writing (1.13)

This commit is contained in:
Bixilon 2020-07-08 23:38:57 +02:00
parent 35728f95d8
commit 4e1c415b14
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 38 additions and 37 deletions

View File

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

View File

@ -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());
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
}
/*
if (readBoolean()) {
return new Slot(readVarInt(), readByte(), readNBT());
}
//else no data
return null;
*/
}
return null;
}

View File

@ -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<Byte> write) {
write.add(b);
}
public static void writeVarInt(int value, List<Byte> 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<Byte> 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());
}
}

View File

@ -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<Byte, ChunkNibble> nibbleMap = new HashMap<>();
for (byte c = 0; c < 16; c++) { // max sections per chunks in chunk column