use of com.viaversion.viaversion.api.minecraft.chunks.BaseChunk in project ViaVersion by ViaVersion.
the class Chunk1_16Type method read.
@Override
public Chunk read(ByteBuf input) throws Exception {
int chunkX = input.readInt();
int chunkZ = input.readInt();
boolean fullChunk = input.readBoolean();
boolean ignoreOldLightData = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NBT.read(input);
int[] biomeData = fullChunk ? new int[1024] : null;
if (fullChunk) {
for (int i = 0; i < 1024; i++) {
biomeData[i] = input.readInt();
}
}
// data size in bytes
Type.VAR_INT.readPrimitive(input);
// Read sections
ChunkSection[] sections = new ChunkSection[16];
for (int i = 0; i < 16; i++) {
// Section not set
if ((primaryBitmask & (1 << i)) == 0)
continue;
short nonAirBlocksCount = input.readShort();
ChunkSection section = Types1_16.CHUNK_SECTION.read(input);
section.setNonAirBlocksCount(nonAirBlocksCount);
sections[i] = section;
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_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);
}
Aggregations