Spawn

''This article is about natural spawning of players and mobs. For Monster Spawners see: Monster Spawner.''

Spawning refers to players and mobs being created and placed in the game world. Players will respawn on their spawn point upon death.

Player Spawning

 * ''For this discussion, coordinates refer to the column centered at (x+0.5, z+0.5). That is, -225x, 255z refers to the column bounded by -224x to -225x and 225z to 226z.

Every world has a "spawn point" (really, an area) located within a few hundred blocks of the origin (0x, 0y, 0z). This point is stored in the leve l.dat file's,  ,   attributes (although   seems to be ignored). If the spawn point is deemed unacceptable, a new, temporary spawn point will be selected (although the criteria for "unacceptable" is unknown).

A player with no spawn point set (such as by a bed) will be placed randomly at the highest point in a 20x/20z square centered on the x-/z- corner of the spawn point; that is, the 20x/20z spawn square's edges are at SpawnX -10/+9, SpawnZ -10/+9.

A 33x/33z slice of the world centered at SpawnX, SpawnZ is "protected", and can (almost; see below) only be modified by Operators; that is, the 33x/3 3z protection square's edges are at SpawnX +16/-16, SpawnZ +16/-16.

Non-operator players cannot place or destroy blocks in the protected area, nor can they use doors or Redstone devices other than Pressure Plates. Creepers can still destroy terrain in the protected area and TNT placed outside of the protected area will destroy surrounding blocks as usual. Along with this, portals from the nether can connect to the protected area, water/lava/fire can spread from outside into the protected area, and pistons can push items inside as well. Players can place blocks on the edge of the protected area if placed against the side of a block on the outside of the area. However, if the edges of the protected area are avoided, small, indestructible structures can be built.

As of Beta 1.4, sleeping in a bed will reset your spawn point to that bed when you awake from them naturally at dawn. If the bed at which you have set your spawn point last is removed, your spawn point reverts to its original location (somewhere near x=0,z=0). The same applies to multiplayer, but clicking "Leave Bed" still resets the spawn point.

Derivation


The spawn point was forced to 100x,100z and the player data was cleared. The purple square outlines the column at 100x,100z, which holds an obsidian tower.

To determine the spawn area, a flat, open area large enough for the (presumed) 20x20 spawn area was created. The player (an op) repeatedly respawned and immediately dug a hole if one was not already present. The red square, above, is drawn from the midpoints of the outermost holes in each direction.

To determine the protection area, the player (a non-op) attempted to place blocks until successful while moving away from the spawn, and then traced around the edges of the protected area until all four corners were found. The lapis corners marked above were the extent of the minimum placeable area by the player. The blue square, above, is drawn from the midpoints of the outermost protected blocks in each direction.

The dimensions of each square are given by  to include the extra half-block on either end of the measurement:

XXXXX  <- width=5 123456789  ^min=3 ^max=7

Animal Spawning
Approximately one in ten newly generated chunks will contain animals, usually in packs of up to four of the same species. They will always spawn on the highest available block in a column i.e. the one that can see the sky. For an animal to spawn on it, this block must be opaque and the two blocks above it must be non-opaque. The block does not need to be Grass nor does it need to be illuminated (as it does with Mob Spawning).

Animals do not spawn in desert or ocean biomes.

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

Very rarely, new animals can spawn in already generated chunks, just like monsters do. Unlike monsters, animals never despawn.

Mob Spawning
Mobs are broadly divided into three categories: hostile, friendly, and water (i.e. Squid). Hostile mobs have a spawning cycle once every game tick (1/20th of a second). Friendly and water mobs have only one spawning cycle every 400 ticks. Because of this, hostile mobs can spawn at any time, but animals spawn very rarely. Instead, most animals spawn within chunks when they are generated (see Animal Spawning).

At the beginning of a cycle, a list is built of all the chunks that are within a 17x17 chunk (272x272 block) area around any player. Mob caps are then calculated based on the number of chunks in the list, using the following formula:

cap = constant * chunks / 256

Each mob category has a separate cap and a different constant in the formula:

Hostile = 70 Passive = 15 Water = 5

In single player mode, there will always be 17x17 = 289 chunks in the list, and the caps work out to:

Hostile = 79 Passive = 16 Water = 5

In multiplayer, chunks that are in range of multiple players are only counted once. So the more spread out the players are, the more chunks will be covered and the higher the caps will be.

The cap is checked once at the beginning of each spawning cycle. If the number of living mobs in a category is over its cap, the entire spawning cycle for that category is skipped.





For each spawning cycle, one attempt is made to spawn a randomly chosen mob pack in each chunk in the list. A random location in the chunk is chosen to be the center point of the pack. For the pack to spawn at all, the center block must be the same "material" as the mob -- water for water mobs and air for all other mobs. Note that in the latter case, it must literally be an air block. Any other block, even a non-colliding one, will prevent the entire pack from spawning.

The pack location must also be in a suitable Biome. Ghasts and Zombie Pigmen can only spawn in the Nether and all other mobs can spawn only in the Overworld. Wolves spawn only in forest and taiga Biomes.

If the pack location is suitable, 12 attempts are made to spawn up to four mobs within a 41x1x41 area centered at that block (that's a 41x41 square that is one block high). Mobs will spawn with the lowest part of their body inside this area. Wolves spawn in packs of up to 8 and Ghasts always spawn alone.

For each spawn attempt, a random block is chosen within the pack area. Blocks close to the center have a much higher chance of being chosen (for the exact details, see the detailed algorithm below). The spawn attempt succeeds only if all of the following conditions are met:


 * There must be no players and no player spawn points within a 24 block distance (spherical) of the spawning block


 * If it's a water mob, then...
 * the spawning block must contain liquid (water or lava)
 * the spawning mob must not be obstructed by other mobs


 * If it's not a water mob, then...
 * the spawning block itself must be non-opaque and non-liquid
 * the block directly below it must be opaque
 * the block directly above it must be non-opaque
 * unless it's a Slime, the spawning mob must not be obstructed by blocks, other mobs, or water


 * If it's a passive mob other than Squid, then...
 * the block directly below the spawning block must be grass
 * the light level of the spawning block must be 9 or brighter


 * If it's a hostile mob other than a Slime, Zombie Pigman, or Ghast, then...
 * the light level of the spawning block must be 7 or darker and more light increases the chance that the spawn will fail
 * sunlight falling on the spawning block further increases the chance that the spawn will fail, by up to 50%


 * If it's a Slime, then...
 * the spawning block must be in a chunk eligible to spawn slimes (see the Slime page for details)
 * the spawning block must be below level 16 (40 as of version 1.9 pre 5).
 * for medium and large slimes, the difficulty must not be set to peaceful
 * there is an additional 90% chance the spawn will fail, thus slimes only spawn 1/10th as often as other mobs, all other things being equal


 * If it's a Ghast, then there is a 95% chance the spawn will fail, thus ghasts only spawn 1/20th as often as other mobs

If all of these conditions are met then the mob is spawned. The pack is complete when its maximum size is reached or 12 attempts have been made, whichever comes first.

Detailed Mob Spawning Algorithm
This pseudo-code is derived straight from the decompiled source of Minecraft Beta 1.7.3

make a list of chunks within 8 chunks lengths of any player (on X and Z)

for each mob category (hostile, passive, water) { calculate the mob cap = constant * chunks / 256 if the cap has been reached for this category, skip to the next category

for each chunk in the list, in random order { get the biome type for this chunk get the weighted list of mob types that can spawn in that biome use those weights to choose a random mob type from the list

choose a random block location in this chunk, as the "base" block of a pack if the block at that location is opaque, skip to the next chunk if the current mob category and the block do not have the same "material" (ie. water for squids, air for the rest) then, skip to the next chunk

loop 3 times { reset the spawn block equal to the center block of the pack loop 4 times { add random numbers from 0 to 5 to both x and z of the spawn block subtract random numbers from 0 to 5 from both x and z       if the current mob category is water then { if the spawn block is not liquid or the block above it is opaque, the spawn attempt fails } otherwise { if the spawn block is opaque or liquid or            the block above it is opaque or             the block below it is not opaque, the spawn attempt fails }

if the spawn block is within 24 block lengths of any player or the player spawn point, the spawn attempt fails

choose a random direction that the spawned mob will face if any conditions specific to the mob type are not met, the spawn attempt fails { chicken, cow, pig, sheep, wolf: block below spawning block is grass spawning block has a light level or sunlight level of 9 or higher (ie. the check passes even at night if the light level caused by the sun is higher than 9 at daytime)

creeper, zombie, skeleton, spider: sunlight level of spawning block is less or equal to a random number from 0 to 31 light level of block is less or equal to a random number from 0 to 7

slime: difficulty is not set to peaceful or slime size is small (if it's not peaceful, the algorithm won't get to this point) spawn block y coordinate is less than 16 the chunk containing the spawn block is a slime chunk (1 in 10 chance) pass a 1 in 10 random test ghast: pass a 1 in 20 random test squid: must not collide with any other entities

all except squid and slimes: must not collide with any other entities must not collide with any blocks must not collide with water or lava }

spawn the mob

if the mob is a spider and a 1 in 100 random test passes, turn it into a spider jockey

if the mob is a sheep, give it a random color if the mob pack is full (1 ghast, 8 wolves, or 4 of any other mob), skip to the next chunk }   }  } }

Other Types of Spawning
A Monster Spawner causes hostile mobs to spawn constantly in any nearby darkness.

A thrown egg has a 1 in 8 chance of spawning a chicken.

As of the 1.9 update, 2 Snow Blocks in the normal world placed on top of each other, with a Pumpkin or Jack-O-Lantern, causes a Snow Golem to spawn.

Despawning
Monsters, squid, and untamed wolves can spontaneously cease to exist, or "despawn", if they are far enough from all players. Other mobs (animals) never despawn in this way.

On every game tick (1/20th of a second), each living mob that is subject to despawning checks the following rules:


 * A mob that is more than 128 blocks (spherical) from every player will spontaneously despawn (disappear).
 * A mob that is more than 32 blocks from every player, and is more than 30 seconds old, has a 1 in 800 chance of despawning. That makes the average lifespan of a mob just under one minute, if they never come within 32 blocks of a player (but see the note below).
 * A mob that is within 32 blocks of at least one player, and is more than 30 seconds old, has a 1 in 800 chance of being "born again" -- having their age reset to zero and getting another 30 seconds of immunity to despawning (this may actually be a bug, the actual intention being to always reset the mob's age when it comes closer than 32 blocks).

Note that mobs only run their despawning code while standing still. If they are chasing a player or wandering, none of the above happens. So, assuming they spend roughly half their time walking, their average lifespan is probably more like 2 minutes. This may also be a bug.