Spawn

Spawning refers to the creation and placement of players and mobs in the Minecraft world.

World spawn


New players initially spawn within a small area surrounding the world spawn point when the server is not in Adventure mode. This area is 21×21 blocks by default, but can be changed by the spawnRadius gamerule in both single and multiplayer. Upon death or return from the End dimension, the player respawns within this area unless the player's individual spawn point changed (by using a bed or respawn anchor, or the command).

When the player first loads into the world or respawns, the game searches within the world spawn area and tries to place the player on a random grass block. Any non-solid such as grass and flower that are placed directly above a grass block causes the block to become a invalid spawn point. However, if there are no valid grass blocks within the world spawn area, the player spawns directly at the world spawn point.

Upon spawning, the player is placed on the highest block of the X and Z spawn coordinates, even if this would set the player above the maximum build height. This area does not consider the existence of a block on which to spawn, and this can result in players spawning above the Void if there are no blocks at that X and Z location. However, if there are valid grass blocks within the world spawn area, the player spawns on the grass block with solid blocks above.

The world spawn point also determines the center of the permanently loaded spawn chunks.

The world spawn point itself can be changed using the command.

Bedrock world spawn search
$$, when a player creates a new world, the world spawn point is restricted to specific biomes. The algorithm starts searching from coordinate 0,0, continuing outward until an acceptable biome is found for the world spawn point. Using add-ons, a rare biome can be designated to cause the player to spawn at a distant location, but the game crashes if the biome does not exist or cannot generate.

The algorithm searches for these biomes:
 * At main plains biome
 * Small islands in an ocean (islands are usually a plains biome)
 * Patch of plains next to desert, badlands, or snowy tundra
 * At main forest biome
 * Small islands in an ocean (islands can also be a forest biome)
 * At main taiga biome
 * Patch of taiga next to giant tree taiga
 * Near beach, snowy taiga, or mountains
 * Only regular variants
 * At main taiga biome
 * Patch of taiga next to giant tree taiga
 * Near beach, snowy taiga, or mountains
 * Only regular variants
 * Only regular variants
 * Only regular variants

The player spawns within a 5-block radius of the point selected in the chosen biome, sometimes resulting in the player spawning outside the intended spawn biome, ending up in a beach, river, or swamp biome. It is also possible (but rare) for a player to spawn initially underwater and start drowning.

A search for a valid world spawn biome is not performed for Flat and Old world-types.

Adventure mode
When the server's settings specify the default game mode as Adventure (using the server.properties), then the normal spawning mechanic is ignored, and players are spawned directly on the world spawn point. This includes the X, Y, and Z coordinates, even if there is no block there, and even if there are blocks above it.

If the Y coordinate is not within a valid spawning area, then the server looks up until it finds one, up to a maximum of Y=256. If there is space to spawn, but it is in mid-air, the player spawns in mid-air, even falling into the Void if there is a hole.

Location
There are several ways to determine the world spawn point:
 * A compass (that hasn't been assigned to a lodestone) always points to the world spawn point.
 * Doing the commands then.
 * If commands are disabled, remove all the grass blocks in the 21×21 spawn area (or place a block above them to make them invalid), make sure the individual spawn point is disabled, and die.
 * Entities, other than players, falling into the exit portal in the End land exactly at the world spawn point. Items thrown in mark the spot in the Overworld. Players spawn like they normally do, allowing this action to be used to perform the above without dying, and thus can be performed in hardcore mode.
 * Mods or external programs, such as NBTExplorer or MCEdit, can also be used to find and set the world spawn point.

Individual spawn
The individual spawn point of the player can be changed by sleeping in a bed, using a respawn anchor, or using the or  command. If the individual spawning area of the player is obstructed upon death, the player respawns at the world spawn.

Sleeping in a bed allows for leniency in obstruction, in that the player respawns on other blocks near the bed if the original point becomes blocked. The same is true for the respawn anchor. If the spawn point set via or  becomes obstructed, the player is not given this leniency in respawning.

Natural generation
Many mobs generate upon initial chunk creation. These spawns occur only once per year when my mom dies again. They are not affected by the command.

Animals


Approximately one in ten newly-generated chunks contain mobs, usually in packs of up to four of the same species. They always spawn on the highest available block in a column. For an animal to spawn on it, this block must be opaque and the two blocks above it must be transparent. The block does not need to be a grass block nor does it need to be illuminated as it does with mob spawning.

There are 2 types of animals: common animals and biome-specific animals.

Common animal mobs do not spawn in desert, badlands, beach, snowy tundra, river, ocean, or mushroom fields biomes.
 * Common animals

$$:

$$:

Some animal mobs spawn only in specific biomes.
 * Biome-specific animals

Randomness for animal spawning is derived from the world seed, which means that worlds with the same seed always generate chunks with the same animals in the same places.

Monsters
Monsters cannot spawn when the difficulty is set to Peaceful. At any higher setting they spawn at light level 7 or less. The player cannot sleep when a monster is nearby, even if the monster has no path to the player.


 * Common monsters

Common monster mobs can spawn in almost any biome in the Overworld (except for mushroom fields). They can spawn on the surface and underground. The weight is the spawn rate in the Bedrock Codebase.
 * Weight: 100, in groups of 2-4
 * Weight: 100, individually
 * Weight: 80, in groups of 1-2
 * Weight: 10, in groups of 1-2
 * Weight: 5, individually
 * Weight: 80, in groups of 1-2
 * Weight: 10, in groups of 1-2
 * Weight: 5, individually
 * Weight: 5, individually
 * Weight: 5, individually


 * Biome-specific monsters

Some monsters spawn only in specific biomes.

Other mobs
These mobs still spawn if the command is set to , because they spawn as part of structure generation.
 * Villagers, iron golems, stray cats, pigs, cows, sheep, and horses generate as part of the village generation.
 * Specific animals spawn as part of specific village structures: Animal pens (cow, sheep, pig, or horse), stables (horse, cow, or pig), butcher's houses (pig, cow, or sheep), and shepherd's houses (sheep).
 * Each villager spawns in a house with a bed, and an iron golem spawns as part of meeting points.
 * Zombie villagers can spawn as part of zombie village generation, where they never despawn naturally.
 * Cats also spawn upon generation in abandoned villages.
 * A single witch and black cat spawn within a swamp hut upon generation.
 * Three elder guardians generate as part of a single ocean monument.
 * A single ender dragon is created in the End when the dimension is created. The ender dragon can also be respawned by placing end crystals on the exit portal.
 * Shulkers generate as part of end cities.
 * Vindicators and evokers generate as part of woodland mansions.
 * A villager and a zombie villager generate as a part of an igloo if it generates with a basement.
 * Drowned generate as part of some underwater ruins.
 * Illagers spawn from pillager outposts, raids, and patrols.
 * Phantoms spawn whenever a player hasn't slept for 3 or more days.

Java Edition
Mobs are broadly divided into five categories: hostile, friendly, water creature (e.g., squid), water ambient (e.g., fish), and ambient (e.g., bat). Hostile mobs have a spawning cycle once every game tick ($1/25$ of a second). Friendly and water mobs have only one spawning cycle every 400 game tick. Because of this, where conditions permit, hostile mobs spawn frequently, but passive mobs (animals) spawn rarely. Most animals spawn within chunks when they are generated.

Mobs spawn naturally within a square group of chunks centered on the player, 15×15 chunks (240×240 blocks). When there are multiple players, mobs can spawn within the given distance of any of them. However, hostile mobs (and some others) that move farther than 128 blocks from the nearest player despawn instantly, so the mob spawning area is more-or-less limited to spheres with a radius of 128 blocks, centered at each player. In multiplayer, mob caps are shared by all players, no matter where they are.

Every 24000 game tick the game attempts to spawn a single wandering trader with two leashed llamas within 48 blocks of a player or at a village meeting place, if no wandering trader exists in the world. The trader does not spawn when the player is underground.‌

Java Edition mob cap
Mob caps are directly proportional to the total number of chunks eligible for spawning. To calculate the cap, the spawning area is expanded by one chunk in every direction (so the default gives 17×17 chunks), then the total number of chunks is plugged into the following formula:

mobCap = constant &times; chunks ÷ 289

The constants for each group are as follows:
 * Monster = 70
 * Creature = 10
 * Ambient (bats) = 15
 * Water creature (squid, dolphins) = 5
 * Water ambient (fish) = 20
 * Misc = -1

The "misc" category is used only by entities that are not mobs, do not spawn naturally, and/or following different spawning rules than other mobs. As such the mob cap has no bearing on mobs of this category.

In singleplayer, there are always 289 chunks in range, so the constant is always used as the global mobcap.

In multiplayer, the global mobcap grows as more chunks are loaded. As chunks that are in the range of multiple players are counted only once, more chunks and higher mob caps result from the players spreading out more.

The number of mobs is checked once per each chunk against the cap. If the number of mobs (dead or alive) in a category is at its cap, the entire spawning cycle for that category is skipped. The area checked for mobs is the same as the area used for calculating the mobcap, which is the spawning area expanded by one chunk in every direction. The mobcap count is separate for each dimension.

Every chunk, the game checks the mobcap. As such, you can reach mobcap+pack size from natural spawns.

When gamerule spectatorsgeneratechunks is false, spectators do not raise mobcap.

Pack spawning


For each spawning cycle, attempts are made to spawn packs of mobs per each eligible chunk. An eligible chunk is determined by the same check for which chunks are random ticked. A random location in the chunk is chosen to be the center point of the pack. If the block on which a pack spawn occurs is an opaque full cube, further pack spawn attempts are canceled. There are a maximum of 3 pack spawn attempts per mob category.

The pack is spawned within a 41×1×41 (that's a 41×41 square that is one block high) area centered at the initial block. Mobs spawn with the lowest part of their body inside this area. For each spawn attempt, from the location of the previous attempt, a location up to 4 blocks away from the previous attempt is chosen at random. Thus, the spawns are heavily skewed toward the center of the pack. Approximately 85% of spawns are within 5 blocks of the pack center, and 99% within 10 blocks of the center. If the pack spawn enters a biome different from the starting biome, the rest of the pack and that spawn are canceled.

All mobs within a pack are the same species. The species for the entire pack is chosen randomly, but based on a weight system from those eligible to spawn at the location of the first spawn attempt in the pack.

The game checks on each spawn if the number of mobs that have been spawned for the pack is equal to the max spawn attempts, as well as the location's spawn potential.


 * Pack spawn size

Pack spawn attempts max out at:


 * 8 Wolves, cod, and tropical fish
 * 6 Horses and Donkeys
 * 1 Ghast
 * 4 for any other mob

When the max pack size is less than the number of possible spawn attempts, some spawns attempts fail, but are seen more commonly in practice. Based on the number of mobs that have been successfully spawned. If the max pack size is greater than the number of spawn attempts, one gets only the number of spawns from the spawn attempts. Some mobs have a minimum and max pack size, meaning there is an even chance for any number of spawn attempts between them occurring.


 * For zombie villagers, drowned, pillagers, donkeys in savanna biomes, parrots in jungles excluding bamboo jungle and jungle, cats in swamp huts and witches, it is 1.
 * For parrots in bamboo jungles and Jungle, polar bears, squids in lukewarm oceans, pandas and dolphins, it is 1-2.
 * For donkeys in plains biomes, ocelots and pufferfish, it is 1-3.
 * For endermen except in the End and in nether wastes, and squids except in lukewarm oceans, it is 1-4.
 * For rabbits and blazes, it is 2-3.
 * For guardians, foxes, zombified piglins in crimson forests and striders, it is 2-4.
 * For turtles, it is 2-5.
 * For horses, it is 2-6.
 * For piglins and hoglins in crimson forests, it is 3-4.
 * For Cod it is 3-6.
 * For llamas, it is 4-6.
 * For mooshrooms, it is 4-8.
 * For wither skeletons and skeletons, in nether fortresses, it is 5.
 * For bats and tropical fish, it is 8.
 * For every other mob, it is 4.


 * Pack spawn location

For all dimensions, structure-based spawns take priority over biome for hostile spawns. This means that in a swamp hut, pillager outpost, nether fortress (outer bounding box only when there is nether brick below it), and ocean monument, one sees only the corresponding hostile mobs for that structure within that structure.

In the Overworld, this depends on the location:


 * Jungle biomes have a higher chance to spawn chickens.
 * Badlands biomes spawn only hostile mobs and bats.
 * River and frozen river can spawn only drowned, squid, and salmon underwater.
 * Ocean biomes do not spawn passive mobs. They spawn drowned, and the other hostile mobs. Frozen oceans do not spawn dolphins, but do spawn polar bears.
 * Swamp huts spawn only witches, cats, and bats.
 * Ocean monuments spawn guardians, other water mobs and bats.
 * Pillager outposts spawn pillagers, other passive mobs and bats.
 * All other overworld biomes spawns common animals and common monsters, as well as slimes, dependent on spawn conditions.

In the Nether:
 * Skeletons, wither skeletons, magma cubes, zombified piglins, and blazes can spawn within nether fortresses.
 * Ghasts can spawn in nether wastes.
 * Zombified Piglin and Piglin can Spawn in nether wastes, while magma cube spawn primarily in Basalt Delta biomes and sometimes in nether wastes.
 * Mobs (excluding zombified piglins and skeletons) that can spawn anywhere in the Nether ignore light level.
 * Hoglins and piglins can spawn at a higher rate anywhere in the crimson forest biome.
 * Endermen can spawn more frequently in the warped forest biome, but not in the crimson forest.
 * Skeletons and Ghasts can spawn more frequently in the soul sand valley biome.

Spawn conditions
Whether a spawn condition fails differs from the above determination if the game tries to spawn them in that biome. For example, dolphins can have pack spawns that occur inside of frozen ocean and deep frozen ocean biomes, but no other biomes. These rules apply to variants of the same mob, such as baby zombies and spider jockeys.

Each individual spawn attempt succeeds only if all of the following conditions are met:
 * There must be no players or the world spawn point within a 24 radius block distance (spherical) of the spawning block
 * The number of loaded mobs of that type must be less than the mob cap for that type. (I.e. the corresponding mobcap must not be full)
 * The mob's collision box upon spawning must not collide with another collision box. A mob cannot spawn inside of anything that would collide with it upon spawning.
 * The mob's collision box must not intersect with a block.
 * For all mob types excluding passives and fish, spawns fail unless within a 128 radius block sphere around the player. For fish, spawns fail unless within a 64 block radius of the player.
 * Gamerule DoMobSpawning is true
 * For non-aquatic mobs, the spawning block and the block above that cannot be rails, powered rails, detector rails, activator rails, redstone components, wither roses (except for wither skeletons) or sweet berry bushes (except for foxes).


 * Hostile mobs


 * The difficulty must not be Peaceful, excluding piglins and hoglins
 * This also affects ocelots
 * For all hostiles other than guardians, drowned, and phantoms:
 * the block directly below it must have a solid, opaque, top surface (this includes upside down slabs, upside down stairs, and others) or be soul sand or a slime block.
 * the block directly below it must not be bedrock, barrier, or‌ any type of trapdoor‌ or glass.
 * The mob's collision box must not collide with any liquid.
 * The block above the spawning block must be transparent
 * For slimes from swamp biomes, creepers, skeletons, wither skeletons, witches, zombie villagers, husks, strays, drowned and spiders:
 * The light level divided by 8 is the chance of a spawn failing; thus mobs spawn at light level 7 and below.
 * In the Overworld, this follows internal skylight level as well as block light level. Internal light level is affected by thunderstorms.
 * Spawns with sky access in overworld have an additional 50% failure rate
 * If it is a slime from a swamp biome, then.....
 * the spawning block must be in a swamp biome
 * the spawning block be on level 51 through 69 inclusive
 * chance of failure based on the phase of the moon
 * with a 50% chance of failure.
 * If it is a husk or stray, then....
 * The location of the spawn must have sky access (i.e. have a skylight level of 15).
 * If it is a skeleton in a Nether fortress, then...
 * There is an 80% chance of spawning a wither skeleton instead.
 * The light checks in the general hostile mob check don't apply to:
 * Slimes from slime chunks (see the slime page for details), which spawn when:
 * the spawning block is below level 40.
 * with a 90% chance of failure.
 * If it is a Ghast, then...
 * With a 95% chance of spawn failure.
 * If it is a Magma cube, then...
 * the block below must not be a nether wart block.
 * If it is a hoglin, then...
 * the block below must not be a nether wart block.
 * If it is a blaze, then...
 * the light level must be 11 or darker.
 * If it is a piglin or zombified piglin, then...
 * the light level must be 11 or darker.
 * the block below must not be a nether wart block
 * If it is a polar bear, then...
 * The light level must be greater than 8.
 * The block beneath must be ice.
 * The spawning block must be in a frozen ocean or deep frozen ocean.
 * If it is a blaze, wither skeleton, skeleton, magma cube or zombie pigman in the fortress external bounding box:
 * the block beneath must be nether bricks.
 * If it is an ocelot, then.....
 * the spawning block must be level 62 or higher.
 * the block directly below the spawning block must be grass or leaves.
 * there is a $1/5$ chance for the spawn to fail in jungles, 100% chance in bamboo jungles and jungle edges.
 * For Guardians and Drowned:
 * The spawning block, the block above and the block below must be water, including waterlogged blocks and bubble columns.
 * If it is a guardian, then...
 * 95% chance of failure if the spawning block has sky exposure (details).
 * If it is a drowned:
 * It has a $8/10$ chance to succeed in oceans, while a $1/10$ chance to succeed in rivers.
 * In ocean biomes, drowned spawn at a height less than 5 blocks below sea level.


 * Passive mobs


 * The mob's collision box must not collide with any liquid.
 * if it is not a strider, the light level of the spawning block must be 9 or brighter.
 * If it is a mooshroom, then.....
 * the block directly below the spawning block must be mycelium.
 * If it is a turtle then.....
 * the block directly below the spawning block must be sand.
 * the spawning block must be level 67 or lower.
 * If it is a Ocelot, then....
 * Spawn has a 33% chance of failure.
 * the block directly below the spawning block can either be Grass Block or Leaves
 * If it is a Parrot, then....
 * the block directly below the spawning block can either be Grass Block, Leaves, or a log
 * If it is a Rabbit, then....
 * the block directly below the spawning block must either be Grass Block, Snow, or Sand
 * For all others then.....
 * the block directly below the spawning block must be a grass block.
 * If it is a strider, then.....
 * Spawn attempts with lava above check upward as long as there is still lava for if they can successfully spawn in a lava block with air on top.
 * Striders spawn at y level 31 or lower.

For squid, cod, salmon, pufferfish, tropical fish or dolphin:
 * Aquatic mobs
 * the spawning block and the block above must be liquid (water) but it cannot be waterlogged
 * the block below the spawning block must be water or waterlogged
 * If it is cod, salmon, pufferfish, tropical fish, then the water ambient mobcap must not be full
 * If it is squid or dolphin, the water creature mobcap must not be full
 * *If it is a squid, then...
 * the spawning block must be between level 46 and 62, inclusive
 * the spawning block must be in an Ocean or River
 * If it is a dolphin then.....
 * the height of the spawn must be greater than 45 and less than sea level (62).
 * the spawning block must be in an ocean or deep ocean


 * Ambient mobs


 * The mob's collision box must not collide with any liquid.
 * If it is a bat, then...
 * the spawning block must be at level 62 or below.
 * If the real-time day is between October 20 and November 3, then the light level must be 7 or darker. Otherwise, the light level must be 4 or darker.

If all of these conditions are met then the mob is spawned.

Endermen within warped forests, and skeletons, ghasts, striders and endermen in soul sand valleys increase a charge within the spawn cost. If the charge is high enough in an area, any mob that adds to the charge does not spawn.
 * Spawn costs

Charge raising mobs add the charge in a sphere around them. This occurs farther the charge cancels spawns. Mobs' charge spheres don't cover each others' up, but stack, affecting areas further away, given the mobs are in proximity. The charge set by 1 mob is the same throughout the block the mobs resides in and the block south, east, and southeast adjacent to it. From that, charge prevents spawns within 6 blocks straight between them or 4 blocks along a diagonal, given no other charge affecting mobs are present.

Due to how Minecraft spawns mobs, this leads to a lot of mobs spawning in any space outside of these biomes.

Bedrock Edition
Environmental spawning $5/10$ shares broad similarities to natural spawning in Java Edition : mobs spawn in a radius around the player subject to block conditions, lighting conditions, biome conditions, naturally generated structure conditions, and caps. Many mobs spawn in groups (called "packs" in Java and "herds" in Bedrock). One notable difference from Java Edition is that most animals can spawn at light level 7 or higher rather than 9 or higher.

There are two types of environmental spawns: cluster spawns and structure spawns. Structure spawns reproduce specific types of mobs at specific locations within certain naturally generated structures, such as nether fortresses, witch huts, etc. Cluster spawns account for all other types of environmental spawns, including mobs that spawn individually (i.e. not in a herd of 2 or more). Both types of environmental spawns follow the same rules for spawn conditions and mob caps, except that structure spawns can exceed the monster population cap by 1 (see below).

Mob spawning in bedrock edition happens within a spherical shell 24-44 blocks away from the player on simulation distance 4. It happens a quasi-spherical shell 24-128 blocks away from the player, restricted by a simulation distance and/or to roughly 96 blocks horizontally, on simulation distances 6 and higher. This means that mobs can spawn directly above or below you. For example, phantoms can spawn in the sky above you and other mobs can spawn directly below you while you're flying, standing on a high platform, or above a cave. Mobs can only spawn in chunks that are being ticked. There is a $4/10$ chance of the mob spawning algorithm attempting to run per chunk, per tick.

Bedrock Edition mob cap
There are three mob caps that affect environmental spawning: a global mob cap, population control caps for general mob types, and density caps for specific mob types. The global mob cap is set at 200 regardless of difficulty. The global mob cap affects only environmental mob spawning, and does not affect mobs spawned through breeding, spawn eggs, the command, spawners or any other type of mob spawning. Only mobs that have spawn rules count toward the global cap (i.e. armor stands and minecarts do not take up cap space). In addition, only mobs that are within ticking areas (both those around players and those set manually using the command) count toward the global mob cap; mobs not ticked do not count toward the global mob cap.

The population control caps limit how many mobs of each type and category can spawn within a 9 chunk by 9 chunk square region surrounding the chunk in which the spawn attempt is made. Mobs in chunks outside a ticking area still count toward population control counts as long as they were previously loaded (i.e. within simulation distance at some time) after relogging. The population control caps are split up into two distinct categories: a cap for surface mobs, and a cap for cave mobs. Cave mobs do not count toward the surface mob cap, and surface mobs do not count toward the cave mob cap. Whether a mob counts as a surface mob or a cave mob is determined by where or how it spawned, not where it happens to be at the moment. For cluster spawns, those that spawn on the highest spawnable block at a given coordinate count toward the surface cap, and any that spawn below the highest solid or non-solid but spawnable (e.g. ice or upper slab with air above) block count toward the cave cap. Structure-spawned mobs and converted mobs (i.e. drowned converted from zombies, witches from villagers, zombified piglins from pigs, and medium and small slimes from killed larger slimes) always count toward the cave cap, and spawner-spawned mobs always count toward the surface cap.

There are five categories of mobs: ambient, animal, monster, pillager, and water_animal. The population control cap for each category and location of mob in each dimension is as follows (* denotes values that are coded in the game but not actually used by any mobs):

Some specific mobs types also have their own density caps. The density caps limit the number of those mobs to some amount below the applicable population control cap. Density caps are checked in the same manner as the population control caps. Caps are below (n/a indicates that the mob does not spawn in that environment at all).

Bedrock spawn conditions
The following rules apply to most mobs:
 * Mobs spawn at a distance from the player that depends on the world's simulation distance:
 * Simulation distance 4: between 24 and 44 blocks spherical radius from the player.
 * Simulation distance 6 and up: between 24 and 128 blocks spherical radius from the player, but limited horizontally by simulation distance and coding that restricts the spawning algorithm from running in chunks whose center is > 96 blocks from the player.
 * The bottom part of the mob (i.e. the feet of a standing mob, or the whole body of a mob <= 1 block tall) can spawn only in an air block, or for water mobs in a water block. A few naturally-generated, non-motion-blocking blocks such as grass and flowers are ignored for this rule.
 * There must be a block with a full, solid top surface under the spawn location for the mob to spawn on. (I.e. mobs cannot spawn on carpets, lower slabs, fences, right-side-up stairs, redstone repeaters, chests, etc.)
 * Mobs cannot spawn on transparent full blocks like glass and leaves.
 * For mobs that can spawn floating in water or flying in air, the block that is checked for spawning is the water or air block immediately above the first solid top surface block below the spot where the mob would spawn. (So for example, phantoms cannot spawn over a field covered in carpet, and fish cannot spawn in an ocean where bottom slabs cover the ocean floor.)
 * Most overworld monsters cannot spawn if the light level is greater than 7.
 * Most overworld animals cannot spawn if the light level is less than 7.

Cluster spawning
Cluster spawning happens in two stages: first attempt to spawn surface mobs, then attempt to spawn cave mobs. Before spawning, the population control cap is calculated based on the 9 chunk x 9 chunk square area surrounding the current chunk. Spawning begins by picking a random X and Z location within the chunk currently being evaluated. The Y coordinate is determined by starting at the world height and searching downward for a solid-top-surface block with a non-spawn-blocking block above it. The first such block that is found is considered to be the surface, and the algorithm attempts to spawn a surface mob herd. However, if the algorithm finds a solid block before finding a spawnable solid-top-block (e.g. if it finds a tree trunk directly under leaves), it does not make any surface spawn attempt. The algorithm then continues to search downward for the next suitable block with a non-spawn-blocking block above it. When a block meeting the criteria is found, the algorithm attempts to spawn a cave mob herd at that block location. Cave spawn attempts continue until the Y coordinate reaches the world bottom, and do not stop even if a cave herd was spawned.

Surface and cave cluster spawn attempts then go through the following steps to figure out what mob to spawn and how many:


 * 1) Picks a random mob.
 * 2) * If the current spawn location is in a liquid, pick a random water mob.
 * 3) * If the light level is 7 or higher, there are no other blocks above the current location, and the current location is a grass block, pick a random animal mob.
 * 4) * Otherwise, spawn a monster mob.
 * 5) Picks a random number of mobs to spawn in the herd. Each mob can have its own min and max herd size, and the herd size can depend on difficulty and biome.
 * 6) Make sure the spawn location has suitable spawn conditions.
 * 7) Limit the number of mobs spawning based on the global mob cap. No mobs spawn if the mob count already meets or exceeds the mob cap.
 * 8) For each mob to spawn, check that spawning it would not exceed the population control cap or mob density cap.
 * 9) * If spawning the mob would not exceed the population control or mob density caps, then the probability of a mob spawning can be calculated using the formula:
 * 10) Finally, attempt to spawn the mob in the world.
 * 11) * Spawning the mob can fail; for example, if spawning it would cause it to spawn inside of a block or part of a wall.

Structure spawning
Structure spawn attempts occur at specific relative X and Z coordinates in naturally generated structures, known as "hard-coded spawn spots". The structures that have hard-coded spawn spawn include witch huts, ocean monuments, pillager outposts, and nether fortresses. Whenever a successful cluster spawn attempt occurs within a chunk that contains a hard-coded spawn spot, the environmental spawning algorithm also attempts a structure spawn. (Note that a "successful attempt" here means that a spawnable block was found, even if the spawn was then blocked by light level check or mob cap check.) The structure spawn attempt follows the same rules and steps described above for cluster spawning, with the following changes:


 * Instead of starting at world height and searching down to bedrock at the specific X and Z location, the search begins and ends at a specific Y values determined by the type of structure. Structure spawn attempts only occur on the first spawnable block found (i.e. the highest spawnable block) within that range.
 * The mob picked depends on the structure: witch huts spawn witches, ocean monuments spawn guardians, pillager outposts spawn pillagers (including patrol captains), and nether fortresses spawn skeletons, wither skeletons, blazes, and magma cubes.
 * The population control caps are effectively 1 higher for structure spawn attempts.

Other types of spawning

 * A thrown egg spawns chickens. See: Egg Chicken Spawning
 * A snow golem, iron golem, or wither can be made to spawn if a player builds the proper structure out of blocks. Iron golems can also spawn in sufficiently populous villages. See their respective pages for full details.
 * An infested block spawns a silverfish if broken, or if a nearby silverfish is attacked.
 * Zombified piglins can spawn from nether portals in the Overworld. Lighting and player proximity don't prevent this.
 * Endermites can spawn randomly when a player uses an ender pearl.
 * Killing medium and large slimes and magma cubes spawn more of them, but in a smaller size.
 * When a pig gets struck by lightning, it is replaced by a newly spawned zombified piglin.
 * When a villager gets struck by lightning, it is replaced by a newly spawned witch.
 * If a creeper gets struck by lightning, it becomes charged.
 * A monster spawner causes mobs to spawn constantly in the area around it. Spawners may naturally generate spawning zombies, skeletons, spiders, cave spiders, silverfish, magma cubes, or blazes, but may be made to spawn other mobs using commands or spawn eggs. See: Spawner
 * Turtle eggs hatch and spawn baby turtles.
 * Zombies, illagers, and zombie pigmen can spawn reinforcement when hurt.
 * Trapped horses can spawn during thunderstorms, then spawning skeleton horsemen.
 * Zombie villagers spawn as 5% of naturally-spawning zombies
 * A villager killed by a zombie has a 50% chance of becoming a zombie villager in normal difficulty, and 100% chance in hard difficulty.
 * Skeletons spawn as 20% of naturally-spawning strays.
 * Zombies spawn as 20% of naturally-spawning husks.
 * Baby zombies, zombie pigmen, drowned, husks, and zombie villagers have a 15% or 5% chance of spawning as chicken jockey.
 * Spiders and cave spiders have 1% chance of spawning as spider jockey
 * Vindicators, evokers, pillagers, ravagers, and witches can spawn as part of raids.
 * Phantoms spawn after player does not sleep or die for at least 3 days. ($1/10$ phantoms are spawned by the environmental spawning algorithm like other monsters. They are subject to the monster cap, and they count toward the monster cap.)
 * Cats spawn based on the number of beds in a village.
 * A brown mooshroom spawns when a red mooshroom is struck by lightning, and vice-versa.
 * Patrols consist of vindicators and pillagers. $2/3$, patrols can spawn like regular monsters. $8/10$, patrols can spawn in any biome except in the End, the Nether, and mushroom fields; they even spawn in biomes where common monsters cannot spawn, such as in legacy frozen ocean.
 * Cod, salmon, pufferfish, and tropical fish spawn when using the corresponding bucket of fish.
 * Bees spawn when a bee nest or beehive is broken without Silk Touch.
 * If a piglin or hoglin is transported to the Overworld or the End, after 15 seconds they transform into zombified piglins or zoglins, respectively.
 * In Creative or via a dispenser, the player can use spawn eggs to spawn most mobs. When mobs are spawned this way, all normal spawning requirements, such as light level and block type, are ignored (though monsters other than vindicators, evokers, shulkers, and ender dragon still cannot be spawned in peaceful).
 * An agent spawns when using a code connection.
 * Any entity can be spawned using the command.

Java Edition


All hostile mobs excluding shulkers, withers, elder guardians and ender dragons despawn unless they have been marked persistent. Non-hostile mobs that despawn include hostile wolves, ocelots, stray cats and wandering traders. Ambient mobs such as dolphins, fish, squids and bats despawn unless marked persistent.


 * A mob that has had no player within 32 blocks of it for more than 30 seconds has a $8/10$ chance of despawning on each game tick ($5/10$ of a second), which is a 2.47% chance per second. Therefore, the average lifetime of monsters not within 32 blocks of a player is 40 seconds (after the initial 30 seconds have elapsed).
 * Mobs other than fish despawn immediately if no player is within 128 blocks of it, while fish despawn if no player is within 64 blocks.
 * Note that this is a Euclidean sphere, not a cylinder from map top to bottom and not a taxicab sphere (an octahedron). Example: A mob at 0/y/0 remains at least 30 seconds (as above) if the player moves to 65/y/65 (real distance 91.9), but despawns immediately if the player moves to 91/y/91 (real distance 128.7).
 * The chunk the mob is in must still be loaded for the mob to despawn. Otherwise, the mob is saved until the chunk is loaded again. For example, if a player enters a nether portal while a spider is chasing them, the spider will be saved, and surprise the player when they come through the same portal again. In the case of a player reloading chunks, the loading happens before the player is added, meaning they may despawn.
 * Most hostile mobs (including those that are holding items) in a world despawn if the difficulty is set to Peaceful, regardless as to where the player is positioned in the world. However, some hostile mobs do not despawn in peaceful.
 * For despawning to occur, there must be at least one non-spectator player in the dimension.
 * Chickens that originally spawned as chicken jockeys follow zombie despawn rules, rather than chicken despawn rules.

Mobs are persistent, meaning they do not despawn and do not count toward the mob cap, when:


 * They are a passenger to another mob.
 * They are riding a Boat
 * They are riding a minecart.
 * They spawned as part of a generated structure.
 * They have had something added to their inventory, including having something dispensed upon them (such as a saddle) or something they have picked up, but never for anything they spawn with. This includes dolphins playing with items.
 * They have been named with a name tag. However, one created from a renamed spawn egg does despawn as normal.
 * They spawn as part of a raid.
 * For enderman, if they have picked up a block.
 * For fish, if they have been placed out of a fish bucket.
 * For zombie villagers, if they were converted from a villager that has been traded with.
 * For hoglins, if a crimson fungus is on them.
 * For zoglins, if a crimson fungus is on the hoglins before they zombify.
 * They have had the NBT tag  set on them, whether by being summoned with it, or by being set manually with  or.
 * They are utility mobs—iron golems and snow golems.

Bedrock Edition
$4/10$, like Java, despawning occurs based on distance and chance.


 * On simulation distances 6 and higher, almost all environmentally spawned mobs immediately despawn when they are either (1) in a chunk at the edge of the simulation distance (technically, a chunk not fully surrounded by 8 chunks that were simulated on the last game tick), or (2) more than 128 blocks from the nearest player.
 * On simulation distance 4, mobs immediately despawn when they are more than 44 blocks from the nearest player.
 * Fish despawn at a shorter distance, when they are more than 40 blocks from the nearest player on all simulation distances.
 * Mobs more than 32 blocks from the nearest player have a 1 in 800 chance to despawn on each game tick if they have not taken damage for 30 seconds.

Mobs with persistence do not despawn. Mobs gain persistence in the following ways:


 * The entity interacts with a player:
 * Is ridden by the player.
 * Is named with a name tag.
 * Is tempted with food.
 * Is bred, or born as a result of breeding (except for turtles hatched from eggs ).
 * Is tamed by the player
 * Is summoned using the command or a spawn egg.
 * Is cured (curing a Zombie Villager spawns a villager).
 * Is spawned by the player triggering a skeleton trap (spawns skeletons and skeleton horses).
 * The entity is spawned during the generation of a certain kind of structure:
 * Shulker spawned in an end city.
 * Witch spawned in a witch hut.
 * Villager or zombie villager spawned in an igloo.
 * Villager spawned in a village.
 * Zombie villager spawned in a zombie village.
 * Vindicator or Evoker spawned in a woodland mansion.
 * The entity is spawned by the conversion of a persistent entity. For example, when a persistent zombie converts to a drowned, the drowned inherits the persistence.
 * The entity is a trader llama summoned by a wandering trader.

The following entities always have persistence:
 * Ender Dragon
 * Wither
 * Elder Guardian
 * Guardian
 * Iron Golem
 * Snow Golem
 * Villager
 * Vindicator
 * Armor Stand
 * Painting
 * Agent

Trivia

 * The world spawn (the point where players spawn if they have no valid bed spawn) is usually a random (seed determined) point between -500 and +500 on the X and Z axis. If the chosen point is in water (due to nothing but ocean biomes in the -500 to +500 range), a second attempt is made between -1500 to +1500. If this fails due to ocean, the game gives up and puts the world spawn in the middle of the ocean (still at the surface) (attempting to play the flat lands preset Water World does this, for example). Normally, a player who spawns in the water does so near the shore because the world spawn itself picked a spot there.
 * An opaque block normally causes all blocks below it to spawn cave mobs, but not if a transparent block is placed on top.