mirror of
https://github.com/minetest-mods/digtron.git
synced 2025-01-03 09:37:27 +01:00
Fix rotation and controller being single-use
This commit is contained in:
parent
c6611fdede
commit
972b6919dc
@ -35,13 +35,25 @@ minetest.register_node("digtron:axle", {
|
|||||||
{-0.25, -0.3125, -0.25, 0.25, 0.3125, 0.25}, -- Axle
|
{-0.25, -0.3125, -0.25, 0.25, 0.3125, 0.25}, -- Axle
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
local meta = minetest.get_meta(pos)
|
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.
|
-- Been too soon since last time the digtron rotated.
|
||||||
|
|
||||||
|
-- added for clarity
|
||||||
|
meta:set_string("infotext", S("repetition delay"))
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local image = DigtronLayout.create(pos, clicker)
|
local image = DigtronLayout.create(pos, clicker)
|
||||||
if image:rotate_layout_image(node.param2) == false then
|
if image:rotate_layout_image(node.param2) == false then
|
||||||
-- This should be impossible, but if self-validation fails abort.
|
-- 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 = minetest.get_meta(pos)
|
||||||
meta:set_string("waiting", "true")
|
meta:set_string("waiting", "true")
|
||||||
meta:set_string("infotext", nil)
|
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
|
else
|
||||||
meta:set_string("infotext", "unrecoverable write_layout_image error")
|
meta:set_string("infotext", "unrecoverable write_layout_image error")
|
||||||
end
|
end
|
||||||
|
@ -54,9 +54,19 @@ minetest.register_node("digtron:controller", {
|
|||||||
|
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if meta:get_string("waiting") == "true" then
|
|
||||||
-- Been too soon since last time the digtron did a cycle.
|
-- new delay code without nodetimer (lost on crating)
|
||||||
return
|
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
|
end
|
||||||
|
|
||||||
local newpos, status, return_code = digtron.execute_dig_cycle(pos, clicker)
|
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.
|
-- Start the delay before digtron can run again.
|
||||||
minetest.get_meta(newpos):set_string("waiting", "true")
|
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,
|
end,
|
||||||
|
|
||||||
on_timer = function(pos, elapsed)
|
on_timer = function(pos, elapsed)
|
||||||
|
Loading…
Reference in New Issue
Block a user