forked from mtcontrib/plantlife_modpack
Take time_speed into account
when setting spawning and growing ABM intervals. also, add some basic sanity checks to the interval value just in case the math comes out wrong. Rearranged a bit of code to accommodate these changes.
This commit is contained in:
parent
2c97d6e8a2
commit
f168f0acb2
@ -24,6 +24,13 @@ end
|
|||||||
|
|
||||||
local DEBUG = false --... except if you want to spam the console with debugging info :-)
|
local DEBUG = false --... except if you want to spam the console with debugging info :-)
|
||||||
|
|
||||||
|
function plantslib:dbg(msg)
|
||||||
|
if DEBUG then
|
||||||
|
print("[Plantlife] "..msg)
|
||||||
|
minetest.log("verbose", "[Plantlife] "..msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
plantslib.plantlife_seed_diff = 329 -- needs to be global so other mods can see it
|
plantslib.plantlife_seed_diff = 329 -- needs to be global so other mods can see it
|
||||||
|
|
||||||
local perlin_octaves = 3
|
local perlin_octaves = 3
|
||||||
@ -40,6 +47,16 @@ local humidity_octaves = 3
|
|||||||
local humidity_persistence = 0.5
|
local humidity_persistence = 0.5
|
||||||
local humidity_scale = 250
|
local humidity_scale = 250
|
||||||
|
|
||||||
|
local time_scale = 1
|
||||||
|
local time_speed = tonumber(minetest.setting_get("time_speed"))
|
||||||
|
|
||||||
|
if time_speed and time_speed > 0 then
|
||||||
|
time_scale = 72 / time_speed
|
||||||
|
end
|
||||||
|
|
||||||
|
plantslib:dbg("time_speed = "..dump(time_speed))
|
||||||
|
plantslib:dbg("time_scale = 72 / time_speed = "..dump(time_scale))
|
||||||
|
|
||||||
--PerlinNoise(seed, octaves, persistence, scale)
|
--PerlinNoise(seed, octaves, persistence, scale)
|
||||||
|
|
||||||
plantslib.perlin_temperature = PerlinNoise(temperature_seeddiff, temperature_octaves, temperature_persistence, temperature_scale)
|
plantslib.perlin_temperature = PerlinNoise(temperature_seeddiff, temperature_octaves, temperature_persistence, temperature_scale)
|
||||||
@ -68,13 +85,6 @@ function plantslib:clone_node(name)
|
|||||||
return node2
|
return node2
|
||||||
end
|
end
|
||||||
|
|
||||||
function plantslib:dbg(msg)
|
|
||||||
if DEBUG then
|
|
||||||
print("[Plantlife] "..msg)
|
|
||||||
minetest.log("verbose", "[Plantlife] "..msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function plantslib:set_defaults(biome)
|
function plantslib:set_defaults(biome)
|
||||||
biome.seed_diff = biome.seed_diff or 0
|
biome.seed_diff = biome.seed_diff or 0
|
||||||
biome.min_elevation = biome.min_elevation or -31000
|
biome.min_elevation = biome.min_elevation or -31000
|
||||||
@ -232,6 +242,12 @@ function plantslib:spawn_on_surfaces(sd,sp,sr,sc,ss,sa)
|
|||||||
biome = sd
|
biome = sd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if biome.spawn_delay*time_scale >= 1 then
|
||||||
|
biome.interval = biome.spawn_delay*time_scale
|
||||||
|
else
|
||||||
|
biome.interval = 1
|
||||||
|
end
|
||||||
|
|
||||||
plantslib:set_defaults(biome)
|
plantslib:set_defaults(biome)
|
||||||
biome.spawn_plants_count = table.getn(biome.spawn_plants)
|
biome.spawn_plants_count = table.getn(biome.spawn_plants)
|
||||||
|
|
||||||
@ -241,7 +257,7 @@ function plantslib:spawn_on_surfaces(sd,sp,sr,sc,ss,sa)
|
|||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = biome.spawn_surfaces,
|
nodenames = biome.spawn_surfaces,
|
||||||
interval = biome.spawn_delay,
|
interval = biome.interval,
|
||||||
chance = biome.spawn_chance,
|
chance = biome.spawn_chance,
|
||||||
neighbors = biome.neighbors,
|
neighbors = biome.neighbors,
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
@ -333,9 +349,15 @@ function plantslib:grow_plants(opts)
|
|||||||
plantslib:dbg("Registered growing ABM:")
|
plantslib:dbg("Registered growing ABM:")
|
||||||
plantslib:dbg(dump(options))
|
plantslib:dbg(dump(options))
|
||||||
|
|
||||||
|
if options.grow_delay*time_scale >= 1 then
|
||||||
|
options.interval = options.grow_delay*time_scale
|
||||||
|
else
|
||||||
|
options.interval = 1
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = { options.grow_plant },
|
nodenames = { options.grow_plant },
|
||||||
interval = options.grow_delay,
|
interval = options.interval,
|
||||||
chance = options.grow_chance,
|
chance = options.grow_chance,
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
local p_top = {x=pos.x, y=pos.y+1, z=pos.z}
|
local p_top = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||||
|
Loading…
Reference in New Issue
Block a user