From 6c715f65f60f1675f2cde15c25d5f73392c671a3 Mon Sep 17 00:00:00 2001 From: Rogier Date: Thu, 2 Apr 2015 13:27:10 +0200 Subject: [PATCH] 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...) --- nature_classic/global_function.lua | 12 +++--------- nature_classic/init.lua | 6 ++---- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/nature_classic/global_function.lua b/nature_classic/global_function.lua index d0806b1..3a5b9e3 100644 --- a/nature_classic/global_function.lua +++ b/nature_classic/global_function.lua @@ -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) diff --git a/nature_classic/init.lua b/nature_classic/init.lua index 31b5f7e..5143eb4 100644 --- a/nature_classic/init.lua +++ b/nature_classic/init.lua @@ -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..")"