Java Code Examples for us.myles.ViaVersion.api.minecraft.chunks.Chunk#getBiomeData()

The following examples show how to use us.myles.ViaVersion.api.minecraft.chunks.Chunk#getBiomeData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Chunk1_8Type.java    From ViaRewind with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    ByteBuf buf = output.alloc().buffer();

    for (int i = 0; i < chunk.getSections().length; i++) {
        if ((chunk.getBitmask() & 1 << i) == 0) continue;
        CHUNK_SECTION_TYPE.write(buf, chunk.getSections()[i]);
    }

    for (int i = 0; i < chunk.getSections().length; i++) {
        if ((chunk.getBitmask() & 1 << i) == 0) continue;
        chunk.getSections()[i].writeBlockLight(buf);
    }

    boolean skyLight = world.getEnvironment() == Environment.NORMAL;
    if (skyLight) {
        for (int i = 0; i < chunk.getSections().length; i++) {
            if ((chunk.getBitmask() & 1 << i) == 0) continue;
            chunk.getSections()[i].writeSkyLight(buf);
        }
    }

    if (chunk.isGroundUp() && chunk.isBiomeData()) {
        for (int biome : chunk.getBiomeData()) {
            buf.writeByte((byte) biome);
        }
    }

    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());
    output.writeBoolean(chunk.isGroundUp());
    output.writeShort(chunk.getBitmask());
    Type.VAR_INT.write(output, buf.readableBytes());
    output.writeBytes(buf, buf.readableBytes());
    buf.release();
}
 
Example 2
Source File: Chunk1_15Type.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());

    output.writeBoolean(chunk.isFullChunk());
    Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
    Type.NBT.write(output, chunk.getHeightMap());

    // Write biome data
    if (chunk.isBiomeData()) {
        for (int value : chunk.getBiomeData()) {
            output.writeInt(value);
        }
    }

    ByteBuf buf = output.alloc().buffer();
    try {
        for (int i = 0; i < 16; i++) {
            ChunkSection section = chunk.getSections()[i];
            if (section == null) continue; // Section not set

            buf.writeShort(section.getNonAirBlocksCount());
            Types1_13.CHUNK_SECTION.write(buf, section);
        }
        buf.readerIndex(0);
        Type.VAR_INT.writePrimitive(output, buf.readableBytes());
        output.writeBytes(buf);
    } finally {
        buf.release(); // release buffer
    }

    // Write Block Entities
    Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
 
Example 3
Source File: Chunk1_9_3_4Type.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());

    output.writeBoolean(chunk.isFullChunk());
    Type.VAR_INT.writePrimitive(output, chunk.getBitmask());

    ByteBuf buf = output.alloc().buffer();
    try {
        for (int i = 0; i < 16; i++) {
            ChunkSection section = chunk.getSections()[i];
            if (section == null) continue; // Section not set
            Types1_9.CHUNK_SECTION.write(buf, section);
            section.writeBlockLight(buf);

            if (!section.hasSkyLight()) continue; // No sky light, we're done here.
            section.writeSkyLight(buf);
        }
        buf.readerIndex(0);
        Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
        output.writeBytes(buf);
    } finally {
        buf.release(); // release buffer
    }

    // Write biome data
    if (chunk.isBiomeData()) {
        for (int biome : chunk.getBiomeData()) {
            output.writeByte((byte) biome);
        }
    }

    // Write Block Entities
    Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
 
Example 4
Source File: Chunk1_14Type.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());

    output.writeBoolean(chunk.isFullChunk());
    Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
    Type.NBT.write(output, chunk.getHeightMap());

    ByteBuf buf = output.alloc().buffer();
    try {
        for (int i = 0; i < 16; i++) {
            ChunkSection section = chunk.getSections()[i];
            if (section == null) continue; // Section not set

            buf.writeShort(section.getNonAirBlocksCount());
            Types1_13.CHUNK_SECTION.write(buf, section);
        }
        buf.readerIndex(0);
        Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0)); // 256 * 4
        output.writeBytes(buf);
    } finally {
        buf.release(); // release buffer
    }

    // Write biome data
    if (chunk.isBiomeData()) {
        for (int value : chunk.getBiomeData()) {
            output.writeInt(value & 0xFF); // This is a temporary workaround, we'll look into fixing this soon :)
        }
    }

    // Write Block Entities
    Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
 
Example 5
Source File: Chunk1_16Type.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());

    output.writeBoolean(chunk.isFullChunk());
    output.writeBoolean(chunk.isIgnoreOldLightData());
    Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
    Type.NBT.write(output, chunk.getHeightMap());

    // Write biome data
    if (chunk.isBiomeData()) {
        for (int value : chunk.getBiomeData()) {
            output.writeInt(value);
        }
    }

    ByteBuf buf = output.alloc().buffer();
    try {
        for (int i = 0; i < 16; i++) {
            ChunkSection section = chunk.getSections()[i];
            if (section == null) continue; // Section not set

            buf.writeShort(section.getNonAirBlocksCount());
            Types1_16.CHUNK_SECTION.write(buf, section);
        }
        buf.readerIndex(0);
        Type.VAR_INT.writePrimitive(output, buf.readableBytes());
        output.writeBytes(buf);
    } finally {
        buf.release(); // release buffer
    }

    // Write Block Entities
    Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
 
Example 6
Source File: Chunk1_13Type.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());

    output.writeBoolean(chunk.isFullChunk());
    Type.VAR_INT.writePrimitive(output, chunk.getBitmask());

    ByteBuf buf = output.alloc().buffer();
    try {
        for (int i = 0; i < 16; i++) {
            ChunkSection section = chunk.getSections()[i];
            if (section == null) continue; // Section not set
            Types1_13.CHUNK_SECTION.write(buf, section);
            section.writeBlockLight(buf);

            if (!section.hasSkyLight()) continue; // No sky light, we're done here.
            section.writeSkyLight(buf);

        }
        buf.readerIndex(0);
        Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0));
        output.writeBytes(buf);
    } finally {
        buf.release(); // release buffer
    }

    // Write biome data
    if (chunk.isBiomeData()) {
        for (int value : chunk.getBiomeData()) {
            output.writeInt(value);
        }
    }

    // Write Block Entities
    Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
 
Example 7
Source File: Chunk1_9_1_2Type.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());

    output.writeBoolean(chunk.isFullChunk());
    Type.VAR_INT.writePrimitive(output, chunk.getBitmask());

    ByteBuf buf = output.alloc().buffer();
    try {
        for (int i = 0; i < 16; i++) {
            ChunkSection section = chunk.getSections()[i];
            if (section == null) continue; // Section not set
            Types1_9.CHUNK_SECTION.write(buf, section);
            section.writeBlockLight(buf);

            if (!section.hasSkyLight()) continue; // No sky light, we're done here.
            section.writeSkyLight(buf);

        }
        buf.readerIndex(0);
        Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
        output.writeBytes(buf);
    } finally {
        buf.release(); // release buffer
    }

    // Write biome data
    if (chunk.isBiomeData()) {
        for (int biome : chunk.getBiomeData()) {
            output.writeByte((byte) biome);
        }
    }
}