1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-07-03 00:20:25 +02:00

Updated plantlife

- Added `if` statements to avoid populating areas when lag is too high
This commit is contained in:
LeMagnesium
2015-02-09 18:20:35 +01:00
parent 6237c70e77
commit 47bf36a8c3
5 changed files with 80 additions and 54 deletions

View File

@ -1,20 +1,35 @@
local NODE_YOUNG = "young"
-- helper functions
local SETTING_TRUE = "true"
local SETTING_FALSE = "false"
minetest.register_globalstep(function(dtime)
nature.dtime = dtime
if #nature.blossomqueue > 0 and dtime < 0.2 then
local pos = nature.blossomqueue[1][1]
local node = nature.blossomqueue[1][2]
if (nature.blossomqueue[1][3] and not nature:is_near_water(pos)) then
table.remove(nature.blossomqueue, 1) -- don't grow if it's not near water, pop from queue.
return
end
nature:grow_node(pos, nature.blossom_node) -- now actually grow it.
table.remove(nature.blossomqueue, 1)
end
end)
local YOUTH_DELAY = 5
nature = {}
function nature.enqueue_node(pos, node, fcn)
local idx = #nature.blossomqueue
nature.blossomqueue[idx+1] = {}
nature.blossomqueue[idx+1][1] = pos
nature.blossomqueue[idx+1][2] = node
nature.blossomqueue[idx+1][3] = fcn
end
local function set_young_node(pos)
local meta = minetest.get_meta(pos)
meta:set_string(NODE_YOUNG, SETTING_TRUE)
minetest.after(YOUTH_DELAY,
meta:set_string(nature.node_young, nature.setting_true)
minetest.after(nature.youth_delay,
function(pos)
local meta = minetest.get_meta(pos)
meta:set_string(NODE_YOUNG, SETTING_FALSE)
meta:set_string(nature.node_young, nature.setting_false)
end,
pos)
end
@ -22,14 +37,14 @@ end
local function is_not_young(pos)
local meta = minetest.get_meta(pos)
local young = meta:get_string(NODE_YOUNG)
return young ~= SETTING_TRUE
local young = meta:get_string(nature.node_young)
return young ~= nature.setting_true
end
function nature:grow_node(pos, nodename)
if pos ~= nil then
local light_enough = minetest.get_node_light(pos, nil)
>= MINIMUM_GROWTH_LIGHT
>= nature.minimum_growth_light
if is_not_young(pos) and light_enough then
minetest.remove_node(pos)
@ -43,6 +58,6 @@ function nature:grow_node(pos, nodename)
end
function nature:is_near_water(pos)
return DISTANCE_FROM_WATER == -1 or minetest.find_node_near(pos, DISTANCE_FROM_WATER,
return nature.distance_from_water == -1 or minetest.find_node_near(pos, nature.distance_from_water,
{ "default:water_source" }) ~= nil
end