2012-12-08 21:56:09 +01:00
|
|
|
-- Function that get the input/output rules of the delayer
|
|
|
|
local delayer_get_output_rules = function(node)
|
2012-12-27 09:28:04 +01:00
|
|
|
local rules = {{x = 0, y = 0, z = 1}}
|
|
|
|
for i = 0, node.param2 do
|
2014-11-22 15:42:22 +01:00
|
|
|
rules = mesecon.rotate_rules_left(rules)
|
2012-12-08 21:56:09 +01:00
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
|
|
|
|
|
|
|
local delayer_get_input_rules = function(node)
|
2012-12-27 09:28:04 +01:00
|
|
|
local rules = {{x = 0, y = 0, z = -1}}
|
|
|
|
for i = 0, node.param2 do
|
2014-11-22 15:42:22 +01:00
|
|
|
rules = mesecon.rotate_rules_left(rules)
|
2012-12-08 21:56:09 +01:00
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Functions that are called after the delay time
|
|
|
|
|
2012-12-27 09:28:04 +01:00
|
|
|
local delayer_activate = function(pos, node)
|
|
|
|
local def = minetest.registered_nodes[node.name]
|
|
|
|
local time = def.delayer_time
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = def.delayer_onstate, param2=node.param2})
|
2014-03-23 09:28:20 +01:00
|
|
|
mesecon.queue:add_action(pos, "receptor_on", {delayer_get_output_rules(node)}, time, nil)
|
2012-12-27 09:28:04 +01:00
|
|
|
end
|
2012-12-08 21:56:09 +01:00
|
|
|
|
2012-12-27 09:28:04 +01:00
|
|
|
local delayer_deactivate = function(pos, node)
|
|
|
|
local def = minetest.registered_nodes[node.name]
|
|
|
|
local time = def.delayer_time
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = def.delayer_offstate, param2=node.param2})
|
2014-03-23 09:28:20 +01:00
|
|
|
mesecon.queue:add_action(pos, "receptor_off", {delayer_get_output_rules(node)}, time, nil)
|
2012-12-08 21:56:09 +01:00
|
|
|
end
|
|
|
|
|
2012-12-27 09:28:04 +01:00
|
|
|
-- Register the 2 (states) x 4 (delay times) delayers
|
2012-12-08 21:56:09 +01:00
|
|
|
|
2012-08-10 21:50:07 +02:00
|
|
|
for i = 1, 4 do
|
|
|
|
local groups = {}
|
2015-10-04 13:30:34 +02:00
|
|
|
if i == 1 then
|
2012-12-08 21:56:09 +01:00
|
|
|
groups = {bendy=2,snappy=1,dig_immediate=2}
|
2012-08-10 21:50:07 +02:00
|
|
|
else
|
2012-12-08 21:56:09 +01:00
|
|
|
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1}
|
2012-08-10 21:50:07 +02:00
|
|
|
end
|
|
|
|
|
2012-12-27 09:28:04 +01:00
|
|
|
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
|
|
|
|
|
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-12-08 21:56:09 +01:00
|
|
|
on_punch = function (pos, node)
|
|
|
|
if node.name=="mesecons_delayer:delayer_off_1" then
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_2", param2=node.param2})
|
2012-12-08 21:56:09 +01:00
|
|
|
elseif node.name=="mesecons_delayer:delayer_off_2" then
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_3", param2=node.param2})
|
2012-12-08 21:56:09 +01:00
|
|
|
elseif node.name=="mesecons_delayer:delayer_off_3" then
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_4", param2=node.param2})
|
2012-12-08 21:56:09 +01:00
|
|
|
elseif node.name=="mesecons_delayer:delayer_off_4" then
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_1", param2=node.param2})
|
2012-12-08 21:56:09 +01:00
|
|
|
end
|
|
|
|
end,
|
2012-12-27 09:28:04 +01:00
|
|
|
delayer_time = delaytime,
|
|
|
|
delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i),
|
2013-03-07 02:51:57 +01:00
|
|
|
sounds = default.node_sound_stone_defaults(),
|
2012-12-08 21:56:09 +01:00
|
|
|
mesecons = {
|
|
|
|
receptor =
|
|
|
|
{
|
|
|
|
state = mesecon.state.off,
|
|
|
|
rules = delayer_get_output_rules
|
|
|
|
},
|
|
|
|
effector =
|
|
|
|
{
|
|
|
|
rules = delayer_get_input_rules,
|
2012-12-27 09:28:04 +01:00
|
|
|
action_on = delayer_activate
|
2012-12-08 21:56:09 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-29 22:11:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
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-12-08 21:56:09 +01:00
|
|
|
groups = {bendy = 2, snappy = 1, dig_immediate = 2, not_in_creative_inventory = 1},
|
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-12-08 21:56:09 +01:00
|
|
|
on_punch = function (pos, node)
|
2012-08-13 20:17:45 +02:00
|
|
|
if node.name=="mesecons_delayer:delayer_on_1" then
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_2", param2=node.param2})
|
2012-12-08 21:56:09 +01:00
|
|
|
elseif node.name=="mesecons_delayer:delayer_on_2" then
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_3", param2=node.param2})
|
2012-12-08 21:56:09 +01:00
|
|
|
elseif node.name=="mesecons_delayer:delayer_on_3" then
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_4", param2=node.param2})
|
2012-12-08 21:56:09 +01:00
|
|
|
elseif node.name=="mesecons_delayer:delayer_on_4" then
|
2013-12-01 02:20:01 +01:00
|
|
|
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_1", param2=node.param2})
|
2012-08-13 20:17:45 +02:00
|
|
|
end
|
2012-12-08 21:56:09 +01:00
|
|
|
end,
|
2012-12-27 09:28:04 +01:00
|
|
|
delayer_time = delaytime,
|
|
|
|
delayer_offstate = "mesecons_delayer:delayer_off_"..tostring(i),
|
2012-12-08 21:56:09 +01:00
|
|
|
mesecons = {
|
|
|
|
receptor =
|
|
|
|
{
|
|
|
|
state = mesecon.state.on,
|
|
|
|
rules = delayer_get_output_rules
|
|
|
|
},
|
|
|
|
effector =
|
|
|
|
{
|
|
|
|
rules = delayer_get_input_rules,
|
2012-12-27 09:28:04 +01:00
|
|
|
action_off = delayer_deactivate
|
2012-12-08 21:56:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2012-08-10 22:58:48 +02:00
|
|
|
end
|
2012-12-30 09:07:49 +01:00
|
|
|
|
|
|
|
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"},
|
|
|
|
}
|
|
|
|
})
|