mirror of
https://github.com/mt-mods/biome_lib.git
synced 2025-01-08 09:00:31 +01:00
register_on_generate: tries and rarity_fertility (#8)
* Can specify the number of tries when generating * 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:
parent
bd92dc1b0b
commit
932485a6fe
11
API.txt
11
API.txt
@ -250,12 +250,21 @@ 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
|
||||
-- set this to some reasonable value depending on your
|
||||
-- object and its size if 5 is insufficient.
|
||||
tries = num, -- the number of attempts that will be made to spawn
|
||||
-- an object, defaults to 2. This means if the first
|
||||
-- attempt fails due to something blocking the object
|
||||
-- for example, another attempt will be made in
|
||||
-- another random location.
|
||||
seed_diff = num, -- Perlin seed-diff value. Defaults to 0, which
|
||||
-- causes the function to inherit the global value of
|
||||
-- 329.
|
||||
|
12
api.lua
12
api.lua
@ -73,7 +73,9 @@ 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
|
||||
|
||||
-- specific to abm spawner
|
||||
@ -182,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
|
||||
|
||||
@ -286,7 +292,7 @@ function biome_lib.populate_surfaces(b, nodes_or_function_or_model, snodes, chec
|
||||
for i = 1, math.min(math.ceil(biome.max_count/25), num_in_biome_nodes) do
|
||||
local tries = 0
|
||||
local spawned = false
|
||||
while tries < 2 and not spawned do
|
||||
while tries < biome.tries and not spawned do
|
||||
local pos = in_biome_nodes[math.random(1, num_in_biome_nodes)]
|
||||
|
||||
local will_place = true
|
||||
|
Loading…
Reference in New Issue
Block a user