Search in sources :

Example 1 with Chunk1_18

use of com.viaversion.viaversion.api.minecraft.chunks.Chunk1_18 in project ViaVersion by ViaVersion.

the class Chunk1_18Type method read.

@Override
public Chunk read(final ByteBuf buffer) throws Exception {
    final int chunkX = buffer.readInt();
    final int chunkZ = buffer.readInt();
    final CompoundTag heightMap = Type.NBT.read(buffer);
    // Read sections
    final ByteBuf sectionsBuf = buffer.readBytes(Type.VAR_INT.readPrimitive(buffer));
    final ChunkSection[] sections = new ChunkSection[ySectionCount];
    try {
        for (int i = 0; i < ySectionCount; i++) {
            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();
    }
    final int blockEntitiesLength = Type.VAR_INT.readPrimitive(buffer);
    final List<BlockEntity> blockEntities = new ArrayList<>(blockEntitiesLength);
    for (int i = 0; i < blockEntitiesLength; i++) {
        blockEntities.add(Types1_18.BLOCK_ENTITY.read(buffer));
    }
    return new Chunk1_18(chunkX, chunkZ, sections, heightMap, blockEntities);
}
Also used : ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) Chunk1_18(com.viaversion.viaversion.api.minecraft.chunks.Chunk1_18) BlockEntity(com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity)

Aggregations

CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)1 BlockEntity (com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity)1 Chunk1_18 (com.viaversion.viaversion.api.minecraft.chunks.Chunk1_18)1 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)1 ByteBuf (io.netty.buffer.ByteBuf)1 ArrayList (java.util.ArrayList)1