Search in sources :

Example 1 with GlowChunkData

use of net.glowstone.generator.GlowChunkData in project Glowstone by GlowstoneMC.

the class ChunkManager method generateChunk.

/**
 * Initialize a single chunk from the chunk generator.
 */
private void generateChunk(GlowChunk chunk, int x, int z) {
    Random random = new Random(x * 341873128712L + z * 132897987541L);
    BiomeGrid biomes = new BiomeGrid();
    int[] biomeValues = biomeGrid[0].generateValues(x * GlowChunk.WIDTH, z * GlowChunk.HEIGHT, GlowChunk.WIDTH, GlowChunk.HEIGHT);
    for (int i = 0; i < biomeValues.length; i++) {
        biomes.biomes[i] = (byte) biomeValues[i];
    }
    // extended sections with data
    GlowChunkData glowChunkData = null;
    if (generator instanceof GlowChunkGenerator) {
        glowChunkData = (GlowChunkData) generator.generateChunkData(world, random, x, z, biomes);
    } else {
        ChunkGenerator.ChunkData chunkData = generator.generateChunkData(world, random, x, z, biomes);
        if (chunkData != null) {
            glowChunkData = new GlowChunkData(world);
            for (int i = 0; i < 16; ++i) {
                for (int j = 0; j < 16; ++j) {
                    int maxHeight = chunkData.getMaxHeight();
                    for (int k = 0; k < maxHeight; ++k) {
                        MaterialData materialData = chunkData.getTypeAndData(i, k, j);
                        glowChunkData.setBlock(i, k, j, materialData == null ? new MaterialData(Material.AIR) : materialData);
                    }
                }
            }
        }
    }
    if (glowChunkData != null) {
        short[][] extSections = glowChunkData.getSections();
        if (extSections != null) {
            ChunkSection[] sections = new ChunkSection[extSections.length];
            for (int i = 0; i < extSections.length; ++i) {
                if (extSections[i] != null) {
                    sections[i] = ChunkSection.fromStateArray(extSections[i]);
                }
            }
            chunk.initializeSections(sections);
            chunk.setBiomes(biomes.biomes);
            chunk.automaticHeightMap();
            return;
        }
    }
    chunk.setBiomes(biomes.biomes);
    chunk.automaticHeightMap();
}
Also used : GlowChunkData(net.glowstone.generator.GlowChunkData) Random(java.util.Random) GlowChunkGenerator(net.glowstone.generator.GlowChunkGenerator) MaterialData(org.bukkit.material.MaterialData) ChunkGenerator(org.bukkit.generator.ChunkGenerator) GlowChunkGenerator(net.glowstone.generator.GlowChunkGenerator)

Aggregations

Random (java.util.Random)1 GlowChunkData (net.glowstone.generator.GlowChunkData)1 GlowChunkGenerator (net.glowstone.generator.GlowChunkGenerator)1 ChunkGenerator (org.bukkit.generator.ChunkGenerator)1 MaterialData (org.bukkit.material.MaterialData)1