-
Notifications
You must be signed in to change notification settings - Fork 1
Mob Spawning: Animals
Animal spawning in vanilla Minecraft happens in two phases: initially during world generation and later for loaded chunks.
There are multiple problems with that approach for a superflat server.
- Subsequent spawning is limited only to loaded chunks which turns player compounds into isolated areas where new animals can be found.
- After depleting naturally spawned animals, new players can’t find any mobs for their own.
- Initial generation spawns packs of animals completely randomly making horses and donkeys available in large numbers which favors early players and forces players joining late to trade or forgo fast travel.
To solve this, Animal spawning module was created. Its config can be found in animalspawn.yml and when enabled, it will generate a large SQLite database, animal_chunks.sqlite.
Chunks:
MinX: -500
MinZ: -500
MaxX: 500
MaxZ: 500A chunk is 16 by 16, so 500 chunks is 8000 blocks. Config shown above will span a map 16,000 squared. The area is defined in chunks because animal spawning module will load chunks in that area and spawn mobs.
The large database is first generated to create a list of chunks to systematically pick from.
SpawningIntervalTicks: 24000
ChunksSpawningAmount: 3This is the interval for loading chunks (24000 ticks means 1200 seconds; 20 ticks is 1 second) and how many chunks should be loaded at the same time.
If a chunk has any animals, additional animals won’t be spawned.
A basic animal declaration can look like this:
Animals:
Pig:
weight: 1
Cow:
weight: 1
Sheep:
weight: 1
Chicken:
weight: 1This config will spawn all animals equally. You can find a list of all animals in Bukkit documentation.
Additionally, sheep can be declared based on their color:
Sheep:
weight: 1
Colors:
White:
weight: 81836
Gray:
weight: 5000
Black:
weight: 5000
Silver:
weight: 5000
Brown:
weight: 3000
Pink:
weight: 164Weights above are pulled directly from Minecraft Wiki and are considered vanilla values.
Horses can be declared based on their appearance as well.
EntityHorse:
weight: 1
Colors:
Black:
weight: 1
Brown:
weight: 10
Chestnut:
weight: 10
Creamy:
weight: 5
Dark_Brown:
weight: 5
Gray:
weight: 5
White:
weight: 1
Styles:
None:
weight: 1
Black_Dots:
weight: 10
White:
weight: 5
White_Dots:
weight: 10
Whitefield:
weight: 5
Variants:
Horse:
weight: 10
Donkey:
weight: 1You can also define types for rabbits:
Rabbit:
weight: 1
MaxAdditionalPackMobs: 0
Types:
Brown:
weight: 1
White:
weight: 1
Black:
weight: 1
Black and white:
weight: 1
Gold:
weight: 1
Salt and pepper:
weight: 1
The killer bunny:
weight: 5AdditionalPackMobs:
Min: 1
Max: 3This means that a spawned animal has a chance to be accompanied by more mobs – in this case from 1 to 3 more (meaning that you will see 2-4 animals in packs).
Additionally, every animal declaration can overwrite pack settings:
Animals:
Chicken:
MinAdditionalPackMobs: 5
MaxAdditionalPackMobs: 10
EntityHorse:
MinAdditionalPackMobs: 0
MaxAdditionalPackMobs: 0In this case, chickens will spawn in packs of 6-11 and horses will always spawn alone.
It’s imperative to disable vanilla spawning for animals declared in config to prevent pooling of animals in loaded chunks.
PreventSpawningAnimals:
- Cow
- Horse
- Pig
- Sheep
- ChickenThis config skips squid, making their spawns vanilla (as long as your bukkit.yml file retains ticks-per.animal-spawns: 400` as a default value)
In new version of animal spawning, animals will only spawns in ranges defined below. You can define any amount of ranges. They should not overlap, and shouldn't go over the world boundaries.
Ranges:
-
StartChunk: 1
EndChunk: 3
Weight: 3
-
StartChunk: 4
EndChunk: 6
Weight: 2
-
StartChunk: 7
EndChunk: 9
Weight: 1StartChunk and EndChunk define start and end of chunk-ring, centered on 0 0.
Higher Weight will make one range be picked more often than usual. Detailed explanation + example below.
Picture represenents simplified version of config example above. (only one quarter of chunk-rings)
c - chunk count
w - weight (from config)
D - weighted chunk count
T - total sum of weighted chunk counts
R - weighted chunk range
Chunk count
c1 = 9
c2 = 27
c3 = 45
Weighted chunk count
Formula D = c * w
D1 = 9 * 3 = 27
D2 = 27 * 2 = 54
D3 = 45 * 1 = 45
Total
Formula T = sum(D)
T = 27 + 54 + 45 = 126
Ranges
R1 = 1..27
R2 = 28..81
R3 = 82..126
Randomizing chunk
- Get a random number from a range 1..T
- In sample case from 1 .. 126
- Let random r = 44
- Select a corresponding range R
- R2 in sample case
- Pick a random chunk in the area corresponding to selected range
- In sample case we pick a random chunk in area 2