forked from mtcontrib/plantlife_modpack
Fix timer bug causing persistent blossoms
Because minetest.after() is not bound to a position, and because it is not saved, it may trigger after the node to which it applies was unloaded, or not at all (if the session ends). If that happens, The 'young' flag will not be cleared, and will have become persistent (i.e. without a timer which will eventually clear it). This patch removes the 'young' flag, and replaces it with a timestamp, removing the need for a timer. Any lingering 'young' flags that have become persistent are automatically removed over time (i.e.: they are simply ignored...)
This commit is contained in:
parent
aaa4186695
commit
6c715f65f6
@ -51,20 +51,14 @@ end
|
||||
local function set_young_node(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
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(nature.node_young, nature.setting_false)
|
||||
end,
|
||||
pos)
|
||||
meta:set_int(nature.meta_blossom_time, minetest.get_gametime())
|
||||
end
|
||||
|
||||
local function is_not_young(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
local young = meta:get_string(nature.node_young)
|
||||
return young ~= nature.setting_true
|
||||
local blossom_time = meta:get_int(nature.meta_blossom_time)
|
||||
return not (blossom_time and minetest.get_gametime() - blossom_time < nature.blossom_duration)
|
||||
end
|
||||
|
||||
function nature:grow_node(pos, nodename)
|
||||
|
@ -26,10 +26,8 @@ nature.blossom_delay = 3600
|
||||
nature.apple_chance = 10
|
||||
nature.apple_spread = 2
|
||||
|
||||
nature.node_young = "young"
|
||||
nature.setting_true = "true"
|
||||
nature.setting_false = "false"
|
||||
nature.youth_delay = 5
|
||||
nature.meta_blossom_time = "blossom_time"
|
||||
nature.blossom_duration = 5
|
||||
|
||||
function dumppos(pos)
|
||||
return "("..pos.x..","..pos.y..","..pos.z..")"
|
||||
|
Loading…
Reference in New Issue
Block a user