-
Notifications
You must be signed in to change notification settings - Fork 82
Biome Rarity
There are two separate ways of calculating biome rarity, and some differences between 1.12.2 and 1.16.5.
BiomeRarity and IsleBiomeRarity are very different. IsleBiomeRarity is calculated as nextInt((scale + 1) - biomeRarity) == 0, where nextInt fetches a random integer between 0 and the number in parentheses. As an example, nextInt(15) will give any number from 0, up to and including 14.
This means that with a biome rarity scale of 100 and a biome with rarity 100, nextInt() fetches a number between 0 and 1 (not including 1), giving IsleBiomeRarity 100 a 100% chance to spawn. An IsleBiomeRarity of 99 will result in nextInt(101-99) == 0 where the possible values from nextInt are 0 and 1, meaning the chance of getting 0 is one in two, or 50%. This continues all the way down to 1, where the calculation is nextInt(100) == 0 which gives the biome a 1/100 chance to spawn, or 1%. This is unique to IsleBiomeRarity, and is not how it works for normal BiomeRarity.
Normal BiomeRarity is instead cumulative for the whole biome group. This is best illustrated with an example. Consider the following biome group: BiomeGroup(0, 100, Forest, Plains, Desert) Where Forest has size 1, rarity 50, Plains has size 1, rarity 30, and Desert has size 2, rarity 90
Normal biome rarities are additive, and compared against the total of all biome rarities in current or subsequent depths. The first is called a cumulative rarity, the latter is called the max rarity.
At generation depth 1, the group has a max rarity of 50 + 30 + 90 = 170. Forest has cumulative rarity 50, and Plains comes after Forest so it is stored with cumulative rarity 50+30 = 80.
When OTG tries to place a biome from the group, it first gets a random number between 0 and max rarity. In this case, that's between 0 and 170. It then compares that number to the first number in the list, which is the cumulative rarity of Forest at 50. If the random number is lower than 50, OTG spawns Forest and moves on.
If the random number is greater than 50, it then compares it to the cumulative rarity of Plains, which is 80. If the random number is less than 80, OTG spawns plains. Otherwise, it spawns nothing and returns an empty cell.
That cell remains empty until depth 2. Here, the max rarity is simply 90, as is the cumulative rarity of Desert. Plains and Forest have already been spawned, so they don't get used in the equation. As every random number generated will be less than 90, desert will spawn in every open cell available in the biome group and fill it completely.
This worked slightly differently in 1.12 - there, if you placed a size 3 biome before a size 2 biome in the biomegroup, the size 3 wouldn't spawn and the size 2 would have that biome's rarity added to its own, making it far more likely to spawn. This has been changed and will no longer happen as of 1.16.5.
TODO: Add pictures to illustrate what is happening