This article aims to roughly describe the Minecraft spawning algorithm as it exists in Java Edition 1.19.
Spawning consists of three phases, which run every tick:
- Collect mob cap data
- Run spawning attempts, depending on mob caps
- Despawn entities
Mob Categories §
The spawning algorithm categorizes all mobs into one of several categories, which are listed here.
|Axolotls||Take a guess...|
|Underground water creatures||Glow squid only|
|Water creatures||Dolphins and squid|
|Miscellaneous||Boats, minecarts, etc.|
Mobs in the miscellaneous category are not involved in natural mob spawning.
Mob Cap §
Spawning for each mob category can only occur if the number of mobs in loaded chunks belonging to that category is lower than a value called the mob cap.
The mob cap for each category is calculated from a base value and scales linearly with the number of loaded chunks. Here is the exact formula:
|Mob Category||Base mob cap|
|Underground water creatures||5|
A chunk is considered spawnable if it is within 8 chunks of a player. In other words, ever player has 17x17 grid of spawnable chunks centered on them.
This is where the 289 found in the mob cap equation comes from; in singleplayer, there will always be 289 spawnable chunks since there is only one player in the game, so the mob cap will be equal to the base value for every category.
On a server, if all the players are spread out so that none of their 17x17 chunk regions overlap, the global mobcap for each category will be equal to the singleplayer mobcap multiplied by the number of players. If there is overlap, the global mobcap will be less.
If the number of mobs in a category exceeds the global mobcap, spawning for that category is entirely skipped. The mob cap is only checked at the start of the spawning cycle, so by the end of the tick, the number of mobs may exceed the mob cap.
The game also checks the local mob cap on a chunk-by-chunk basis. Each player has a local mob cap, which simply counts the number of mobs in each category within the spawnable chunks surrounding that player. For a given category and chunk, if there is at least one player within range whose local mob cap isn't filled, spawning can proceed.
Practical Example §
Suppose the game is currently evaluating monster spawning for the chunk highlighted in red.
There are 434 loaded chunks, so the global monster mob cap is . If the total number of monsters in the world is greater than 105, no monster spawning will happen in any chunks.
If the global mob cap is not met, the game proceeds to check each player's local mob cap. First, it retrieves the number of monsters within player 1's spawnable chunks, highlighted in blue here:
If there are fewer than 70 monsters in the blue chunks, monsters can spawn in the red chunk. Otherwise, the game moves on to player 2's local mob cap.
The local mob cap helps ensure that spawns are equally distributed between players. Before 1.18, if multiple players were online and occupying different parts of the world, odds are the vast majority of spawning spaces would be outside of a mob farm, which would severely impact the number of spawns in the farm. Now, players in non-spawnproofed areas have minimal effect on mob spawning beyond their spawnable chunks because their local mob cap will prevent them from taking up more of the global mob cap.
Mob Cap Quirks §
Generally speaking, monsters that have special attributes preventing them from despawning do not contribute to the mobcap, so the following groups aren't counted:
- Mobs with the
PersistenceRequiredtag set to true, including:
- Zombie piglins created when pigs are struck by lightning
- Witches created when villagers are struck by lightning
- All elder guardians
- Duplicated allays
- Skeletons created from skeleton traps
- Zombies holding items
- Most mobs spawned as part of a structure, e.g. the black cat in a witch hut
- Mobs that are riding another entity (such as a boat or a minecart)
- Fish and axolotls from buckets
- Endermen carrying blocks
- Raiders that are part of raids
There is a narrow class of mobs that contribute to the monster mob cap but do not despawn, meaning that if enough of these mobs are accumulated to fill the mob cap hostile mob spawning will be disabled for the entire world. Such a device is called a mobswitch. Examples include:
- Zombie villagers which are converting or have been traded with before
Every tick, the game looks through all spawning chunks and checks which categories of mobs may spawn there. Then, for each category, it selects a random position within the chunk which will be used for mob spawning. It begins by selecting a random X and Z value; next, it looks up the height of the highest non-air block at that X/Z combo, and picks a random Y-value between the minimum build height and the Y-coordinate of air block above the highest block.
Once a location is picked, the game checks if the block at that location is a redstone conductor (i.e. all full solid blocks, as well as soul sand and mud). If so, the spawn attempt immediately ends. Otherwise, it will make up to three attempts to spawn a pack of mobs near that location.
The heightmap is a critical factor in the performance of a farm. Spawning attempts are evenly distributed along the Y-axis, so you want to minimize the chance that a spawn attempt occurs above or below your farm. Thus, there are two things you should keep in mind:
- Always try to build mob farms as low as possible.
- Avoid placing solid blocks above mob farms.
Unfortunately, if you build your farm very low in the world to maximize its rates, you will need to eliminate all spawnable spaces within 128 blocks of its proximity to prevent those spawns from filling up the mob cap. This means either lighting up all the caves within that radius or excavating a perimeter. An alternative is to build a surface-level farm and position your AFK spot at a high Y-level to ensure that all spawnable spaces are restricted to the farm. Of course, spawn rates will be diminished.
Another thing to keep in mind is that the game doesn't try to spawn a mob directly at the selected location; instead, it picks random positions in a square surrounding the initial position using the rules outlined in the following section. This means that spawn attempts which begin outside of your farm may still contribute to its rates. This yields two more pieces of advice:
- Build an overhang directly above the highest spawning platform in your mob farm to raise the heightmap in the columns surrounding the farm, so that spawn attempts which occur there may produce spawns within the farm.
- Never place solid blocks at foot level around the farm, since they will instantly cause a spawn attempt to end.
Pack Spawning Mechanics §
Minecraft spawns all mobs in packs, meaning that one spawn attempt generally results in multiple mobs being spawned. Keep in mind that the algorithm can be rather idiosyncratic and knowing all the details is not too important when it comes to farm optimization.
The idea behind pack spawning is that the game starts from the initial position, adds a random X and Z offset, and tries to spawn a mob. This process is repeated for every mob in the pack. The offsets are picked according to a triangular distribution, so smaller offsets occur more frequently.
When the position is offset for the first time, the game checks the biome at that position, and retrieves the list of mobs in the current category that can spawn in that biome. That list looks something like this:
The mob spawning weights and pack sizes are documented here.
The odds of a mob type being selected is equal to its weight divided by the total weight of all the mob types in that category. In this case, the probability that a zombie is picked to be spawned is .
Spawn Conditions §
Over time, the rules that decide whether a mob should be allowed to spawn have grown quite Byzantine. I will attempt to give a mostly complete description of them here.
For starters, all attempts to spawn a mob as part of a pack fail if they are within 24 blocks of the player or the world spawn point. The position must also be within a loaded chunk and within the world border. However, the chunk does not have to be entity ticking, so it's possible for mobs to spawn in lazy chunks that never despawn. These mobs still contribute to the mobcap, so it may lead to situations where the mob cap gets quickly taken up. This phenomenon was once classified as a bug, but for unknown reasons this behavior was reintroduced in 1.17. Generally speaking, this is only a problem if you play on a very low simulation distance.
Once a mob type is picked, the game checks whether the selected position is valid for the mob according to the following rules:
- The distance between the position and the nearest player cannot be greater than the mob's despawn distance.
- Creatures are not affected by this.
- If the mob's spawn placement type is
- The upper face of the block below the position must be full and cannot emit a light level greater than 13.
- Bedrock, berries, glass, tinted glass, and trapdoors are not spawnable.
- Soul sand and mud are spawnable despite their upper face not being full.
- Mangrove leaves and regular leaves are only spawnable for ocelots and parrots.
- Ice is only spawnable for polar bears.
- Magma blocks are only spawnable for fire immune mobs.
- The block at the position and above the position must be valid for mob spawns:
- The block cannot be full.
- The block cannot be redstone conductive.
- The block cannot have liquid.
- The block cannot be a rail.
- The block cannot harm the mob being spawned:
- Non-fire immune mobs cannot spawn in fire
- Only wither skeletons can spawn in wither roses
- Only polar bears, snow golems, and strays can spawn in powder snow
- If the mob's spawn placement type is
- The block at the position must be water, and the block above it may not be a redstone conductor (full blocks, soul sand, mud).
- If the mob's spawn placement type is
- The block at the position must be lava.
- The mob must not collide with a block or another entity at the position.
||Axolotl, Cod, Dolphin, Drowned, Guardian, Pufferfish, Salmon, Squid, Tropical Fish, Glow Squid|
||Bat, Blaze, Cave Spider, Chicken, Cow, Creeper, Donkey, Enderman, Frog, Ghast, Goat, Horse, Husk, Iron Golem, Llama, Magma Cube, Mooshroom, Ocelot, Parrot, Pig, Hoglin, Piglin, Polar Bear, Rabbit, Sheep, Skeleton, Slime, Spider, Stray, Turtle, Witch, Wither Skeleton, Wolf, Zombie, Zombified Piglin, Zombie Villager|
There are also further mob-specific rules that need to be satisfied for the spawning attempt to continue.
The block underneath the position must be clay.
Cod, Dolphin, Pufferfish, Salmon, Squid, Tropical Fish §
The position's Y-level may be between 50 and 63, inclusive. The block below the position and the block above the position must be water. The block above may not be waterlogged or a bubble column. In Lush Caves, tropical fish may spawn at any Y-level.
The block at and below the position must be water. Drowned are subject to the same light level restrictions as other monsters. In rivers, there is a chance of the spawn attempt succeeding. In all other biomes, the chance is , and the position must also be over 5 blocks below the sea level.
The block at the position and below the position must contain water. If the position is exposed to the sky, there is a 95% chance of the spawn attempt failing.
The Y-level must be below 64. The light level must be below 4, except around Halloween (Oct 20 - Nov 3), when the light level must be below 7. The chance of a spawn attempt failing increases linearly.
This includes cave spiders, creepers, endermen, skeletons, spiders, witches, wither skeletons, zombies, and zombie villagers.
Each additional sky light level adds a chance of failure. In the Overworld and End, the block light level must be zero. (TODO: Figure out the Nether stuff)
This includes chickens, cows,donkeys, horses, llamas, mules, pigs, and sheep.
The block below the position must be a grass block and the light level must be above 8.
The block below the position must be a grass block, mud, mangrove roots, or muddy mangrove roots, and the light level must be above 8.
The spawn attempt has a 95% chance of failing.
Glow Squid §
The Y-level of the position must be less than or equal to 30, the light level must be zero, and the block at the position must be water.
The block below the position must be stone, snow, a snow block, packed ice, or gravel, and the light level must be above 8.
Regular monster spawn rules apply. The sky light at the position must also be 15.
The block below the position must be mycelium, and the light level must be above 8.
The spawn attempt has a chance of failing.
The block below the position must be grass, air, or a block with the
#logs tag, and the light level must be above 8.
Hoglin, Piglin §
The block below the position must not be nether wart.
Polar Bear §
The light level must be above 8. Also, if in a frozen ocean or deep frozen ocean biome, the block below the position must be ice; otherwise, the block below the position must be grass.
The block below the position must be grass, snow, or sand, and the light level must be above 8.
If in a swamp or mangrove swamp biome, a slime may spawn between Y-levels 50 and 70 (exclusive). The chance of the spawn attempt succeeding depends on the moon brightness, peaking at 50%. The light level must be 8 or below; higher light levels increase the chance of the attempt failing.
Slimes also spawn in slime chunks in all biomes, where the Y-level must be below 40. The attempt has a 90% chance of failure.
The position must be able to see the sky, excluding any powdered snow blocks that might be in the way. Monster lighting conditions must also be met.
If the position is occupied by lava, the game will continually move up until it finds an air block. If an air block is not found, the spawn attempt fails.
The Y-level must be no more than 4 blocks above sea level, the block below the position must be sand, and the light level must be above 8.
The block below the position must be grass, snow, or a snow block, and the light level must be above 8.
The block below the position must be grass, snow, a snow block, podzol, or coarse dirt, and the light level must be above 8.
Golems, animals, allays, wandering traders, and villagers never despawn, with exceptions:
- Untamed cats that are older than 2,400 ticks can despawn.
- Chickens that spawned as part of a chicken jockey can despawn.
Shulkers are considered golems for some reason, so they don't despawn.
In addition, certain mobs with special characteristics do not despawn:
- Endermen carrying blocks
- Axolotl and fish from buckets
- Raiders that are participating in a raid
- Mobs with the
PersistenceRequiredNBT tag set to true
- Mobs riding another entity
- Zombie villagers that are in the process of converting or have been traded with
For mobs that can despawn, the following process is used:
- Calculate the distance to the nearest player
- If the distance is greater than 128 blocks (or 64 blocks for water ambient mobs), despawn immediately.
- If the distance is greater than 32 blocks and over 600 ticks have elapsed, the mob has a 1/800 chance of despawning each tick
Endermites will disappear after 2,400 ticks unless the
PersistenceRequired tag is set, but this mechanic is implemented separately from regular despawning.
Spawning Potentials §
In addition to the mob cap, spawning is limited in soul sand valley and warped forest biomes through a new mechanic called spawn potentials. Here's how it works.
Essentially, every mob emits a potential field that diminishes with distance. The strength of this potential at a given position is calculated according to the following equation:
The charge value depends on the mob type and biome.
When spawning one of the mobs listed in the tables below, the potential contribution from all other mobs in potential-calculating biomes is added up and compared to a total energy value. The potential must be less than the total energy for the spawn attempt to continue.
Soul Sand Valley
|Mob Type||Total Energy||Charge|
|Mob Type||Total Energy||Charge|
If a mob does not contribute to the mob cap, it also does not contribute to spawn potentials. The conditions for this are documented here.
Other Resources §
If you want to keep learning about mob spawning, LogicalGeekBoy's video on mob spawning (featuring MethodZz) is a good place to start.
Gnembon also has an excellent video on the newly introduced spawn potential system.