cn.nukkit.level.generator.Normal Java Examples

The following examples show how to use cn.nukkit.level.generator.Normal. 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: PopulatorGroundCover.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    int realX = chunkX << 4;
    int realZ = chunkZ << 4;
    for (int x = 0; x < 16; ++x) {
        for (int z = 0; z < 16; ++z) {
            Biome realBiome = EnumBiome.getBiome(chunk.getBiomeId(x, z));
            if (realBiome instanceof CoveredBiome) {
                final CoveredBiome biome = (CoveredBiome) realBiome;
                //just in case!
                synchronized (biome.synchronizeCover) {
                    biome.preCover(realX | x, realZ | z);
                    int coverBlock = biome.getCoverBlock() << 4;

                    boolean hasCovered = false;
                    int realY;
                    //start one below build limit in case of cover blocks
                    for (int y = 254; y > 32; y--) {
                        if (chunk.getFullBlock(x, y, z) == STONE) {
                            COVER:
                            if (!hasCovered) {
                                if (y >= Normal.seaHeight) {
                                    chunk.setFullBlockId(x, y + 1, z, coverBlock);
                                    int surfaceDepth = biome.getSurfaceDepth(y);
                                    for (int i = 0; i < surfaceDepth; i++) {
                                        realY = y - i;
                                        if (chunk.getFullBlock(x, realY, z) == STONE) {
                                            chunk.setFullBlockId(x, realY, z, (biome.getSurfaceBlock(realY) << 4) | biome.getSurfaceMeta(realY));
                                        } else break COVER;
                                    }
                                    y -= surfaceDepth;
                                }
                                int groundDepth = biome.getGroundDepth(y);
                                for (int i = 0; i < groundDepth; i++) {
                                    realY = y - i;
                                    if (chunk.getFullBlock(x, realY, z) == STONE) {
                                        chunk.setFullBlockId(x, realY, z, (biome.getGroundBlock(realY) << 4) | biome.getGroundMeta(realY));
                                    } else break COVER;
                                }
                                //don't take all of groundDepth away because we do y-- in the loop
                                y -= groundDepth - 1;
                            }
                            hasCovered = true;
                        } else {
                            if (hasCovered) {
                                //reset it if this isn't a valid stone block (allows us to place ground cover on top and below overhangs)
                                hasCovered = false;
                            }
                        }
                    }
                }
            }
        }
    }
}