Search in sources :

Example 6 with BiomeGenerationSettings

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

the class MixinChunkGeneratorFlat method addPopulators.

@Override
public void addPopulators(WorldGenerator generator) {
    for (Object o : this.structureGenerators.values()) {
        if (o instanceof MapGenBase) {
            generator.getGenerationPopulators().add((GenerationPopulator) o);
            if (o instanceof MapGenStructure) {
                generator.getPopulators().add((Populator) o);
            }
        }
    }
    if (this.flatWorldGenInfo.getWorldFeatures().containsKey("lake")) {
        Lake lake = Lake.builder().chance(1 / 4d).liquidType((BlockState) Blocks.WATER.getDefaultState()).height(VariableAmount.baseWithRandomAddition(0, 256)).build();
        FilteredPopulator filtered = new FilteredPopulator(lake);
        filtered.setRequiredFlags(WorldGenConstants.VILLAGE_FLAG);
        generator.getPopulators().add(lake);
    }
    if (this.flatWorldGenInfo.getWorldFeatures().containsKey("lava_lake")) {
        Lake lake = Lake.builder().chance(1 / 8d).liquidType((BlockState) Blocks.WATER.getDefaultState()).height(VariableAmount.baseWithVariance(0, VariableAmount.baseWithRandomAddition(8, VariableAmount.baseWithOptionalAddition(55, 193, 0.1)))).build();
        FilteredPopulator filtered = new FilteredPopulator(lake);
        filtered.setRequiredFlags(WorldGenConstants.VILLAGE_FLAG);
        generator.getPopulators().add(filtered);
    }
    if (this.hasDungeons) {
        Dungeon dungeon = Dungeon.builder().attempts(8).build();
        generator.getPopulators().add(dungeon);
    }
    for (BiomeType type : Sponge.getRegistry().getAllOf(BiomeType.class)) {
        BiomeGenerationSettings settings = generator.getBiomeSettings(type);
        settings.getGroundCoverLayers().clear();
        if (!this.hasDecoration) {
            settings.getPopulators().clear();
            settings.getGenerationPopulators().clear();
        }
    }
}
Also used : BiomeType(org.spongepowered.api.world.biome.BiomeType) FilteredPopulator(org.spongepowered.common.world.gen.populators.FilteredPopulator) MapGenStructure(net.minecraft.world.gen.structure.MapGenStructure) Dungeon(org.spongepowered.api.world.gen.populator.Dungeon) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) Lake(org.spongepowered.api.world.gen.populator.Lake) MapGenBase(net.minecraft.world.gen.MapGenBase)

Example 7 with BiomeGenerationSettings

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

the class SpongeChunkGenerator method getBiomeSettings.

@Override
public BiomeGenerationSettings getBiomeSettings(BiomeType type) {
    checkNotNull(type, "type");
    BiomeGenerationSettings settings = this.biomeSettings.get(type);
    if (settings == null) {
        if (SpongeGenerationPopulator.class.isInstance(this.baseGenerator)) {
            // If the base generator was mod provided then we assume that it
            // will handle its own
            // generation so we don't add the base game's generation
            settings = new SpongeBiomeGenerationSettings();
        } else {
            settings = type.createDefaultGenerationSettings((org.spongepowered.api.world.World) this.world);
        }
        this.biomeSettings.put(type, settings);
    }
    return settings;
}
Also used : BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) SpongeBiomeGenerationSettings(org.spongepowered.common.world.biome.SpongeBiomeGenerationSettings) World(net.minecraft.world.World) SpongeBiomeGenerationSettings(org.spongepowered.common.world.biome.SpongeBiomeGenerationSettings)

Example 8 with BiomeGenerationSettings

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

Example 9 with BiomeGenerationSettings

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

the class SpongeWorldGenerator method getBiomeSettings.

@Override
public BiomeGenerationSettings getBiomeSettings(BiomeType type) {
    checkNotNull(type);
    BiomeGenerationSettings settings = this.biomeSettings.get(type);
    if (settings == null) {
        if (SpongeGenerationPopulator.class.isInstance(this.baseGenerator)) {
            // If the base generator was mod provided then we assume that it will handle its own
            // generation so we don't add the base game's generation
            settings = new SpongeBiomeGenerationSettings();
        } else {
            settings = type.createDefaultGenerationSettings((org.spongepowered.api.world.World) this.world);
        }
        this.biomeSettings.put(type, settings);
    }
    return settings;
}
Also used : SpongeBiomeGenerationSettings(org.spongepowered.common.world.biome.SpongeBiomeGenerationSettings) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) World(net.minecraft.world.World) SpongeBiomeGenerationSettings(org.spongepowered.common.world.biome.SpongeBiomeGenerationSettings)

Example 10 with BiomeGenerationSettings

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

the class SpongeChunkGeneratorForge method populate.

@Override
public void populate(int chunkX, int chunkZ) {
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    this.chunkGeneratorTiming.startTimingIfSync();
    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));
    Chunk chunk = (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));
    MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Pre(this, this.world, this.rand, chunkX, chunkZ, false));
    MinecraftForge.EVENT_BUS.post(new DecorateBiomeEvent.Pre(this.world, this.rand, blockpos));
    MinecraftForge.ORE_GEN_BUS.post(new OreGenEvent.Pre(this.world, this.rand, blockpos));
    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) {
        if (!(populator instanceof PlainsGrassPopulator)) {
            if (!this.checkForgeEvent(populator, this, chunkX, chunkZ, flags, chunk)) {
                continue;
            }
        } else {
            final PlainsGrassPopulator grassPop = (PlainsGrassPopulator) populator;
            if (!this.checkForgeEvent(grassPop.getFlowers(), this, chunkX, chunkZ, flags, chunk)) {
                grassPop.setPopulateFlowers(false);
            }
            if (!this.checkForgeEvent(grassPop.getGrass(), this, chunkX, chunkZ, flags, chunk)) {
                grassPop.setPopulateGrass(false);
            }
            if (!this.checkForgeEvent(grassPop.getPlant(), this, chunkX, chunkZ, flags, chunk)) {
                grassPop.setPopulateGrass(false);
            }
            if (!grassPop.isPopulateFlowers() && !grassPop.isPopulateGrass()) {
                continue;
            }
        }
        final PopulatorType type = populator.getType();
        if (Sponge.getGame().getEventManager().post(SpongeEventFactory.createPopulateChunkEventPopulate(Sponge.getCauseStackManager().getCurrentCause(), populator, chunk))) {
            continue;
        }
        try (PopulatorPhaseContext context = GenerationPhase.State.POPULATOR_RUNNING.createPhaseContext().world(this.world).populator(type).buildAndSwitch()) {
            Timing timing = null;
            if (Timings.isTimingsEnabled()) {
                timing = this.populatorTimings.get(populator.getType().getId());
                if (timing == null) {
                    timing = SpongeTimingsFactory.ofSafe(populator.getType().getId());
                    this.populatorTimings.put(populator.getType().getId(), timing);
                }
                timing.startTimingIfSync();
            }
            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();
            }
        }
    }
    MinecraftForge.ORE_GEN_BUS.post(new OreGenEvent.Post(this.world, this.rand, blockpos));
    MinecraftForge.EVENT_BUS.post(new DecorateBiomeEvent.Post(this.world, this.rand, blockpos));
    MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Post(this, this.world, this.rand, chunkX, chunkZ, false));
    // populate method so that its particular changes are used.
    if (this.baseGenerator instanceof SpongeGenerationPopulator) {
        Timing timing = null;
        IChunkGenerator chunkGenerator = ((SpongeGenerationPopulator) this.baseGenerator).getHandle(this.world);
        if (Timings.isTimingsEnabled()) {
            IGenerationPopulator spongePopulator = (IGenerationPopulator) this.baseGenerator;
            timing = spongePopulator.getTimingsHandler();
            timing.startTimingIfSync();
        }
        chunkGenerator.populate(chunkX, chunkZ);
        if (Timings.isTimingsEnabled()) {
            timing.stopTimingIfSync();
        }
    }
    org.spongepowered.api.event.world.chunk.PopulateChunkEvent.Post event = SpongeEventFactory.createPopulateChunkEventPost(Sponge.getCauseStackManager().getCurrentCause(), ImmutableList.copyOf(populators), chunk);
    SpongeImpl.postEvent(event);
    BlockFalling.fallInstantly = false;
    this.chunkGeneratorTiming.stopTimingIfSync();
    ((IMixinWorldServer) spongeWorld).getTimingsHandler().chunkPopulate.stopTimingIfSync();
}
Also used : PlainsGrassPopulator(org.spongepowered.common.world.gen.populators.PlainsGrassPopulator) IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) OreGenEvent(net.minecraftforge.event.terraingen.OreGenEvent) 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) BlockPos(net.minecraft.util.math.BlockPos) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) GenerationPopulator(org.spongepowered.api.world.gen.GenerationPopulator) PlainsGrassPopulator(org.spongepowered.common.world.gen.populators.PlainsGrassPopulator) SpongeGenerationPopulator(org.spongepowered.common.world.gen.SpongeGenerationPopulator) Populator(org.spongepowered.api.world.gen.Populator) AnimalPopulator(org.spongepowered.common.world.gen.populators.AnimalPopulator) IFlaggedPopulator(org.spongepowered.common.interfaces.world.gen.IFlaggedPopulator) SnowPopulator(org.spongepowered.common.world.gen.populators.SnowPopulator) IGenerationPopulator(org.spongepowered.common.interfaces.world.gen.IGenerationPopulator) DecorateBiomeEvent(net.minecraftforge.event.terraingen.DecorateBiomeEvent) ImmutableBiomeVolume(org.spongepowered.api.world.extent.ImmutableBiomeVolume) PopulatorPhaseContext(org.spongepowered.common.event.tracking.phase.generation.PopulatorPhaseContext) IFlaggedPopulator(org.spongepowered.common.interfaces.world.gen.IFlaggedPopulator) SpongeGenerationPopulator(org.spongepowered.common.world.gen.SpongeGenerationPopulator) PopulateChunkEvent(net.minecraftforge.event.terraingen.PopulateChunkEvent) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) Chunk(org.spongepowered.api.world.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)

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