Search in sources :

Example 1 with MobCategory

use of net.minecraft.world.entity.MobCategory 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)

Example 2 with MobCategory

use of net.minecraft.world.entity.MobCategory in project SpongeCommon by SpongePowered.

the class NaturalSpawnerMixin method spawnForChunk.

// @formatter:on
/**
 * @author morph - January 3rd, 2021 - Minecraft 1.16.4
 * @reason Use world configured spawn limits
 */
@Overwrite
public static void spawnForChunk(ServerLevel world, LevelChunk chunk, NaturalSpawner.SpawnState manager, boolean spawnFriendlies, boolean spawnEnemies, boolean doMobSpawning) {
    world.getProfiler().push("spawner");
    for (final MobCategory entityclassification : SPAWNING_CATEGORIES) {
        if ((spawnFriendlies || !entityclassification.isFriendly()) && (spawnEnemies || entityclassification.isFriendly()) && (doMobSpawning || !entityclassification.isPersistent()) && NaturalSpawnerMixin.impl$canSpawnInLevel(manager, entityclassification, world)) {
            // spawnCategoryForChunk(var0, param0, param1, (param1x, param2x, param3x) -> param2.canSpawn(param1x, param2x,
            // param3x), (param1x, param2x) -> param2.afterSpawn(param1x, param2x));
            NaturalSpawnerMixin.spawnCategoryForChunk(entityclassification, world, chunk, (p_234969_1_, p_234969_2_, p_234969_3_) -> ((NaturalSpawner_SpawnStateAccessor) manager).invoker$canSpawn(p_234969_1_, p_234969_2_, p_234969_3_), (p_234970_1_, p_234970_2_) -> ((NaturalSpawner_SpawnStateAccessor) manager).invoker$afterSpawn(p_234970_1_, p_234970_2_));
        }
    }
    world.getProfiler().pop();
}
Also used : MobCategory(net.minecraft.world.entity.MobCategory) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

MobCategory (net.minecraft.world.entity.MobCategory)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 WeightedRandomList (net.minecraft.util.random.WeightedRandomList)1 MobSpawnSettings (net.minecraft.world.level.biome.MobSpawnSettings)1 StructureSpawnListGatherEvent (net.minecraftforge.event.world.StructureSpawnListGatherEvent)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1