Search in sources :

Example 1 with BiomeGenerationSettings

use of org.spongepowered.api.world.biome.BiomeGenerationSettings in project Skree by Skelril.

the class NoOreWorldGeneratorModifier method modifyWorldGenerator.

@Override
public void modifyWorldGenerator(WorldProperties world, DataContainer settings, WorldGenerator worldGenerator) {
    for (BiomeType biomeType : Sponge.getRegistry().getAllOf(BiomeType.class)) {
        BiomeGenerationSettings biomeData = worldGenerator.getBiomeSettings(biomeType);
        List<Ore> populators = biomeData.getPopulators(Ore.class);
        biomeData.getPopulators().removeAll(populators);
    }
}
Also used : BiomeType(org.spongepowered.api.world.biome.BiomeType) Ore(org.spongepowered.api.world.gen.populator.Ore) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings)

Example 2 with BiomeGenerationSettings

use of org.spongepowered.api.world.biome.BiomeGenerationSettings in project SpongeCommon by SpongePowered.

the class SpongeChunkGenerator method populate.

@Override
public void populate(int chunkX, int chunkZ) {
    IMixinWorldServer world = (IMixinWorldServer) this.world;
    world.getTimingsHandler().chunkPopulate.startTimingIfSync();
    this.chunkGeneratorTiming.startTimingIfSync();
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    this.rand.setSeed(this.world.getSeed());
    long i1 = this.rand.nextLong() / 2L * 2L + 1L;
    long j1 = this.rand.nextLong() / 2L * 2L + 1L;
    this.rand.setSeed(chunkX * i1 + chunkZ * j1 ^ this.world.getSeed());
    BlockFalling.fallInstantly = true;
    // Have to regeneate the biomes so that any virtual biomes can be passed
    // to the populator.
    this.cachedBiomes.reuse(new Vector3i(chunkX * 16, 0, chunkZ * 16));
    this.biomeGenerator.generateBiomes(this.cachedBiomes);
    ImmutableBiomeVolume biomeBuffer = this.cachedBiomes.getImmutableBiomeCopy();
    BlockPos blockpos = new BlockPos(chunkX * 16, 0, chunkZ * 16);
    BiomeType biome = (BiomeType) this.world.getBiome(blockpos.add(16, 0, 16));
    org.spongepowered.api.world.Chunk chunk = (org.spongepowered.api.world.Chunk) this.world.getChunkFromChunkCoords(chunkX, chunkZ);
    BiomeGenerationSettings settings = getBiomeSettings(biome);
    List<Populator> populators = new ArrayList<>(this.pop);
    Populator snowPopulator = null;
    Iterator<Populator> itr = populators.iterator();
    while (itr.hasNext()) {
        Populator populator = itr.next();
        if (populator instanceof SnowPopulator) {
            itr.remove();
            snowPopulator = populator;
            break;
        }
    }
    populators.addAll(settings.getPopulators());
    if (snowPopulator != null) {
        populators.add(snowPopulator);
    }
    Sponge.getGame().getEventManager().post(SpongeEventFactory.createPopulateChunkEventPre(Sponge.getCauseStackManager().getCurrentCause(), populators, chunk));
    List<String> flags = Lists.newArrayList();
    Vector3i min = new Vector3i(chunkX * 16 + 8, 0, chunkZ * 16 + 8);
    org.spongepowered.api.world.World spongeWorld = (org.spongepowered.api.world.World) this.world;
    Extent volume = new SoftBufferExtentViewDownsize(chunk.getWorld(), min, min.add(15, 255, 15), min.sub(8, 0, 8), min.add(23, 255, 23));
    for (Populator populator : populators) {
        final PopulatorType type = populator.getType();
        if (type == null) {
            System.err.printf("Found a populator with a null type: %s populator%n", populator);
        }
        if (Sponge.getGame().getEventManager().post(SpongeEventFactory.createPopulateChunkEventPopulate(Sponge.getCauseStackManager().getCurrentCause(), populator, chunk))) {
            continue;
        }
        try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
            Timing timing = null;
            if (Timings.isTimingsEnabled()) {
                timing = this.populatorTimings.get(populator.getType().getId());
                if (timing == null) {
                    // ,
                    timing = SpongeTimingsFactory.ofSafe("populate - " + populator.getType().getId());
                    // this.chunkGeneratorTiming);
                    this.populatorTimings.put(populator.getType().getId(), timing);
                }
                timing.startTimingIfSync();
            }
            try (PhaseContext<?> context = GenerationPhase.State.POPULATOR_RUNNING.createPhaseContext().world(world).populator(type).buildAndSwitch()) {
                if (populator instanceof IFlaggedPopulator) {
                    ((IFlaggedPopulator) populator).populate(spongeWorld, volume, this.rand, biomeBuffer, flags);
                } else {
                    populator.populate(spongeWorld, volume, this.rand, biomeBuffer);
                }
                if (Timings.isTimingsEnabled()) {
                    timing.stopTimingIfSync();
                }
            }
        }
    }
    // populate method so that its particular changes are used.
    if (this.baseGenerator instanceof SpongeGenerationPopulator) {
        Timing timing = null;
        if (Timings.isTimingsEnabled()) {
            IGenerationPopulator spongePopulator = (IGenerationPopulator) this.baseGenerator;
            timing = spongePopulator.getTimingsHandler();
            timing.startTimingIfSync();
        }
        ((SpongeGenerationPopulator) this.baseGenerator).getHandle(this.world).populate(chunkX, chunkZ);
        if (Timings.isTimingsEnabled()) {
            timing.stopTimingIfSync();
        }
    }
    PopulateChunkEvent.Post event = SpongeEventFactory.createPopulateChunkEventPost(Sponge.getCauseStackManager().getCurrentCause(), ImmutableList.copyOf(populators), chunk);
    SpongeImpl.postEvent(event);
    BlockFalling.fallInstantly = false;
    this.chunkGeneratorTiming.stopTimingIfSync();
    world.getTimingsHandler().chunkPopulate.stopTimingIfSync();
}
Also used : Extent(org.spongepowered.api.world.extent.Extent) ArrayList(java.util.ArrayList) IGenerationPopulator(org.spongepowered.common.interfaces.world.gen.IGenerationPopulator) PopulatorType(org.spongepowered.api.world.gen.PopulatorType) World(net.minecraft.world.World) BiomeType(org.spongepowered.api.world.biome.BiomeType) SoftBufferExtentViewDownsize(org.spongepowered.common.world.extent.SoftBufferExtentViewDownsize) ChunkGeneratorOverworld(net.minecraft.world.gen.ChunkGeneratorOverworld) IChunkProviderOverworld(org.spongepowered.common.interfaces.world.gen.IChunkProviderOverworld) CauseStackManager(org.spongepowered.api.event.CauseStackManager) BlockPos(net.minecraft.util.math.BlockPos) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) SpongeBiomeGenerationSettings(org.spongepowered.common.world.biome.SpongeBiomeGenerationSettings) GenerationPopulator(org.spongepowered.api.world.gen.GenerationPopulator) Populator(org.spongepowered.api.world.gen.Populator) IFlaggedPopulator(org.spongepowered.common.interfaces.world.gen.IFlaggedPopulator) SnowPopulator(org.spongepowered.common.world.gen.populators.SnowPopulator) IGenerationPopulator(org.spongepowered.common.interfaces.world.gen.IGenerationPopulator) ImmutableBiomeVolume(org.spongepowered.api.world.extent.ImmutableBiomeVolume) IFlaggedPopulator(org.spongepowered.common.interfaces.world.gen.IFlaggedPopulator) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) PopulateChunkEvent(org.spongepowered.api.event.world.chunk.PopulateChunkEvent) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) Vector3i(com.flowpowered.math.vector.Vector3i) SnowPopulator(org.spongepowered.common.world.gen.populators.SnowPopulator) Timing(co.aikar.timings.Timing)

Example 3 with BiomeGenerationSettings

use of org.spongepowered.api.world.biome.BiomeGenerationSettings 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;
}
Also used : ImmutableBiomeVolume(org.spongepowered.api.world.extent.ImmutableBiomeVolume) EventManager(org.spongepowered.api.event.EventManager) Extent(org.spongepowered.api.world.extent.Extent) BiomeGenerator(org.spongepowered.api.world.gen.BiomeGenerator) LinkedList(java.util.LinkedList) VirtualBiomeType(org.spongepowered.api.world.biome.VirtualBiomeType) BiomeType(org.spongepowered.api.world.biome.BiomeType) SoftBufferExtentViewDownsize(org.lanternpowered.server.world.extent.SoftBufferExtentViewDownsize) Vector3i(com.flowpowered.math.vector.Vector3i) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) GenerationPopulator(org.spongepowered.api.world.gen.GenerationPopulator) Populator(org.spongepowered.api.world.gen.Populator)

Example 4 with BiomeGenerationSettings

use of org.spongepowered.api.world.biome.BiomeGenerationSettings 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 5 with BiomeGenerationSettings

use of org.spongepowered.api.world.biome.BiomeGenerationSettings in project SpongeAPI by SpongePowered.

the class VoidWorldGeneratorModifier method modifyWorldGenerator.

@Override
public void modifyWorldGenerator(WorldProperties world, DataContainer settings, WorldGenerator worldGenerator) {
    worldGenerator.getGenerationPopulators().clear();
    worldGenerator.getPopulators().clear();
    for (BiomeType biome : Sponge.getRegistry().getAllOf(BiomeType.class)) {
        BiomeGenerationSettings biomeSettings = worldGenerator.getBiomeSettings(biome);
        biomeSettings.getGenerationPopulators().clear();
        biomeSettings.getPopulators().clear();
        biomeSettings.getGroundCoverLayers().clear();
    }
    worldGenerator.setBaseGenerationPopulator((world1, buffer, biomes) -> {
    });
    worldGenerator.setBiomeGenerator(buffer -> buffer.getBiomeWorker().fill((x, y, z) -> BiomeTypes.VOID));
}
Also used : WorldGenerator(org.spongepowered.api.world.gen.WorldGenerator) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Sponge(org.spongepowered.api.Sponge) DataContainer(org.spongepowered.api.data.DataContainer) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) BiomeType(org.spongepowered.api.world.biome.BiomeType) BiomeTypes(org.spongepowered.api.world.biome.BiomeTypes) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) BiomeType(org.spongepowered.api.world.biome.BiomeType) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings)

Aggregations

BiomeGenerationSettings (org.spongepowered.api.world.biome.BiomeGenerationSettings)10 BiomeType (org.spongepowered.api.world.biome.BiomeType)8 Vector3i (com.flowpowered.math.vector.Vector3i)5 ImmutableBiomeVolume (org.spongepowered.api.world.extent.ImmutableBiomeVolume)5 GenerationPopulator (org.spongepowered.api.world.gen.GenerationPopulator)5 World (net.minecraft.world.World)4 SpongeBiomeGenerationSettings (org.spongepowered.common.world.biome.SpongeBiomeGenerationSettings)4 Extent (org.spongepowered.api.world.extent.Extent)3 Populator (org.spongepowered.api.world.gen.Populator)3 IGenerationPopulator (org.spongepowered.common.interfaces.world.gen.IGenerationPopulator)3 Timing (co.aikar.timings.Timing)2 ArrayList (java.util.ArrayList)2 BlockPos (net.minecraft.util.math.BlockPos)2 Chunk (net.minecraft.world.chunk.Chunk)2 ChunkGeneratorOverworld (net.minecraft.world.gen.ChunkGeneratorOverworld)2 EventManager (org.spongepowered.api.event.EventManager)2 VirtualBiomeType (org.spongepowered.api.world.biome.VirtualBiomeType)2 BiomeGenerator (org.spongepowered.api.world.gen.BiomeGenerator)2 PopulatorType (org.spongepowered.api.world.gen.PopulatorType)2 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)2