use of org.spongepowered.common.util.gen.ChunkPrimerBuffer in project SpongeCommon by SpongePowered.
the class SpongeChunkGenerator method generateChunk.
@Override
public Chunk generateChunk(int chunkX, int chunkZ) {
this.rand.setSeed(chunkX * 341873128712L + chunkZ * 132897987541L);
this.cachedBiomes.reuse(new Vector3i(chunkX * 16, 0, chunkZ * 16));
this.biomeGenerator.generateBiomes(this.cachedBiomes);
ImmutableBiomeVolume biomeBuffer = this.cachedBiomes.getImmutableBiomeCopy();
// Generate base terrain
ChunkPrimer chunkprimer = new ChunkPrimer();
MutableBlockVolume blockBuffer = new ChunkPrimerBuffer(chunkprimer, chunkX, chunkZ);
this.baseGenerator.populate((org.spongepowered.api.world.World) this.world, blockBuffer, biomeBuffer);
if (!(this.baseGenerator instanceof SpongeGenerationPopulator)) {
replaceBiomeBlocks(this.world, this.rand, chunkX, chunkZ, chunkprimer, biomeBuffer);
}
// Apply the generator populators to complete the blockBuffer
for (GenerationPopulator populator : this.genpop) {
populator.populate((org.spongepowered.api.world.World) this.world, blockBuffer, biomeBuffer);
}
// Get unique biomes to determine what generator populators to run
List<BiomeType> uniqueBiomes = Lists.newArrayList();
BiomeType biome;
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
biome = this.cachedBiomes.getBiome(chunkX * 16 + x, 0, chunkZ * 16 + z);
if (!uniqueBiomes.contains(biome)) {
uniqueBiomes.add(biome);
}
}
}
// run our generator populators
for (BiomeType type : uniqueBiomes) {
BiomeGenerationSettings settings = getBiomeSettings(type);
for (GenerationPopulator populator : settings.getGenerationPopulators()) {
populator.populate((org.spongepowered.api.world.World) this.world, blockBuffer, biomeBuffer);
}
}
// Assemble chunk
Chunk chunk;
if (this.baseGenerator instanceof SpongeGenerationPopulator && ((SpongeGenerationPopulator) this.baseGenerator).getCachedChunk() != null) {
chunk = ((SpongeGenerationPopulator) this.baseGenerator).getCachedChunk();
((IMixinChunk) chunk).fill(chunkprimer);
} else {
chunk = new Chunk(this.world, chunkprimer, chunkX, chunkZ);
this.cachedBiomes.fill(chunk.getBiomeArray());
}
chunk.generateSkylightMap();
return chunk;
}
Aggregations