use of org.spongepowered.api.world.gen.GenerationPopulator in project SpongeCommon by SpongePowered.
the class SpongeBiomeGenerationSettingsBuilder method generationPopulators.
@Override
public Builder generationPopulators(Iterable<GenerationPopulator> genpop) {
checkNotNull(genpop, "genpop");
this.genpop.clear();
for (GenerationPopulator pop : genpop) {
this.genpop.add(checkNotNull(pop, "pop"));
}
return this;
}
use of org.spongepowered.api.world.gen.GenerationPopulator in project LanternServer by LanternPowered.
the class LanternChunkManager method generate.
/**
* Attempts to generate the chunk.
*
* @param chunk The chunk
* @param cause The cause
*/
private void generate(LanternChunk chunk, Cause cause) {
final EventManager eventManager = Sponge.getEventManager();
eventManager.post(SpongeEventFactory.createGenerateChunkEventPre(cause, chunk));
final GenerationBuffers buffers = this.genBuffers.get();
// noinspection ConstantConditions
final ChunkBiomeBuffer biomeBuffer = buffers.chunkBiomeBuffer;
biomeBuffer.reuse(new Vector3i(chunk.getX() << 4, 0, chunk.getZ() << 4));
// Generate the biomes
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());
final ChunkBlockBuffer blockBuffer = buffers.chunkBlockBuffer;
blockBuffer.reuse(new Vector3i(chunk.getX() << 4, 0, chunk.getZ() << 4));
// Apply the main world generator
final GenerationPopulator baseGenerator = this.worldGenerator.getBaseGenerationPopulator();
baseGenerator.populate(this.world, blockBuffer, immutableBiomeVolume);
// Get all the used biome types
final Set<BiomeType> biomeTypes = ImmutableSet.copyOf(biomeBuffer.biomeTypes);
for (BiomeType biomeType : biomeTypes) {
final BiomeGenerationSettings settings = this.worldGenerator.getBiomeSettings(biomeType);
for (GenerationPopulator generator : settings.getGenerationPopulators()) {
generator.populate(this.world, blockBuffer, immutableBiomeVolume);
}
}
// Apply the generator populators to complete the block buffer
for (GenerationPopulator generator : this.worldGenerator.getGenerationPopulators()) {
generator.populate(this.world, blockBuffer, immutableBiomeVolume);
}
// Create the chunk sections
final ChunkSection[] sections = new ChunkSection[CHUNK_SECTIONS];
for (int sy = 0; sy < CHUNK_SECTIONS; sy++) {
final int nonAirCount = blockBuffer.nonAirCount[sy];
if (nonAirCount > 0) {
sections[sy] = new ChunkSection(blockBuffer.types[sy]);
}
}
// Initialize the chunk
chunk.initializeSections(sections);
chunk.initializeHeightMap(null);
chunk.initializeLight();
eventManager.post(SpongeEventFactory.createGenerateChunkEventPost(cause, chunk));
}
use of org.spongepowered.api.world.gen.GenerationPopulator in project LanternServer by LanternPowered.
the class LanternBiomeGenerationSettingsBuilder method generationPopulators.
@Override
public Builder generationPopulators(GenerationPopulator... populators) {
checkNotNull(populators, "populators");
this.generationPopulators.clear();
for (GenerationPopulator populator : populators) {
this.generationPopulators.add(checkNotNull(populator, "populator"));
}
return this;
}
use of org.spongepowered.api.world.gen.GenerationPopulator in project SpongeCommon by SpongePowered.
the class SpongeBiomeGenerationSettingsBuilder method generationPopulators.
@Override
public Builder generationPopulators(GenerationPopulator... genpop) {
checkNotNull(genpop, "genpop");
this.genpop.clear();
for (GenerationPopulator pop : genpop) {
this.genpop.add(checkNotNull(pop, "pop"));
}
return this;
}
use of org.spongepowered.api.world.gen.GenerationPopulator 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