Implement size var int in all chunk types correctly (#3495)

This commit is contained in:
EnZaXD 2023-10-24 02:03:32 +02:00 committed by GitHub
parent 2c6e18e4fe
commit 0f030c86a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 94 deletions

View File

@ -85,15 +85,6 @@ public class ChunkType1_13 extends Type<Chunk> {
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
}
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData);
}

View File

@ -50,16 +50,15 @@ public class ChunkType1_14 extends Type<Chunk> {
boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(input);
Type.VAR_INT.readPrimitive(input);
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input));
// Read sections
ChunkSection[] sections = new ChunkSection[16];
for (int i = 0; i < 16; i++) {
if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set
short nonAirBlocksCount = input.readShort();
ChunkSection section = Types1_13.CHUNK_SECTION.read(input);
short nonAirBlocksCount = data.readShort();
ChunkSection section = Types1_13.CHUNK_SECTION.read(data);
section.setNonAirBlocksCount(nonAirBlocksCount);
sections[i] = section;
}
@ -67,20 +66,11 @@ public class ChunkType1_14 extends Type<Chunk> {
int[] biomeData = fullChunk ? new int[256] : null;
if (fullChunk) {
for (int i = 0; i < 256; i++) {
biomeData[i] = input.readInt();
biomeData[i] = data.readInt();
}
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
}
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData);
}

View File

@ -58,29 +58,20 @@ public class ChunkType1_15 extends Type<Chunk> {
}
}
Type.VAR_INT.readPrimitive(input); // data size in bytes
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input));
// Read sections
ChunkSection[] sections = new ChunkSection[16];
for (int i = 0; i < 16; i++) {
if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set
short nonAirBlocksCount = input.readShort();
ChunkSection section = Types1_13.CHUNK_SECTION.read(input);
short nonAirBlocksCount = data.readShort();
ChunkSection section = Types1_13.CHUNK_SECTION.read(data);
section.setNonAirBlocksCount(nonAirBlocksCount);
sections[i] = section;
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
}
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData);
}

View File

@ -59,29 +59,20 @@ public class ChunkType1_16 extends Type<Chunk> {
}
}
Type.VAR_INT.readPrimitive(input); // data size in bytes
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input));
// Read sections
ChunkSection[] sections = new ChunkSection[16];
for (int i = 0; i < 16; i++) {
if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set
short nonAirBlocksCount = input.readShort();
ChunkSection section = Types1_16.CHUNK_SECTION.read(input);
short nonAirBlocksCount = data.readShort();
ChunkSection section = Types1_16.CHUNK_SECTION.read(data);
section.setNonAirBlocksCount(nonAirBlocksCount);
sections[i] = section;
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
}
return new BaseChunk(chunkX, chunkZ, fullChunk, ignoreOldLightData, primaryBitmask, sections, biomeData, heightMap, nbtData);
}

View File

@ -56,29 +56,20 @@ public class ChunkType1_16_2 extends Type<Chunk> {
biomeData = Type.VAR_INT_ARRAY_PRIMITIVE.read(input);
}
Type.VAR_INT.readPrimitive(input); // data size in bytes
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input));
// Read sections
ChunkSection[] sections = new ChunkSection[16];
for (int i = 0; i < 16; i++) {
if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set
short nonAirBlocksCount = input.readShort();
ChunkSection section = Types1_16.CHUNK_SECTION.read(input);
short nonAirBlocksCount = data.readShort();
ChunkSection section = Types1_16.CHUNK_SECTION.read(data);
section.setNonAirBlocksCount(nonAirBlocksCount);
sections[i] = section;
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
}
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData);
}

View File

@ -56,29 +56,20 @@ public final class ChunkType1_17 extends Type<Chunk> {
int[] biomeData = Type.VAR_INT_ARRAY_PRIMITIVE.read(input);
Type.VAR_INT.readPrimitive(input); // data size in bytes
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input));
// Read sections
ChunkSection[] sections = new ChunkSection[ySectionCount];
for (int i = 0; i < ySectionCount; i++) {
if (!sectionsMask.get(i)) continue; // Section not set
short nonAirBlocksCount = input.readShort();
ChunkSection section = Types1_16.CHUNK_SECTION.read(input);
short nonAirBlocksCount = data.readShort();
ChunkSection section = Types1_16.CHUNK_SECTION.read(data);
section.setNonAirBlocksCount(nonAirBlocksCount);
sections[i] = section;
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
}
return new BaseChunk(chunkX, chunkZ, true, false, sectionsMask, sections, biomeData, heightMap, nbtData);
}

View File

@ -58,9 +58,6 @@ public final class ChunkType1_18 extends Type<Chunk> {
sections[i] = sectionType.read(sectionsBuf);
}
} finally {
/*if (sectionsBuf.readableBytes() > 0 && Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + sectionsBuf.readableBytes() + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}*/
sectionsBuf.release();
}

View File

@ -54,8 +54,7 @@ public class ChunkType1_9_1 extends Type<Chunk> {
boolean groundUp = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
// Size (unused)
Type.VAR_INT.readPrimitive(input);
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input));
BitSet usedSections = new BitSet(16);
ChunkSection[] sections = new ChunkSection[16];
@ -69,18 +68,18 @@ public class ChunkType1_9_1 extends Type<Chunk> {
// Read sections
for (int i = 0; i < 16; i++) {
if (!usedSections.get(i)) continue; // Section not set
ChunkSection section = Types1_9.CHUNK_SECTION.read(input);
ChunkSection section = Types1_9.CHUNK_SECTION.read(data);
sections[i] = section;
section.getLight().readBlockLight(input);
section.getLight().readBlockLight(data);
if (hasSkyLight) {
section.getLight().readSkyLight(input);
section.getLight().readSkyLight(data);
}
}
int[] biomeData = groundUp ? new int[256] : null;
if (groundUp) {
for (int i = 0; i < 256; i++) {
biomeData[i] = input.readByte() & 0xFF;
biomeData[i] = data.readByte() & 0xFF;
}
}

View File

@ -57,38 +57,29 @@ public class ChunkType1_9_3 extends Type<Chunk> {
boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
Type.VAR_INT.readPrimitive(input);
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input));
// Read sections
ChunkSection[] sections = new ChunkSection[16];
for (int i = 0; i < 16; i++) {
if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set
ChunkSection section = Types1_9.CHUNK_SECTION.read(input);
ChunkSection section = Types1_9.CHUNK_SECTION.read(data);
sections[i] = section;
section.getLight().readBlockLight(input);
section.getLight().readBlockLight(data);
if (hasSkyLight) {
section.getLight().readSkyLight(input);
section.getLight().readSkyLight(data);
}
}
int[] biomeData = fullChunk ? new int[256] : null;
if (fullChunk) {
for (int i = 0; i < 256; i++) {
biomeData[i] = input.readByte() & 0xFF;
biomeData[i] = data.readByte() & 0xFF;
}
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
}
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData);
}