Skip to content

How to make a mob spawn in the world (Minecraft mod)

Natural spawning is per biome: each biome has a list of spawners with a mob type, a weight and a group size, sorted by category (monster, creature…). Fabric API adds to that list with BiomeModifications.addSpawn. Forge (1.17.1 and newer) and NeoForge do it with a data file, a biome modifier of type forge:add_spawns or neoforge:add_spawns. On 1.16.5 and 1.12.2 it is done in code. Your own mob also needs a spawn placement (where it may stand) registered, or it may never appear.

Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.

  1. Choose the mob id, weight and group size.
  2. On Fabric, call BiomeModifications.addSpawn at startup.
  3. On Forge and NeoForge, add the biome modifier JSON under data/<modid>/forge/biome_modifier or data/<modid>/neoforge/biome_modifier.
  4. Make a new world, or go to new chunks, to see it.

The example uses these values. Change them in the code.

Setting In the example What it does
mob minecraft:zombie The id of the mob.
category MONSTER Its spawn category (Fabric).
weight 10 How often, compared to others (a pig is 10).
group 4 The biggest group.

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Uses:

  • BiomeModifications.addSpawn
  • BiomeSelectors.foundInOverworld
  • MobCategory

src/main/java/com/example/examplemod/event/MoreMobsSpawns.java

package com.example.examplemod.event;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
// minecraft:zombie spawns in every overworld biome, weight 10, in groups of 1 to 4 (Fabric API: BiomeModifications.addSpawn).
public final class MoreMobsSpawns {
private MoreMobsSpawns() {
}
// Called from the mod's onInitialize.
public static void register() {
EntityType<?> type = BuiltInRegistries.ENTITY_TYPE.get(new ResourceLocation("minecraft:zombie"));
BiomeModifications.addSpawn(BiomeSelectors.foundInOverworld(), MobCategory.MONSTER, type, 10, 1, 4);
}
}

In your main mod class, inside onInitialize:

MoreMobsSpawns.register();

Uses:

  • BiomeModifications.addSpawn
  • BiomeSelectors.foundInOverworld
  • MobCategory

src/main/java/com/example/examplemod/event/MoreMobsSpawns.java

package com.example.examplemod.event;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
// minecraft:zombie spawns in every overworld biome, weight 10, in groups of 1 to 4 (Fabric API: BiomeModifications.addSpawn).
public final class MoreMobsSpawns {
private MoreMobsSpawns() {
}
// Called from the mod's onInitialize.
public static void register() {
EntityType<?> type = BuiltInRegistries.ENTITY_TYPE.get(ResourceLocation.parse("minecraft:zombie"));
BiomeModifications.addSpawn(BiomeSelectors.foundInOverworld(), MobCategory.MONSTER, type, 10, 1, 4);
}
}

In your main mod class, inside onInitialize:

MoreMobsSpawns.register();

NeoForge 1.20.1 to 1.21.1, NeoForge 1.21.2 to 26.3

Section titled “NeoForge 1.20.1 to 1.21.1, NeoForge 1.21.2 to 26.3”

Uses:

  • neoforge:add_spawns

The biome modifier is data: NeoForge reads it from the data folder, so no Java is needed.

src/main/resources/data/examplemod/neoforge/biome_modifier/more_mobs.json

{
"type": "neoforge:add_spawns",
"biomes": "#minecraft:is_overworld",
"spawners": {
"type": "minecraft:zombie",
"weight": 10,
"minCount": 1,
"maxCount": 4
}
}

Uses:

  • BiomeModifications.addSpawn
  • BiomeSelectors.foundInOverworld
  • MobCategory

src/main/java/com/example/examplemod/event/MoreMobsSpawns.java

package com.example.examplemod.event;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
// minecraft:zombie spawns in every overworld biome, weight 10, in groups of 1 to 4 (Fabric API: BiomeModifications.addSpawn).
public final class MoreMobsSpawns {
private MoreMobsSpawns() {
}
// Called from the mod's onInitialize.
public static void register() {
EntityType<?> type = BuiltInRegistries.ENTITY_TYPE.getValue(ResourceLocation.parse("minecraft:zombie"));
BiomeModifications.addSpawn(BiomeSelectors.foundInOverworld(), MobCategory.MONSTER, type, 10, 1, 4);
}
}

In your main mod class, inside onInitialize:

MoreMobsSpawns.register();

Uses:

  • BiomeModifications.addSpawn
  • BiomeSelectors.foundInOverworld
  • MobCategory

src/main/java/com/example/examplemod/event/MoreMobsSpawns.java

package com.example.examplemod.event;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
// minecraft:zombie spawns in every overworld biome, weight 10, in groups of 1 to 4 (Fabric API: BiomeModifications.addSpawn).
public final class MoreMobsSpawns {
private MoreMobsSpawns() {
}
// Called from the mod's onInitialize.
public static void register() {
EntityType<?> type = BuiltInRegistries.ENTITY_TYPE.getValue(Identifier.parse("minecraft:zombie"));
BiomeModifications.addSpawn(BiomeSelectors.foundInOverworld(), MobCategory.MONSTER, type, 10, 1, 4);
}
}

In your main mod class, inside onInitialize:

MoreMobsSpawns.register();

Uses:

  • neoforge:add_spawns

The biome modifier is data: NeoForge reads it from the data folder, so no Java is needed.

src/main/resources/data/examplemod/forge/biome_modifier/more_mobs.json

{
"type": "forge:add_spawns",
"biomes": "#minecraft:is_overworld",
"spawners": {
"type": "minecraft:zombie",
"weight": 10,
"minCount": 1,
"maxCount": 4
}
}

Uses:

  • BiomeModifications.addSpawn
  • BiomeSelectors.foundInOverworld
  • MobCategory

src/main/java/com/example/examplemod/event/MoreMobsSpawns.java

package com.example.examplemod.event;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
// minecraft:zombie spawns in every overworld biome, weight 10, in groups of 1 to 4 (Fabric API: BiomeModifications.addSpawn).
public final class MoreMobsSpawns {
private MoreMobsSpawns() {
}
// Called from the mod's onInitialize.
public static void register() {
EntityType<?> type = Registry.ENTITY_TYPE.get(new ResourceLocation("minecraft:zombie"));
BiomeModifications.addSpawn(BiomeSelectors.foundInOverworld(), MobCategory.MONSTER, type, 10, 1, 4);
}
}

In your main mod class, inside onInitialize:

MoreMobsSpawns.register();

Uses:

  • BiomeLoadingEvent.getSpawns
  • MobSpawnInfo.Spawners
  • MobSpawnInfo.Builder.addSpawn

The spawn is added in code with BiomeLoadingEvent: biome modifier files do not exist in 1.16.5.

src/main/java/com/example/examplemod/worldgen/MoreMobsSpawns.java

package com.example.examplemod.worldgen;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.MobSpawnInfo;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.registries.ForgeRegistries;
// Adds minecraft:zombie to the spawn list of every overworld biome as it loads (Forge 1.16.5: BiomeLoadingEvent; biome modifier files are 1.19+).
public final class MoreMobsSpawns {
private MoreMobsSpawns() {
}
// Called from the mod's constructor.
public static void register() {
MinecraftForge.EVENT_BUS.addListener(MoreMobsSpawns::onBiomeLoading);
}
private static void onBiomeLoading(BiomeLoadingEvent event) {
if (event.getCategory() == Biome.Category.NETHER || event.getCategory() == Biome.Category.THEEND) {
return;
}
EntityType<?> type = ForgeRegistries.ENTITIES.getValue(new ResourceLocation("minecraft:zombie"));
event.getSpawns().addSpawn(EntityClassification.MONSTER, new MobSpawnInfo.Spawners(type, 10, 1, 4));
}
}

In your main mod class, inside <init>:

MoreMobsSpawns.register();

Uses:

  • BiomeLoadingEvent.getSpawns
  • MobSpawnInfo.Spawners
  • MobSpawnInfo.Builder.addSpawn

In 1.12.2 the spawn is added in code with EntityRegistry.addSpawn(type, weight, min, max, category, biomes); biome modifier files came with 1.19.

src/main/java/com/example/examplemod/worldgen/MoreMobsSpawns.java

package com.example.examplemod.worldgen;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
// Adds minecraft:zombie to the spawn list of every biome (Forge 1.12.2: EntityRegistry.addSpawn; biome modifier files are 1.19+).
public final class MoreMobsSpawns {
private MoreMobsSpawns() {
}
// Called from preInit.
@SuppressWarnings("unchecked")
public static void register() {
Class<? extends EntityLiving> type = (Class<? extends EntityLiving>) EntityList.getClass(new ResourceLocation("minecraft:zombie"));
Biome[] biomes = ForgeRegistries.BIOMES.getValuesCollection().toArray(new Biome[0]);
EntityRegistry.addSpawn(type, 10, 1, 4, EnumCreatureType.MONSTER, biomes);
}
}

In your main mod class, inside preInit:

MoreMobsSpawns.register();

Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.