Search in sources :

Example 1 with BiomeLoadingEvent

use of net.minecraftforge.event.world.BiomeLoadingEvent in project SinoCore by SinoCraftProject.

the class PlacedFeatureRegister method onGenerator.

@SubscribeEvent(priority = EventPriority.HIGH)
public void onGenerator(BiomeLoadingEvent event) {
    BiomeGenerationSettingsBuilder generation = event.getGeneration();
    ResourceLocation name = event.getName();
    Biome.BiomeCategory category = event.getCategory();
    Biome.ClimateSettings climate = event.getClimate();
    BiomeSpecialEffects effects = event.getEffects();
    features.stream().filter(e -> e.test(name, category, climate, effects)).forEach(e -> generation.addFeature(e.decoration.ordinal(), e));
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) BiomeLoadingEvent(net.minecraftforge.event.world.BiomeLoadingEvent) Predicate(java.util.function.Predicate) Collection(java.util.Collection) GenerationStep(net.minecraft.world.level.levelgen.GenerationStep) ArrayUtils(org.apache.commons.lang3.ArrayUtils) TreeConfiguration(net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration) Biome(net.minecraft.world.level.biome.Biome) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Objects(java.util.Objects) MinecraftForge(net.minecraftforge.common.MinecraftForge) List(java.util.List) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature) EventPriority(net.minecraftforge.eventbus.api.EventPriority) BiomeGenerationSettingsBuilder(net.minecraftforge.common.world.BiomeGenerationSettingsBuilder) Suppliers(games.moegirl.sinocraft.sinocore.api.util.Suppliers) BiomeSpecialEffects(net.minecraft.world.level.biome.BiomeSpecialEffects) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OreConfiguration(net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration) FeatureConfiguration(net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration) Biome(net.minecraft.world.level.biome.Biome) ResourceLocation(net.minecraft.resources.ResourceLocation) BiomeSpecialEffects(net.minecraft.world.level.biome.BiomeSpecialEffects) BiomeGenerationSettingsBuilder(net.minecraftforge.common.world.BiomeGenerationSettingsBuilder) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with BiomeLoadingEvent

use of net.minecraftforge.event.world.BiomeLoadingEvent in project Mekanism by mekanism.

the class SpawnHelper method onBiomeLoad.

public static void onBiomeLoad(BiomeLoadingEvent event) {
    // Add spawns to any biomes that have mob spawns for the "parent" types of our mobs
    MobSpawnInfoBuilder spawns = event.getSpawns();
    List<MobSpawnInfo.Spawners> monsterSpawns = spawns.getSpawner(EntityClassification.MONSTER);
    if (!monsterSpawns.isEmpty()) {
        // Fail quick if no monsters can spawn in this biome anyway
        ResourceLocation biomeName = event.getName();
        getSpawnConfigs().filter(spawnConfig -> spawnConfig.shouldSpawn.get() && !spawnConfig.biomeBlackList.get().contains(biomeName)).forEach(spawnConfig -> {
            EntityType<?> parent = spawnConfig.parentTypeProvider.getEntityType();
            monsterSpawns.stream().filter(monsterSpawn -> monsterSpawn.type == parent).findFirst().ifPresent(parentEntry -> {
                // If the adult mob can spawn in this biome let the baby mob spawn in it
                // Note: We adjust the mob's spawning based on the adult's spawn rates
                MobSpawnInfo.Spawners spawner = getSpawner(spawnConfig, parentEntry);
                spawns.addSpawn(EntityClassification.MONSTER, spawner);
                MobSpawnInfo.SpawnCosts parentCost = spawns.getCost(parent);
                if (parentCost == null) {
                    Mekanism.logger.debug("Adding spawn rate for '{}' in biome '{}', with weight: {}, minSize: {}, maxSize: {}", spawner.type.getRegistryName(), biomeName, spawner.weight, spawner.minCount, spawner.maxCount);
                } else {
                    double spawnCostPerEntity = parentCost.getCharge() * spawnConfig.spawnCostPerEntityPercentage.get();
                    double maxSpawnCost = parentCost.getEnergyBudget() * spawnConfig.maxSpawnCostPercentage.get();
                    spawns.addMobCharge(spawner.type, spawnCostPerEntity, maxSpawnCost);
                    Mekanism.logger.debug("Adding spawn rate for '{}' in biome '{}', with weight: {}, minSize: {}, maxSize: {}, spawnCostPerEntity: {}, maxSpawnCost: {}", spawner.type.getRegistryName(), biomeName, spawner.weight, spawner.minCount, spawner.maxCount, spawnCostPerEntity, maxSpawnCost);
                }
            });
        });
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) Mekanism(mekanism.common.Mekanism) BiomeLoadingEvent(net.minecraftforge.event.world.BiomeLoadingEvent) AdditionsEntityTypes(mekanism.additions.common.registries.AdditionsEntityTypes) ParrotEntity(net.minecraft.entity.passive.ParrotEntity) EntityTypeRegistryObject(mekanism.common.registration.impl.EntityTypeRegistryObject) MobSpawnInfo(net.minecraft.world.biome.MobSpawnInfo) EntityBabyStray(mekanism.additions.common.entity.baby.EntityBabyStray) MobSpawnInfoBuilder(net.minecraftforge.common.world.MobSpawnInfoBuilder) AdditionsCommonConfig(mekanism.additions.common.config.AdditionsCommonConfig) EntityClassification(net.minecraft.entity.EntityClassification) SoundEvents(net.minecraft.util.SoundEvents) List(java.util.List) Stream(java.util.stream.Stream) EntitySpawnPlacementRegistry(net.minecraft.entity.EntitySpawnPlacementRegistry) MekanismAdditionsConfig(mekanism.additions.common.config.MekanismAdditionsConfig) ResourceLocation(net.minecraft.util.ResourceLocation) StructureSpawnListGatherEvent(net.minecraftforge.event.world.StructureSpawnListGatherEvent) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) Heightmap(net.minecraft.world.gen.Heightmap) MobSpawnInfoBuilder(net.minecraftforge.common.world.MobSpawnInfoBuilder) ResourceLocation(net.minecraft.util.ResourceLocation) MobSpawnInfo(net.minecraft.world.biome.MobSpawnInfo)

Example 3 with BiomeLoadingEvent

use of net.minecraftforge.event.world.BiomeLoadingEvent in project Magma-1.16.x by magmafoundation.

the class ForgeHooks method enhanceBiome.

public static Biome enhanceBiome(@Nullable final ResourceLocation name, final Biome.Climate climate, final Biome.Category category, final Float depth, final Float scale, final BiomeAmbience effects, final BiomeGenerationSettings gen, final MobSpawnInfo spawns, final RecordCodecBuilder.Instance<Biome> codec, final BiomeCallbackFunction callback) {
    BiomeGenerationSettingsBuilder genBuilder = new BiomeGenerationSettingsBuilder(gen);
    MobSpawnInfoBuilder spawnBuilder = new MobSpawnInfoBuilder(spawns);
    BiomeLoadingEvent event = new BiomeLoadingEvent(name, climate, category, depth, scale, effects, genBuilder, spawnBuilder);
    MinecraftForge.EVENT_BUS.post(event);
    return callback.apply(event.getClimate(), event.getCategory(), event.getDepth(), event.getScale(), event.getEffects(), event.getGeneration().build(), event.getSpawns().build()).setRegistryName(name);
}
Also used : MobSpawnInfoBuilder(net.minecraftforge.common.world.MobSpawnInfoBuilder) BiomeLoadingEvent(net.minecraftforge.event.world.BiomeLoadingEvent) BiomeGenerationSettingsBuilder(net.minecraftforge.common.world.BiomeGenerationSettingsBuilder)

Example 4 with BiomeLoadingEvent

use of net.minecraftforge.event.world.BiomeLoadingEvent in project LoliServer by Loli-Server.

the class ForgeHooks method enhanceBiome.

public static Biome enhanceBiome(@Nullable final ResourceLocation name, final Biome.Climate climate, final Biome.Category category, final Float depth, final Float scale, final BiomeAmbience effects, final BiomeGenerationSettings gen, final MobSpawnInfo spawns, final RecordCodecBuilder.Instance<Biome> codec, final BiomeCallbackFunction callback) {
    BiomeGenerationSettingsBuilder genBuilder = new BiomeGenerationSettingsBuilder(gen);
    MobSpawnInfoBuilder spawnBuilder = new MobSpawnInfoBuilder(spawns);
    BiomeLoadingEvent event = new BiomeLoadingEvent(name, climate, category, depth, scale, effects, genBuilder, spawnBuilder);
    MinecraftForge.EVENT_BUS.post(event);
    return callback.apply(event.getClimate(), event.getCategory(), event.getDepth(), event.getScale(), event.getEffects(), event.getGeneration().build(), event.getSpawns().build()).setRegistryName(name);
}
Also used : MobSpawnInfoBuilder(net.minecraftforge.common.world.MobSpawnInfoBuilder) BiomeLoadingEvent(net.minecraftforge.event.world.BiomeLoadingEvent) BiomeGenerationSettingsBuilder(net.minecraftforge.common.world.BiomeGenerationSettingsBuilder)

Aggregations

BiomeLoadingEvent (net.minecraftforge.event.world.BiomeLoadingEvent)4 BiomeGenerationSettingsBuilder (net.minecraftforge.common.world.BiomeGenerationSettingsBuilder)3 MobSpawnInfoBuilder (net.minecraftforge.common.world.MobSpawnInfoBuilder)3 List (java.util.List)2 Suppliers (games.moegirl.sinocraft.sinocore.api.util.Suppliers)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1 Stream (java.util.stream.Stream)1 AdditionsCommonConfig (mekanism.additions.common.config.AdditionsCommonConfig)1 MekanismAdditionsConfig (mekanism.additions.common.config.MekanismAdditionsConfig)1 EntityBabyStray (mekanism.additions.common.entity.baby.EntityBabyStray)1 AdditionsEntityTypes (mekanism.additions.common.registries.AdditionsEntityTypes)1 Mekanism (mekanism.common.Mekanism)1 EntityTypeRegistryObject (mekanism.common.registration.impl.EntityTypeRegistryObject)1 EntityClassification (net.minecraft.entity.EntityClassification)1 EntitySpawnPlacementRegistry (net.minecraft.entity.EntitySpawnPlacementRegistry)1