summaryrefslogtreecommitdiff
path: root/mesecons_delayer
diff options
context:
space:
mode:
Diffstat (limited to 'mesecons_delayer')
-rw-r--r--mesecons_delayer/init.lua98
1 files changed, 40 insertions, 58 deletions
diff --git a/mesecons_delayer/init.lua b/mesecons_delayer/init.lua
index 6bdb72d..f70629a 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,8 +173,16 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
effector =
{
rules = delayer_get_input_rules,
- action_change = delayer_update
+ action_off = delayer_deactivate
}
}
})
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"},
+ }
+})