Java Code Examples for us.myles.ViaVersion.api.minecraft.chunks.ChunkSection#hasSkyLight()

The following examples show how to use us.myles.ViaVersion.api.minecraft.chunks.ChunkSection#hasSkyLight() . 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_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 2
Source File: Chunk1_9to1_8Type.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientChunks param, Chunk input) throws Exception {
    if (!(input instanceof Chunk1_8)) throw new Exception("Incompatible chunk, " + input.getClass());

    Chunk1_8 chunk = (Chunk1_8) input;
    // Write primary info
    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());
    if (chunk.isUnloadPacket()) return;
    output.writeByte(chunk.isFullChunk() ? 0x01 : 0x00);
    Type.VAR_INT.writePrimitive(output, chunk.getBitmask());

    ByteBuf buf = output.alloc().buffer();
    try {
        for (int i = 0; i < SECTION_COUNT; 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.hasBiomeData() ? 256 : 0));
        output.writeBytes(buf);
    } finally {
        buf.release(); // release buffer
    }

    // Write biome data
    if (chunk.hasBiomeData()) {
        for (int biome : chunk.getBiomeData()) {
            output.writeByte((byte) biome);
        }
    }
}
 
Example 3
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 4
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);
        }
    }
}
 
Example 5
Source File: WorldPackets.java    From ViaVersion with MIT License 4 votes vote down vote up
private static void setNonFullLight(Chunk chunk, ChunkSection section, int ySection, int x, int y, int z) {
    int skyLight = 0;
    int blockLight = 0;
    for (BlockFace blockFace : BlockFace.values()) {
        NibbleArray skyLightArray = section.getSkyLightNibbleArray();
        NibbleArray blockLightArray = section.getBlockLightNibbleArray();
        int neighbourX = x + blockFace.getModX();
        int neighbourY = y + blockFace.getModY();
        int neighbourZ = z + blockFace.getModZ();

        if (blockFace.getModX() != 0) {
            // Another chunk, nothing we can do without an unnecessary amount of caching
            if (neighbourX == 16 || neighbourX == -1) continue;
        } else if (blockFace.getModY() != 0) {
            if (neighbourY == 16 || neighbourY == -1) {
                if (neighbourY == 16) {
                    ySection += 1;
                    neighbourY = 0;
                } else {
                    ySection -= 1;
                    neighbourY = 15;
                }

                if (ySection == 16 || ySection == -1) continue;

                ChunkSection newSection = chunk.getSections()[ySection];
                if (newSection == null) continue;

                skyLightArray = newSection.getSkyLightNibbleArray();
                blockLightArray = newSection.getBlockLightNibbleArray();
            }
        } else if (blockFace.getModZ() != 0) {
            // Another chunk, nothing we can do without an unnecessary amount of caching
            if (neighbourZ == 16 || neighbourZ == -1) continue;
        }

        if (blockLightArray != null && blockLight != 15) {
            int neighbourBlockLight = blockLightArray.get(neighbourX, neighbourY, neighbourZ);
            if (neighbourBlockLight == 15) {
                blockLight = 14;
            } else if (neighbourBlockLight > blockLight) {
                blockLight = neighbourBlockLight - 1; // lower light level by one
            }
        }
        if (skyLightArray != null && skyLight != 15) {
            int neighbourSkyLight = skyLightArray.get(neighbourX, neighbourY, neighbourZ);
            if (neighbourSkyLight == 15) {
                if (blockFace.getModY() == 1) {
                    // Keep 15 if block is exposed to sky
                    skyLight = 15;
                    continue;
                }

                skyLight = 14;
            } else if (neighbourSkyLight > skyLight) {
                skyLight = neighbourSkyLight - 1; // lower light level by one
            }
        }
    }

    if (skyLight != 0) {
        if (!section.hasSkyLight()) {
            byte[] newSkyLight = new byte[2028];
            section.setSkyLight(newSkyLight);
        }

        section.getSkyLightNibbleArray().set(x, y, z, skyLight);
    }
    if (blockLight != 0) {
        section.getBlockLightNibbleArray().set(x, y, z, blockLight);
    }
}