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 function set_young_node(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
meta:set_string(nature.node_young, nature.setting_true)
|
meta:set_int(nature.meta_blossom_time, minetest.get_gametime())
|
||||||
minetest.after(nature.youth_delay,
|
|
||||||
function(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string(nature.node_young, nature.setting_false)
|
|
||||||
end,
|
|
||||||
pos)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function is_not_young(pos)
|
local function is_not_young(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
local young = meta:get_string(nature.node_young)
|
local blossom_time = meta:get_int(nature.meta_blossom_time)
|
||||||
return young ~= nature.setting_true
|
return not (blossom_time and minetest.get_gametime() - blossom_time < nature.blossom_duration)
|
||||||
end
|
end
|
||||||
|
|
||||||
function nature:grow_node(pos, nodename)
|
function nature:grow_node(pos, nodename)
|
||||||
|
@ -26,10 +26,8 @@ nature.blossom_delay = 3600
|
|||||||
nature.apple_chance = 10
|
nature.apple_chance = 10
|
||||||
nature.apple_spread = 2
|
nature.apple_spread = 2
|
||||||
|
|
||||||
nature.node_young = "young"
|
nature.meta_blossom_time = "blossom_time"
|
||||||
nature.setting_true = "true"
|
nature.blossom_duration = 5
|
||||||
nature.setting_false = "false"
|
|
||||||
nature.youth_delay = 5
|
|
||||||
|
|
||||||
function dumppos(pos)
|
function dumppos(pos)
|
||||||
return "("..pos.x..","..pos.y..","..pos.z..")"
|
return "("..pos.x..","..pos.y..","..pos.z..")"
|
||||||
|
Loading…
Reference in New Issue
Block a user