From 972b6919dcef70dcd03effabe5e5e628c8735ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Thu, 2 Apr 2020 21:48:28 +0200 Subject: [PATCH] Fix rotation and controller being single-use --- nodes/node_axle.lua | 18 ++++++++++++++++-- nodes/node_controllers.lua | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/nodes/node_axle.lua b/nodes/node_axle.lua index ac9ea2d..1ae9ecc 100644 --- a/nodes/node_axle.lua +++ b/nodes/node_axle.lua @@ -35,13 +35,25 @@ minetest.register_node("digtron:axle", { {-0.25, -0.3125, -0.25, 0.25, 0.3125, 0.25}, -- Axle } }, + + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local meta = minetest.get_meta(pos) - if meta:get_string("waiting") == "true" then + + -- new delay code without nodetimer (lost on crating) + local now = minetest.get_gametime() + local last_time = tonumber(meta:get_string("last_time")) or 0 + -- if meta:get_string("waiting") == "true" then + if last_time + digtron.config.cycle_time*2 > now then -- Been too soon since last time the digtron rotated. + + -- added for clarity + meta:set_string("infotext", S("repetition delay")) + return end + local image = DigtronLayout.create(pos, clicker) if image:rotate_layout_image(node.param2) == false then -- This should be impossible, but if self-validation fails abort. @@ -53,7 +65,9 @@ minetest.register_node("digtron:axle", { meta = minetest.get_meta(pos) meta:set_string("waiting", "true") meta:set_string("infotext", nil) - minetest.get_node_timer(pos):start(digtron.config.cycle_time*2) + -- minetest.get_node_timer(pos):start(digtron.config.cycle_time*2) + -- new delay code + meta:set_string("last_time",tostring(minetest.get_gametime())) else meta:set_string("infotext", "unrecoverable write_layout_image error") end diff --git a/nodes/node_controllers.lua b/nodes/node_controllers.lua index 5c9a839..8e20919 100644 --- a/nodes/node_controllers.lua +++ b/nodes/node_controllers.lua @@ -54,9 +54,19 @@ minetest.register_node("digtron:controller", { on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local meta = minetest.get_meta(pos) - if meta:get_string("waiting") == "true" then - -- Been too soon since last time the digtron did a cycle. - return + + -- new delay code without nodetimer (lost on crating) + local now = minetest.get_gametime() + local last_time = (tonumber(meta:get_string("last_time")) or 0 ) + + -- if meta:get_string("waiting") == "true" then + if last_time + digtron.config.cycle_time > now then + -- Been too soon since last time the digtron did a cycle. + + -- added for clarity + meta:set_string("infotext", S("repetition delay")) + + return end local newpos, status, return_code = digtron.execute_dig_cycle(pos, clicker) @@ -68,7 +78,9 @@ minetest.register_node("digtron:controller", { -- Start the delay before digtron can run again. minetest.get_meta(newpos):set_string("waiting", "true") - minetest.get_node_timer(newpos):start(digtron.config.cycle_time) + -- minetest.get_node_timer(newpos):start(digtron.config.cycle_time) + -- new delay code + meta:set_string("last_time",tostring(minetest.get_gametime())) end, on_timer = function(pos, elapsed)