2012-08-10 21:50:07 +02:00
|
|
|
for i = 1, 4 do
|
|
|
|
local groups = {}
|
|
|
|
if i == 1 then
|
2012-08-13 16:49:14 +02:00
|
|
|
groups = {bendy=2,snappy=1,dig_immediate=2, mesecon = 3}
|
2012-08-10 21:50:07 +02:00
|
|
|
else
|
2012-08-13 16:49:14 +02:00
|
|
|
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}
|
2012-08-10 21:50:07 +02:00
|
|
|
end
|
|
|
|
|
2012-08-12 02:20:50 +02:00
|
|
|
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
|
|
|
|
{ -3/16, -7/16, -3/16, 3/16, -26/64, -2/16 },
|
|
|
|
{ -4/16, -7/16, -2/16, 4/16, -26/64, 2/16 },
|
|
|
|
{ -3/16, -7/16, 2/16, 3/16, -26/64, 3/16 },
|
|
|
|
{ -2/16, -7/16, 3/16, 2/16, -26/64, 4/16 },
|
|
|
|
|
|
|
|
{ -6/16, -7/16, -6/16, -4/16, -27/64, -4/16 }, -- the timer indicator
|
|
|
|
{ -8/16, -8/16, -1/16, -6/16, -7/16, 1/16 }, -- the two wire stubs
|
|
|
|
{ 6/16, -8/16, -1/16, 8/16, -7/16, 1/16 }}
|
|
|
|
|
2012-08-10 21:50:07 +02:00
|
|
|
minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
|
2012-03-29 22:11:17 +02:00
|
|
|
description = "Delayer",
|
2012-06-21 20:33:01 +02:00
|
|
|
drawtype = "nodebox",
|
2012-08-07 09:40:04 +02:00
|
|
|
tiles = {
|
2012-08-10 21:50:07 +02:00
|
|
|
"mesecons_delayer_off_"..tostring(i)..".png",
|
2012-08-12 02:53:47 +02:00
|
|
|
"mesecons_delayer_bottom.png",
|
2012-08-12 02:20:50 +02:00
|
|
|
"mesecons_delayer_ends_off.png",
|
|
|
|
"mesecons_delayer_ends_off.png",
|
|
|
|
"mesecons_delayer_sides_off.png",
|
|
|
|
"mesecons_delayer_sides_off.png"
|
2012-08-07 09:40:04 +02:00
|
|
|
},
|
2012-03-29 22:11:17 +02:00
|
|
|
inventory_image = "mesecons_delayer_off_1.png",
|
2012-04-02 08:41:27 +02:00
|
|
|
wield_image = "mesecons_delayer_off_1.png",
|
2012-08-10 21:50:07 +02:00
|
|
|
walkable = true,
|
2012-06-21 20:33:01 +02:00
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2012-08-12 02:20:50 +02:00
|
|
|
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
|
2012-06-21 20:33:01 +02:00
|
|
|
},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
2012-08-12 02:20:50 +02:00
|
|
|
fixed = boxes
|
2012-06-21 20:33:01 +02:00
|
|
|
},
|
2012-08-10 21:50:07 +02:00
|
|
|
groups = groups,
|
2012-03-29 22:11:17 +02:00
|
|
|
paramtype = "light",
|
2012-06-21 20:33:01 +02:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
is_ground_content = true,
|
2012-03-29 22:11:17 +02:00
|
|
|
drop = 'mesecons_delayer:delayer_off_1',
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2012-08-10 21:50:07 +02:00
|
|
|
minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
|
|
|
|
description = "You hacker you",
|
2012-06-21 20:33:01 +02:00
|
|
|
drawtype = "nodebox",
|
2012-08-07 09:40:04 +02:00
|
|
|
tiles = {
|
2012-08-10 21:50:07 +02:00
|
|
|
"mesecons_delayer_on_"..tostring(i)..".png",
|
2012-08-12 02:20:50 +02:00
|
|
|
"mesecons_delayer_bottom.png",
|
|
|
|
"mesecons_delayer_ends_on.png",
|
|
|
|
"mesecons_delayer_ends_on.png",
|
|
|
|
"mesecons_delayer_sides_on.png",
|
|
|
|
"mesecons_delayer_sides_on.png"
|
2012-08-07 09:40:04 +02:00
|
|
|
},
|
2012-08-10 21:50:07 +02:00
|
|
|
walkable = true,
|
2012-06-21 20:33:01 +02:00
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2012-08-12 02:20:50 +02:00
|
|
|
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
|
2012-06-21 20:33:01 +02:00
|
|
|
},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
2012-08-12 02:20:50 +02:00
|
|
|
fixed = boxes
|
2012-06-21 20:33:01 +02:00
|
|
|
},
|
2012-08-13 16:49:14 +02:00
|
|
|
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 3},
|
2012-03-29 22:11:17 +02:00
|
|
|
paramtype = "light",
|
2012-06-21 20:33:01 +02:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
is_ground_content = true,
|
2012-03-29 22:11:17 +02:00
|
|
|
drop = 'mesecons_delayer:delayer_off_1',
|
|
|
|
})
|
2012-08-10 21:50:07 +02:00
|
|
|
end
|
2012-03-29 22:11:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_punchnode(function (pos, node)
|
2012-08-10 22:58:48 +02:00
|
|
|
mesecon.delayer_get_output_rules(node.param2)
|
2012-03-29 22:11:17 +02:00
|
|
|
if node.name=="mesecons_delayer:delayer_off_1" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2", param2=node.param2})
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_off_2" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3", param2=node.param2})
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_off_3" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4", param2=node.param2})
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_off_4" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2})
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_punchnode(function (pos, node)
|
2012-08-10 22:58:48 +02:00
|
|
|
mesecon.delayer_get_output_rules(node.param2)
|
2012-03-29 22:11:17 +02:00
|
|
|
if node.name=="mesecons_delayer:delayer_on_1" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2", param2=node.param2})
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_on_2" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3", param2=node.param2})
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_on_3" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4", param2=node.param2})
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_on_4" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2})
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2012-08-12 21:28:53 +02:00
|
|
|
mesecon.delayer_update = function(pos, node)
|
2012-03-29 22:11:17 +02:00
|
|
|
if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then
|
2012-08-12 21:28:53 +02:00
|
|
|
local input_rules = mesecon.delayer_get_input_rules(node.param2)[1]
|
|
|
|
np = {x = pos.x + input_rules.x, y = pos.y + input_rules.y, z = pos.z + input_rules.z}
|
2012-08-10 22:58:48 +02:00
|
|
|
|
|
|
|
if mesecon:is_power_on(np) then
|
2012-08-12 21:28:53 +02:00
|
|
|
local time = 0
|
2012-03-29 22:11:17 +02:00
|
|
|
if node.name=="mesecons_delayer:delayer_off_1" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2})
|
2012-04-06 20:03:12 +02:00
|
|
|
time=0.1
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_off_2" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2", param2=node.param2})
|
2012-04-06 20:03:12 +02:00
|
|
|
time=0.3
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_off_3" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3", param2=node.param2})
|
2012-04-06 20:03:12 +02:00
|
|
|
time=0.5
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_off_4" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4", param2=node.param2})
|
2012-04-06 20:03:12 +02:00
|
|
|
time=1
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.after(time, mesecon.delayer_turnon, {pos=pos, param2=node.param2})
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
end
|
2012-08-12 21:28:53 +02:00
|
|
|
|
2012-03-29 22:11:17 +02:00
|
|
|
if string.find(node.name, "mesecons_delayer:delayer_on")~=nil then
|
2012-08-12 21:28:53 +02:00
|
|
|
local input_rules = mesecon.delayer_get_input_rules(node.param2)[1]
|
|
|
|
np = {x = pos.x + input_rules.x, y = pos.y + input_rules.y, z = pos.z + input_rules.z}
|
2012-08-10 22:58:48 +02:00
|
|
|
|
|
|
|
if not mesecon:is_power_on(np) then
|
2012-08-12 21:28:53 +02:00
|
|
|
local time = 0
|
2012-03-29 22:11:17 +02:00
|
|
|
if node.name=="mesecons_delayer:delayer_on_1" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2})
|
2012-04-06 20:03:12 +02:00
|
|
|
time=0.1
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_on_2" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2", param2=node.param2})
|
2012-04-06 20:03:12 +02:00
|
|
|
time=0.3
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_on_3" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3", param2=node.param2})
|
2012-04-06 20:03:12 +02:00
|
|
|
time=0.5
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
if node.name=="mesecons_delayer:delayer_on_4" then
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4", param2=node.param2})
|
2012-04-06 20:03:12 +02:00
|
|
|
time=1
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
2012-08-10 22:58:48 +02:00
|
|
|
minetest.after(time, mesecon.delayer_turnoff, {pos=pos, param2=node.param2})
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-12 21:28:53 +02:00
|
|
|
mesecon:register_on_signal_change(mesecon.delayer_update)
|
2012-03-29 22:11:17 +02:00
|
|
|
|
|
|
|
mesecon.delayer_turnon=function(params)
|
2012-08-10 22:58:48 +02:00
|
|
|
local rules = mesecon.delayer_get_output_rules(params.param2)
|
|
|
|
mesecon:receptor_on(params.pos, rules)
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
mesecon.delayer_turnoff=function(params)
|
2012-08-10 22:58:48 +02:00
|
|
|
local rules = mesecon.delayer_get_output_rules(params.param2)
|
|
|
|
mesecon:receptor_off(params.pos, rules)
|
2012-03-29 22:11:17 +02:00
|
|
|
end
|
|
|
|
|
2012-08-10 22:58:48 +02:00
|
|
|
mesecon.delayer_get_output_rules = function(param2)
|
2012-08-12 21:28:53 +02:00
|
|
|
local rules = {}
|
2012-08-10 22:58:48 +02:00
|
|
|
if param2 == 0 then
|
|
|
|
table.insert(rules, {x = 1, y = 0, z = 0})
|
|
|
|
elseif param2 == 2 then
|
|
|
|
table.insert(rules, {x =-1, y = 0, z = 0})
|
|
|
|
elseif param2 == 1 then
|
|
|
|
table.insert(rules, {x = 0, y = 0, z =-1})
|
|
|
|
elseif param2 == 3 then
|
|
|
|
table.insert(rules, {x = 0, y = 0, z = 1})
|
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
|
|
|
|
|
|
|
mesecon.delayer_get_input_rules = function(param2)
|
2012-08-12 21:28:53 +02:00
|
|
|
local rules = {}
|
2012-08-10 22:58:48 +02:00
|
|
|
if param2 == 0 then
|
|
|
|
table.insert(rules, {x =-1, y = 0, z = 0})
|
|
|
|
elseif param2 == 2 then
|
|
|
|
table.insert(rules, {x = 1, y = 0, z = 0})
|
|
|
|
elseif param2 == 1 then
|
|
|
|
table.insert(rules, {x = 0, y = 0, z = 1})
|
|
|
|
elseif param2 == 3 then
|
|
|
|
table.insert(rules, {x = 0, y = 0, z =-1})
|
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
2012-03-29 22:11:17 +02:00
|
|
|
|
2012-08-12 21:28:53 +02:00
|
|
|
all_rules = {{x = 1, y = 0, z = 0}, {x =-1, y = 0, z = 0}, {x = 0, y = 0, z =-1}, {x = 0, y = 0, z = 1}} --required to check if a newly placed should be turned on
|
|
|
|
|
|
|
|
mesecon:add_receptor_node("mesecons_delayer:delayer_on_1", all_rules, mesecon.delayer_get_output_rules)
|
|
|
|
mesecon:add_receptor_node("mesecons_delayer:delayer_on_2", all_rules, mesecon.delayer_get_output_rules)
|
|
|
|
mesecon:add_receptor_node("mesecons_delayer:delayer_on_3", all_rules, mesecon.delayer_get_output_rules)
|
|
|
|
mesecon:add_receptor_node("mesecons_delayer:delayer_on_4", all_rules, mesecon.delayer_get_output_rules)
|
2012-03-29 22:11:17 +02:00
|
|
|
|
2012-08-12 21:28:53 +02:00
|
|
|
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_1", all_rules, mesecon.delayer_get_output_rules)
|
|
|
|
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_2", all_rules, mesecon.delayer_get_output_rules)
|
|
|
|
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_3", all_rules, mesecon.delayer_get_output_rules)
|
|
|
|
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_4", all_rules, mesecon.delayer_get_output_rules)
|
2012-08-13 16:49:14 +02:00
|
|
|
|
|
|
|
mesecon:register_effector("mesecons_delayer:delayer_on_1", "mesecons_delayer:delayer_off_1", all_rules, mesecon.delayer_get_input_rules)
|
|
|
|
mesecon:register_effector("mesecons_delayer:delayer_on_2", "mesecons_delayer:delayer_off_2", all_rules, mesecon.delayer_get_input_rules)
|
|
|
|
mesecon:register_effector("mesecons_delayer:delayer_on_3", "mesecons_delayer:delayer_off_3", all_rules, mesecon.delayer_get_input_rules)
|
|
|
|
mesecon:register_effector("mesecons_delayer:delayer_on_4", "mesecons_delayer:delayer_off_4", all_rules, mesecon.delayer_get_input_rules)
|