Added rarity_fertility which means rarity can be affected by fertility level.

Rarity can now be a fraction.

A rarity of 100 (with rarity_fertility of 0) means the object will never appear, and a rarity of 0 means it will always appear.
This commit is contained in:
Jordan Leppert 2021-12-15 10:52:38 +00:00
parent b2e078d127
commit c8e51c8ee2
2 changed files with 12 additions and 3 deletions

View File

@ -250,7 +250,11 @@ biome = {
-- skipped. Avoid using excessively large radii.
rarity = num, -- How rare should this object be in its biome? Larger
-- values make objects more rare, via:
-- math.random(1,100) > this
-- math.random() * 100 > this
rarity_fertility -- The amount that the rarity is reduced by fertility.
= num, -- This makes the rarity field the upper bound for
-- rarity, and (rarity - rarity_fertility) the lower
-- bound. Defaults to 0.
max_count = num, -- The absolute maximum number of your object that
-- should be allowed to spawn in a 5x5x5 mapblock area
-- (80x80x80 nodes). Defaults to 5, but be sure you

View File

@ -73,6 +73,7 @@ function biome_lib.set_defaults(biome)
biome.near_nodes_size = biome.near_nodes_size or 0
biome.near_nodes_count = biome.near_nodes_count or 1
biome.rarity = biome.rarity or 50
biome.rarity_fertility = biome.rarity_fertility or 0
biome.max_count = biome.max_count or 125
biome.tries = biome.tries or 2
if biome.check_air ~= false then biome.check_air = true end
@ -183,14 +184,18 @@ end
local function populate_single_surface(biome, pos, perlin_fertile_area, checkair)
local p_top = { x = pos.x, y = pos.y + 1, z = pos.z }
if math.random(1, 100) <= biome.rarity then
if biome.rarity - biome.rarity_fertility == 100 then
return
end
local fertility, temperature, humidity = get_biome_data(pos, perlin_fertile_area)
if math.random() * 100 <= (biome.rarity - ((fertility + 1) / 2 * biome.rarity_fertility)) then
return
end
local pos_biome_ok = pos.y >= biome.min_elevation and pos.y <= biome.max_elevation
and fertility > biome.plantlife_limit
and fertility >= biome.plantlife_limit
and temperature <= biome.temp_min and temperature >= biome.temp_max
and humidity <= biome.humidity_min and humidity >= biome.humidity_max