Search in sources :

Example 1 with ChunkPopulateEvent

use of org.bukkit.event.world.ChunkPopulateEvent in project Glowstone by GlowstoneMC.

the class ChunkManager method populateChunk.

/**
     * Populate a single chunk if needed.
     */
private void populateChunk(int x, int z, boolean force) {
    GlowChunk chunk = getChunk(x, z);
    // cancel out if it's already populated
    if (chunk.isPopulated()) {
        return;
    }
    // cancel out if the 3x3 around it isn't available
    for (int x2 = x - 1; x2 <= x + 1; ++x2) {
        for (int z2 = z - 1; z2 <= z + 1; ++z2) {
            if (!getChunk(x2, z2).isLoaded() && (!force || !loadChunk(x2, z2, true))) {
                return;
            }
        }
    }
    // it might have loaded since before, so check again that it's not already populated
    if (chunk.isPopulated()) {
        return;
    }
    chunk.setPopulated(true);
    Random random = new Random(world.getSeed());
    long xRand = (random.nextLong() / 2 << 1) + 1;
    long zRand = (random.nextLong() / 2 << 1) + 1;
    random.setSeed(x * xRand + z * zRand ^ world.getSeed());
    for (BlockPopulator p : world.getPopulators()) {
        p.populate(world, random, chunk);
    }
    EventFactory.callEvent(new ChunkPopulateEvent(chunk));
}
Also used : BlockPopulator(org.bukkit.generator.BlockPopulator) ChunkPopulateEvent(org.bukkit.event.world.ChunkPopulateEvent)

Aggregations

ChunkPopulateEvent (org.bukkit.event.world.ChunkPopulateEvent)1 BlockPopulator (org.bukkit.generator.BlockPopulator)1