use of org.bukkit.generator.BlockPopulator 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) {
if (world.getServer().isGenerationDisabled()) {
return;
}
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.getInstance().callEvent(new ChunkPopulateEvent(chunk));
}
Aggregations