Search in sources :

Example 1 with StructureSpawnListGatherEvent

use of net.minecraftforge.event.world.StructureSpawnListGatherEvent in project MinecraftForge by MinecraftForge.

the class StructureSpawnManager method gatherEntitySpawns.

private static void gatherEntitySpawns(Map<StructureFeature<?>, StructureSpawnInfo> structuresWithSpawns, StructureFeature<?> structure) {
    StructureSpawnListGatherEvent event = new StructureSpawnListGatherEvent(structure);
    MinecraftForge.EVENT_BUS.post(event);
    ImmutableMap.Builder<net.minecraft.world.entity.MobCategory, WeightedRandomList<MobSpawnSettings.SpawnerData>> builder = ImmutableMap.builder();
    event.getEntitySpawns().forEach((classification, spawns) -> {
        if (!spawns.isEmpty())
            builder.put(classification, WeightedRandomList.create(spawns));
    });
    ImmutableMap<MobCategory, WeightedRandomList<MobSpawnSettings.SpawnerData>> entitySpawns = builder.build();
    if (!entitySpawns.isEmpty())
        structuresWithSpawns.put(structure, new StructureSpawnInfo(entitySpawns, event.isInsideOnly()));
}
Also used : WeightedRandomList(net.minecraft.util.random.WeightedRandomList) MobSpawnSettings(net.minecraft.world.level.biome.MobSpawnSettings) StructureSpawnListGatherEvent(net.minecraftforge.event.world.StructureSpawnListGatherEvent) ImmutableMap(com.google.common.collect.ImmutableMap) MobCategory(net.minecraft.world.entity.MobCategory)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 WeightedRandomList (net.minecraft.util.random.WeightedRandomList)1 MobCategory (net.minecraft.world.entity.MobCategory)1 MobSpawnSettings (net.minecraft.world.level.biome.MobSpawnSettings)1 StructureSpawnListGatherEvent (net.minecraftforge.event.world.StructureSpawnListGatherEvent)1