package ovh.glitchlabs.masterwild.worldgen; import net.minecraft.core.HolderSet; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BiomeTags; import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.MobSpawnSettings; import net.neoforged.neoforge.common.world.BiomeModifier; import net.neoforged.neoforge.common.world.BiomeModifiers; import net.neoforged.neoforge.registries.NeoForgeRegistries; import ovh.glitchlabs.masterwild.Masterwild; import ovh.glitchlabs.masterwild.entity.ModEntities; import java.util.List; public class ModBiomeModifiers { public static final ResourceKey SPAWN_RACCOON = registerKey("spawn_raccoon"); public static final ResourceKey SPAWN_PINGUIN = registerKey("spawn_pinguin"); public static final ResourceKey SPAWN_FIREFLY = registerKey("spawn_firefly"); public static final ResourceKey SPAWN_ROOSTER = registerKey("spawn_rooster"); public static final ResourceKey SPAWN_SHARK = registerKey("spawn_shark"); public static final ResourceKey SPAWN_HEDGEHOG = registerKey("spawn_hedgehog"); public static final ResourceKey SPAWN_RED_PANDA = registerKey("spawn_red_panda"); public static final ResourceKey SPAWN_BUTTERFLY = registerKey("spawn_butterfly"); public static final ResourceKey SPAWN_MONKEY = registerKey("spawn_monkey"); public static void bootstrap(BootstrapContext context) { var placedFeatures = context.lookup(Registries.PLACED_FEATURE); var biomes = context.lookup(Registries.BIOME); addSpawn(context, SPAWN_RACCOON, HolderSet.direct( biomes.getOrThrow(Biomes.PLAINS), biomes.getOrThrow(Biomes.FOREST), biomes.getOrThrow(Biomes.BIRCH_FOREST)), ModEntities.RACCOON.get(), 10, 1, 3); addSpawn(context, SPAWN_PINGUIN, HolderSet.direct( biomes.getOrThrow(Biomes.SNOWY_PLAINS), biomes.getOrThrow(Biomes.SNOWY_BEACH), biomes.getOrThrow(Biomes.SNOWY_TAIGA), biomes.getOrThrow(Biomes.FROZEN_RIVER), biomes.getOrThrow(Biomes.ICE_SPIKES)), ModEntities.PINGUIN.get(), 15, 4, 6); addSpawn(context, SPAWN_FIREFLY, HolderSet.direct( biomes.getOrThrow(Biomes.SWAMP), biomes.getOrThrow(Biomes.MANGROVE_SWAMP), biomes.getOrThrow(Biomes.DARK_FOREST), biomes.getOrThrow(Biomes.FLOWER_FOREST), biomes.getOrThrow(Biomes.FOREST)), ModEntities.FIREFLY.get(), 50, 10, 25); addSpawn(context, SPAWN_ROOSTER, HolderSet.direct( biomes.getOrThrow(Biomes.PLAINS), biomes.getOrThrow(Biomes.SUNFLOWER_PLAINS), biomes.getOrThrow(Biomes.MEADOW)), ModEntities.ROOSTER.get(), 5, 2, 3); addSpawn(context, SPAWN_SHARK, biomes.getOrThrow(BiomeTags.IS_OCEAN), ModEntities.SHARK.get(), 3, 1, 2); addSpawn(context, SPAWN_HEDGEHOG, biomes.getOrThrow(BiomeTags.IS_FOREST), ModEntities.HEDGEHOG.get(), 10, 1, 3); addSpawn(context, SPAWN_RED_PANDA, HolderSet.direct( biomes.getOrThrow(Biomes.BAMBOO_JUNGLE), biomes.getOrThrow(Biomes.JUNGLE), biomes.getOrThrow(Biomes.CHERRY_GROVE)), ModEntities.RED_PANDA.get(), 8, 1, 3); addSpawn(context, SPAWN_MONKEY, HolderSet.direct( biomes.getOrThrow(Biomes.JUNGLE)), ModEntities.MONKEY.get(), 9, 2, 5); addSpawn(context, SPAWN_BUTTERFLY, HolderSet.direct( biomes.getOrThrow(Biomes.FLOWER_FOREST), biomes.getOrThrow(Biomes.MEADOW), biomes.getOrThrow(Biomes.SUNFLOWER_PLAINS), biomes.getOrThrow(Biomes.PLAINS), biomes.getOrThrow(Biomes.CHERRY_GROVE)), ModEntities.BUTTERFLY.get(), 10, 3, 6); } private static void addSpawn(BootstrapContext context, ResourceKey key, HolderSet biomes, EntityType type, int weight, int minCount, int maxCount) { context.register(key, new BiomeModifiers.AddSpawnsBiomeModifier(biomes, List.of(new MobSpawnSettings.SpawnerData(type, weight, minCount, maxCount)))); } private static ResourceKey registerKey(String name) { return ResourceKey.create(NeoForgeRegistries.Keys.BIOME_MODIFIERS, ResourceLocation.fromNamespaceAndPath(Masterwild.MODID, name)); } }