Search in sources :

Example 1 with SnowPopulator

use of org.spongepowered.common.world.gen.populators.SnowPopulator 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 2 with SnowPopulator

use of org.spongepowered.common.world.gen.populators.SnowPopulator in project SpongeCommon by SpongePowered.

the class MixinChunkGeneratorOverworld method addPopulators.

@Override
public void addPopulators(WorldGenerator generator) {
    if (this.settings.useCaves) {
        generator.getGenerationPopulators().add((GenerationPopulator) this.caveGenerator);
    }
    if (this.settings.useRavines) {
        generator.getGenerationPopulators().add((GenerationPopulator) this.ravineGenerator);
    }
    if (this.settings.useMineShafts && this.mapFeaturesEnabled) {
        generator.getGenerationPopulators().add((GenerationPopulator) this.mineshaftGenerator);
        generator.getPopulators().add((Populator) this.mineshaftGenerator);
    }
    if (this.settings.useVillages && this.mapFeaturesEnabled) {
        generator.getGenerationPopulators().add((GenerationPopulator) this.villageGenerator);
        generator.getPopulators().add((Populator) this.villageGenerator);
    }
    if (this.settings.useStrongholds && this.mapFeaturesEnabled) {
        generator.getGenerationPopulators().add((GenerationPopulator) this.strongholdGenerator);
        generator.getPopulators().add((Populator) this.strongholdGenerator);
    }
    if (this.settings.useTemples && this.mapFeaturesEnabled) {
        generator.getGenerationPopulators().add((GenerationPopulator) this.scatteredFeatureGenerator);
        generator.getPopulators().add((Populator) this.scatteredFeatureGenerator);
    }
    if (this.settings.useMonuments && this.mapFeaturesEnabled) {
        generator.getGenerationPopulators().add((GenerationPopulator) this.oceanMonumentGenerator);
        generator.getPopulators().add((Populator) this.oceanMonumentGenerator);
    }
    if (this.settings.useMansions && this.mapFeaturesEnabled) {
        generator.getGenerationPopulators().add((GenerationPopulator) this.woodlandMansionGenerator);
        generator.getPopulators().add((Populator) this.woodlandMansionGenerator);
    }
    if (this.settings.useWaterLakes) {
        Lake lake = Lake.builder().chance(1d / this.settings.waterLakeChance).liquidType((BlockState) Blocks.WATER.getDefaultState()).height(VariableAmount.baseWithRandomAddition(0, 256)).build();
        FilteredPopulator filtered = new FilteredPopulator(lake, (c) -> {
            Biome biomegenbase = this.world.getBiome(VecHelper.toBlockPos(c.getBlockMin()).add(16, 0, 16));
            return biomegenbase != Biomes.DESERT && biomegenbase != Biomes.DESERT_HILLS;
        });
        filtered.setRequiredFlags(WorldGenConstants.VILLAGE_FLAG);
        generator.getPopulators().add(filtered);
    }
    if (this.settings.useLavaLakes) {
        Lake lake = Lake.builder().chance(1d / this.settings.lavaLakeChance).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.settings.useDungeons) {
        Dungeon dungeon = Dungeon.builder().attempts(this.settings.dungeonChance).build();
        generator.getPopulators().add(dungeon);
    }
    generator.getPopulators().add(new AnimalPopulator());
    generator.getPopulators().add(new SnowPopulator());
}
Also used : FilteredPopulator(org.spongepowered.common.world.gen.populators.FilteredPopulator) Biome(net.minecraft.world.biome.Biome) Dungeon(org.spongepowered.api.world.gen.populator.Dungeon) SnowPopulator(org.spongepowered.common.world.gen.populators.SnowPopulator) Lake(org.spongepowered.api.world.gen.populator.Lake) AnimalPopulator(org.spongepowered.common.world.gen.populators.AnimalPopulator)

Example 3 with SnowPopulator

use of org.spongepowered.common.world.gen.populators.SnowPopulator 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

SnowPopulator (org.spongepowered.common.world.gen.populators.SnowPopulator)3 Timing (co.aikar.timings.Timing)2 Vector3i (com.flowpowered.math.vector.Vector3i)2 ArrayList (java.util.ArrayList)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 BiomeGenerationSettings (org.spongepowered.api.world.biome.BiomeGenerationSettings)2 BiomeType (org.spongepowered.api.world.biome.BiomeType)2 Extent (org.spongepowered.api.world.extent.Extent)2 ImmutableBiomeVolume (org.spongepowered.api.world.extent.ImmutableBiomeVolume)2 GenerationPopulator (org.spongepowered.api.world.gen.GenerationPopulator)2 Populator (org.spongepowered.api.world.gen.Populator)2 PopulatorType (org.spongepowered.api.world.gen.PopulatorType)2 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)2 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)2 IFlaggedPopulator (org.spongepowered.common.interfaces.world.gen.IFlaggedPopulator)2 IGenerationPopulator (org.spongepowered.common.interfaces.world.gen.IGenerationPopulator)2 SoftBufferExtentViewDownsize (org.spongepowered.common.world.extent.SoftBufferExtentViewDownsize)2 AnimalPopulator (org.spongepowered.common.world.gen.populators.AnimalPopulator)2 Biome (net.minecraft.world.biome.Biome)1