forked from mtcontrib/biome_lib
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:
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
|
||||
|
Reference in New Issue
Block a user