use of org.lanternpowered.server.world.extent.SoftBufferExtentViewDownsize in project LanternServer by LanternPowered.
the class LanternChunkManager method populateChunk.
private void populateChunk(LanternChunk chunk, Cause cause, Random random) {
chunk.populating = true;
// Populate
int chunkX = chunk.getX() * 16;
int chunkZ = chunk.getZ() * 16;
long worldSeed = this.world.getProperties().getSeed();
random.setSeed(worldSeed);
long xSeed = random.nextLong() / 2 * 2 + 1;
long zSeed = random.nextLong() / 2 * 2 + 1;
long chunkSeed = xSeed * chunkX + zSeed * chunkZ ^ worldSeed;
random.setSeed(chunkSeed);
// noinspection ConstantConditions
final ChunkBiomeBuffer biomeBuffer = this.genBuffers.get().chunkBiomeBuffer;
biomeBuffer.reuse(new Vector3i(chunkX + 8, 0, chunkZ + 8));
// We ave to regenerate the biomes so that any
// virtual biomes can be passed to the populator.
final BiomeGenerator biomeGenerator = this.worldGenerator.getBiomeGenerator();
biomeGenerator.generateBiomes(biomeBuffer);
// Initialize the biomes into the chunk
final ImmutableBiomeVolume immutableBiomeVolume = biomeBuffer.getImmutableBiomeCopy();
chunk.initializeBiomes(biomeBuffer.detach().clone());
// Using the biome at an arbitrary point within the chunk
// ({16, 0, 16} in the vanilla game)
final BiomeType biomeType = immutableBiomeVolume.getBiome(chunkX + 16, 0, chunkZ + 16);
// Get the generation settings
final BiomeGenerationSettings biomeGenSettings = this.worldGenerator.getBiomeSettings(biomeType);
final List<Populator> populators = new LinkedList<>(biomeGenSettings.getPopulators());
populators.addAll(this.worldGenerator.getPopulators());
final EventManager eventManager = Sponge.getEventManager();
final Vector3i min = new Vector3i(chunkX + 8, 0, chunkZ + 8);
final Extent volume = new SoftBufferExtentViewDownsize(chunk.getWorld(), min, min.add(15, 0, 15), min.sub(8, 0, 8), min.add(23, 0, 23));
// Call the pre populate event, this allows
// modifications to the populators list
// Called before a chunk begins populating. (javadoc)
eventManager.post(SpongeEventFactory.createPopulateChunkEventPre(cause, populators, chunk));
// First populate the chunk with the biome populators
for (Populator populator : populators) {
// Called when a populator is about to run against a chunk. (javadoc)
eventManager.post(SpongeEventFactory.createPopulateChunkEventPopulate(cause, populator, chunk));
populator.populate(this.world, volume, random);
}
// Called when a chunk finishes populating. (javadoc)
eventManager.post(SpongeEventFactory.createPopulateChunkEventPost(cause, ImmutableList.copyOf(populators), chunk));
this.world.getEventListener().onPopulateChunk(chunk);
// We are done
chunk.populated = true;
chunk.populating = false;
}
Aggregations