Search in sources :

Example 1 with ChunkPrimerBuffer

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;
}
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

Vector3i (com.flowpowered.math.vector.Vector3i)1 Chunk (net.minecraft.world.chunk.Chunk)1 ChunkPrimer (net.minecraft.world.chunk.ChunkPrimer)1 ChunkGeneratorOverworld (net.minecraft.world.gen.ChunkGeneratorOverworld)1 BiomeGenerationSettings (org.spongepowered.api.world.biome.BiomeGenerationSettings)1 BiomeType (org.spongepowered.api.world.biome.BiomeType)1 ImmutableBiomeVolume (org.spongepowered.api.world.extent.ImmutableBiomeVolume)1 MutableBlockVolume (org.spongepowered.api.world.extent.MutableBlockVolume)1 GenerationPopulator (org.spongepowered.api.world.gen.GenerationPopulator)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