Search in sources :

Example 1 with GenerationPopulator

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;
}
Also used : GenerationPopulator(org.spongepowered.api.world.gen.GenerationPopulator)

Example 2 with GenerationPopulator

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));
}
Also used : ImmutableBiomeVolume(org.spongepowered.api.world.extent.ImmutableBiomeVolume) EventManager(org.spongepowered.api.event.EventManager) BiomeGenerator(org.spongepowered.api.world.gen.BiomeGenerator) VirtualBiomeType(org.spongepowered.api.world.biome.VirtualBiomeType) BiomeType(org.spongepowered.api.world.biome.BiomeType) GenerationPopulator(org.spongepowered.api.world.gen.GenerationPopulator) Vector3i(com.flowpowered.math.vector.Vector3i) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) ChunkSection(org.lanternpowered.server.world.chunk.LanternChunk.ChunkSection)

Example 3 with GenerationPopulator

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;
}
Also used : GenerationPopulator(org.spongepowered.api.world.gen.GenerationPopulator)

Example 4 with GenerationPopulator

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;
}
Also used : GenerationPopulator(org.spongepowered.api.world.gen.GenerationPopulator)

Example 5 with GenerationPopulator

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;
}
Also used : ImmutableBiomeVolume(org.spongepowered.api.world.extent.ImmutableBiomeVolume) MutableBlockVolume(org.spongepowered.api.world.extent.MutableBlockVolume) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) ChunkPrimerBuffer(org.spongepowered.common.util.gen.ChunkPrimerBuffer) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) ChunkPrimer(net.minecraft.world.chunk.ChunkPrimer) BiomeType(org.spongepowered.api.world.biome.BiomeType) ChunkGeneratorOverworld(net.minecraft.world.gen.ChunkGeneratorOverworld) IChunkProviderOverworld(org.spongepowered.common.interfaces.world.gen.IChunkProviderOverworld) GenerationPopulator(org.spongepowered.api.world.gen.GenerationPopulator) IGenerationPopulator(org.spongepowered.common.interfaces.world.gen.IGenerationPopulator) Vector3i(com.flowpowered.math.vector.Vector3i) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) SpongeBiomeGenerationSettings(org.spongepowered.common.world.biome.SpongeBiomeGenerationSettings)

Aggregations

GenerationPopulator (org.spongepowered.api.world.gen.GenerationPopulator)6 Vector3i (com.flowpowered.math.vector.Vector3i)2 BiomeGenerationSettings (org.spongepowered.api.world.biome.BiomeGenerationSettings)2 BiomeType (org.spongepowered.api.world.biome.BiomeType)2 ImmutableBiomeVolume (org.spongepowered.api.world.extent.ImmutableBiomeVolume)2 Chunk (net.minecraft.world.chunk.Chunk)1 ChunkPrimer (net.minecraft.world.chunk.ChunkPrimer)1 ChunkGeneratorOverworld (net.minecraft.world.gen.ChunkGeneratorOverworld)1 ChunkSection (org.lanternpowered.server.world.chunk.LanternChunk.ChunkSection)1 EventManager (org.spongepowered.api.event.EventManager)1 VirtualBiomeType (org.spongepowered.api.world.biome.VirtualBiomeType)1 MutableBlockVolume (org.spongepowered.api.world.extent.MutableBlockVolume)1 BiomeGenerator (org.spongepowered.api.world.gen.BiomeGenerator)1 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)1 IChunkProviderOverworld (org.spongepowered.common.interfaces.world.gen.IChunkProviderOverworld)1 IGenerationPopulator (org.spongepowered.common.interfaces.world.gen.IGenerationPopulator)1 ChunkPrimerBuffer (org.spongepowered.common.util.gen.ChunkPrimerBuffer)1 SpongeBiomeGenerationSettings (org.spongepowered.common.world.biome.SpongeBiomeGenerationSettings)1