From 7fe4947056656982ee9af9fad8d67d14e7086c9a Mon Sep 17 00:00:00 2001 From: Jeija Date: Thu, 27 Dec 2012 09:28:04 +0100 Subject: Bugfix foes for pistons, delayyrs, gates and microcontrollers. Rework delayers. --- mesecons_delayer/init.lua | 90 +++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 58 deletions(-) (limited to 'mesecons_delayer/init.lua') diff --git a/mesecons_delayer/init.lua b/mesecons_delayer/init.lua index 6bdb72d..2175c3c 100644 --- a/mesecons_delayer/init.lua +++ b/mesecons_delayer/init.lua @@ -1,28 +1,16 @@ -- Function that get the input/output rules of the delayer local delayer_get_output_rules = function(node) - local rules = {} - if node.param2 == 0 then - table.insert(rules, {x = 1, y = 0, z = 0}) - elseif node.param2 == 2 then - table.insert(rules, {x =-1, y = 0, z = 0}) - elseif node.param2 == 1 then - table.insert(rules, {x = 0, y = 0, z =-1}) - elseif node.param2 == 3 then - table.insert(rules, {x = 0, y = 0, z = 1}) + local rules = {{x = 0, y = 0, z = 1}} + for i = 0, node.param2 do + rules = mesecon:rotate_rules_left(rules) end return rules end local delayer_get_input_rules = function(node) - local rules = {} - if node.param2 == 0 then - table.insert(rules, {x =-1, y = 0, z = 0}) - elseif node.param2 == 2 then - table.insert(rules, {x = 1, y = 0, z = 0}) - elseif node.param2 == 1 then - table.insert(rules, {x = 0, y = 0, z = 1}) - elseif node.param2 == 3 then - table.insert(rules, {x = 0, y = 0, z =-1}) + local rules = {{x = 0, y = 0, z = -1}} + for i = 0, node.param2 do + rules = mesecon:rotate_rules_left(rules) end return rules end @@ -30,54 +18,30 @@ end -- Functions that are called after the delay time local delayer_turnon = function(params) - local rules = delayer_get_output_rules(params) + local rules = delayer_get_output_rules(params.node) mesecon:receptor_on(params.pos, rules) end local delayer_turnoff = function(params) - local rules = delayer_get_output_rules(params) + local rules = delayer_get_output_rules(params.node) mesecon:receptor_off(params.pos, rules) end -local delayer_update = function(pos, node) - if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then - local time = 0 - if node.name=="mesecons_delayer:delayer_off_1" then - mesecon:swap_node(pos, "mesecons_delayer:delayer_on_1") - time=0.1 - elseif node.name=="mesecons_delayer:delayer_off_2" then - mesecon:swap_node(pos, "mesecons_delayer:delayer_on_2") - time=0.3 - elseif node.name=="mesecons_delayer:delayer_off_3" then - mesecon:swap_node(pos, "mesecons_delayer:delayer_on_3") - time=0.5 - elseif node.name=="mesecons_delayer:delayer_off_4" then - mesecon:swap_node(pos, "mesecons_delayer:delayer_on_4") - time=1 - end - minetest.after(time, delayer_turnon, {pos=pos, param2=node.param2}) - end +local delayer_activate = function(pos, node) + local def = minetest.registered_nodes[node.name] + local time = def.delayer_time + mesecon:swap_node(pos, def.delayer_onstate) + minetest.after(time, delayer_turnon , {pos = pos, node = node}) +end - if string.find(node.name, "mesecons_delayer:delayer_on")~=nil then - local time = 0 - if node.name=="mesecons_delayer:delayer_on_1" then - mesecon:swap_node(pos, "mesecons_delayer:delayer_off_1") - time=0.1 - elseif node.name=="mesecons_delayer:delayer_on_2" then - mesecon:swap_node(pos, "mesecons_delayer:delayer_off_2") - time=0.3 - elseif node.name=="mesecons_delayer:delayer_on_3" then - mesecon:swap_node(pos, "mesecons_delayer:delayer_off_3") - time=0.5 - elseif node.name=="mesecons_delayer:delayer_on_4" then - mesecon:swap_node(pos, "mesecons_delayer:delayer_off_4") - time=1 - end - minetest.after(time, delayer_turnoff, {pos=pos, param2=node.param2}) - end +local delayer_deactivate = function(pos, node) + local def = minetest.registered_nodes[node.name] + local time = def.delayer_time + mesecon:swap_node(pos, def.delayer_offstate) + minetest.after(time, delayer_turnoff, {pos = pos, node = node}) end ---Actually register the 2 (states) x 4 (delay times) delayers +-- Register the 2 (states) x 4 (delay times) delayers for i = 1, 4 do local groups = {} @@ -87,6 +51,12 @@ else groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1} end +local delaytime +if i == 1 then delaytime = 0.1 +elseif i == 2 then delaytime = 0.3 +elseif i == 3 then delaytime = 0.5 +elseif i == 4 then delaytime = 1.0 end + boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab { -2/16, -7/16, -4/16, 2/16, -26/64, -3/16 }, -- the jeweled "on" indicator @@ -138,6 +108,8 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), { mesecon:swap_node(pos,"mesecons_delayer:delayer_off_1") end end, + delayer_time = delaytime, + delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i), mesecons = { receptor = { @@ -147,7 +119,7 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), { effector = { rules = delayer_get_input_rules, - action_change = delayer_update + action_on = delayer_activate } } }) @@ -190,6 +162,8 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), { mesecon:swap_node(pos,"mesecons_delayer:delayer_on_1") end end, + delayer_time = delaytime, + delayer_offstate = "mesecons_delayer:delayer_off_"..tostring(i), mesecons = { receptor = { @@ -199,7 +173,7 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), { effector = { rules = delayer_get_input_rules, - action_change = delayer_update + action_off = delayer_deactivate } } }) -- cgit v1.2.3 From 52ddd4bdc931a1f806ea581002b0f39ba83158bc Mon Sep 17 00:00:00 2001 From: Jeija Date: Sun, 30 Dec 2012 09:07:49 +0100 Subject: Add crafting recipe for the delayer (similar to redstone, but with cobble instead of stone) --- mesecons_delayer/init.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'mesecons_delayer/init.lua') diff --git a/mesecons_delayer/init.lua b/mesecons_delayer/init.lua index 2175c3c..f70629a 100644 --- a/mesecons_delayer/init.lua +++ b/mesecons_delayer/init.lua @@ -178,3 +178,11 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), { } }) end + +minetest.register_craft({ + output = "mesecons_delayer:delayer_off_1", + recipe = { + {"mesecons_torch:mesecon_torch_on", "group:mesecon_conductor_craftable", "mesecons_torch:mesecon_torch_on"}, + {"default:cobble","default:cobble", "default:cobble"}, + } +}) -- cgit v1.2.3