How does spawning in Minecraft work?
Minecraft uses a weighted, conditional spawn system to spawn its mobs.
For starters, Minecraft always keeps its world populated with mobs. Nobody has dug up the exact number to my knowledge, but Minecraft ALWAYS keeps a certain amount of mobs alive in the world. If there are not enough mobs in the vicinity of the player, the game will immediately try to spawn more. This explains scenarios such as squid being much more common in the ocean; they are the only mob that can spawn while the player is out in the ocean, and because the game needs to have a certain amount of mobs, they all have to be a squid.
You need to keep this in mind. If your custom mob is the only one that can spawn in a certain situation, it doesn't matter how rare it is. They will spawn a LOT. Say you write custom code to make a monster that spawns at day, with a measly spawn weight of 1 (5 times rarer than a witch!). You'd expect this mob to almost never spawn since it has a spawn weight of 1. But there are no other monsters that can spawn at day, so that is the only mob that the game can spawn, and it doesn't care how low the spawn weight is in that case. Your incredibly rare monster suddenly appears tenfold across the world.
As I mentioned, many mobs can only spawn in certain conditions. When trying to spawn a mob, the game will only pick mobs that meet the current criteria for a spawn location it has chosen. Many of these conditions can be controlled in MCreator, by the way. Many examples that influence what mobs can spawn may be:
- Time of day
- Light level
- Amount of space available (is the mob too big?)
- Are we spawning in water or on land?
- The block to spawn the mob on (for example, animals prefer to spawn on grass)
- A mob's spawning type
You are asked to choose a mob spawning type when creating a mob in MCreator. The game will always have mobs of different spawning types in the world; there will always be a fairly even balance of monsters, animals and so on, even if one type is more likely to spawn than the other.
- Monster - This mob prefers to spawn in low light levels or at night. Examples are Zombies, Skeletons, and Spiders. Pretty basic.
- Creature - These mobs can spawn at any time, but monsters have much higher spawn weights and usually take over at night. Examples are Chickens, Cows, and Pigs. Again, fairly easy to understand.
- Water Creature - To my knowledge, Water Creatures behave identically to regular Creatures, but spawn in liquids instead of on blocks. Examples are Squid and Guardians.
- Ambient - This is one you need to watch out for. Ambient creatures are identical to regular Creatures but are simply a different category to make sure that both types of creature will spawn. The problem? Bats are the only ambient creature in vanilla Minecraft. They can also only spawn in the dark. If you set a mob to Ambient, and allow it to spawn in the light, expect it to be ABSOLUTELY EVERYWHERE. This category was supposedly intended by Mojang to be used for creatures with no gameplay effects, such as bats, frogs, etc. and that is all you should use it for. Do not make a hostile mob and place it in Ambient!
Other spawning parameters
Although much simpler than those I just mentioned, I would also like to go over the other spawn parameters available.
- Despawn when idle - This is ticked for almost any mob in the game, except for Iron Golems, bosses, and basically whatever you would expect to not disappear after disappearing on a 2-hour mining trip. Turn this on so the world doesn't become overloaded with your custom mobs. Leave it off for bosses and player-created mobs, and just generally stuff you don't want to disappear.
- Mobs in spawn group - The minimum and maximum values here simply determine how large a group of this mob is allowed to be. Use a larger range for more diverse groups and vice versa.
- Specific biomes - Self-explanatory. The mob will only spawn in the biomes you pick here. For the uninitiated, Hell is the Nether and Sky is the End, in case your mob spawns in multiple dimensions.
- Can spawn in dungeons? - You know the small dungeon rooms in Minecraft, with chests and a spawner for a spider or skeleton or whatever? This allows your mob to be featured in those spawners. Do this for tough mobs to give your player a hard time ;)
So what spawn weight should I use?
When choosing spawn weight, remember that as mentioned above, the spawn weight is compared to that of other mobs that could also be spawned. If your mob has very few spawn restrictions, you should set a lower weight than you would for a mob that can only spawn at night in a certain biome.
Some vanilla mob weights were dug up from Minecraft code here.
- Witches have a spawn weight of 5.
- Cows have a spawn weight of 8.
- Endermen, Chickens, Pigs, Squid and Bats have a spawn weight of 10.
- Sheep have a spawn weight of 12.
- Zombies, Skeletons, Spiders, Creepers, and Slimes have a spawn weight of 100.
Of course, even though zombies and such have 100 spawn weight, they cannot spawn at day meaning only the other weights matter. The game decides which mob to spawn simply by adding up all of the weights and picking a random number in there which corresponds to a certain mob and it's weight.
Here I'll go over what I would set the spawn weights to for certain types of the mob you might create.
- If you're making a new monster, set the spawn weight to 100.
- If you want a rarer monster, set the spawn weight to somewhere below 10. Remember that 10 is an Enderman's spawn weight and 5 is a Witch's.
- For a world boss of some kind, set the spawn weight to 2, 1 or even a decimal.
- For an animal, set the spawn weight to somewhere between 7 and 15, depending on how common it should be.
- For a rare animal, use something like 0.2, which balances nicely with other animals.
In simple words, think about the other mobs that could spawn instead of yours, and consider their weights.
I also did some quick rough maths here to give you some ideas for how common a mob would be in percentage. These are only accurate based on the spawn weights we know for vanilla mobs, and of course the more mobs you add the lower their chance of spawning is.
- A new monster with 20 spawn weight has a 4.5% chance to spawn whenever the game needs to spawn a monster.
- A new monster with 100 spawn weight has a 19% chance to spawn and will be as common as most common monsters.
- A new monster with 5 spawn weight has a 1.1% chance to spawn.
- A new monster with 1 spawn weight has a 0.2% chance to spawn, which means 1 in 500 mobs will be your custom one. Great for a world boss!
For animals, you should reduce spawn weight compared to monsters.
- A new animal with 20 spawn weight has a 33% chance to spawn whenever the game wants to place an animal. A pretty high chance, since 1 in 3 animals will be your custom one.
- A new animal with 10 spawn weight has a 20% chance to spawn and will be as common as most farm animals.
- A new animal with 2 spawn weight has a 4.7% chance to spawn, this would be good for something rather rare. (This is actually more than a monster with 20 spawn weight!)
- A new animal with 0.2 spawn weight has a 0.5% chance to spawn. Great for a Zelda-styled legendary bunny or something.