2022-12-01 18:33:19 +01:00
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
|
2012-12-08 21:56:09 +01:00
|
|
|
-- Function that get the input/output rules of the delayer
|
2022-06-05 11:19:18 +02:00
|
|
|
local delayer_get_output_rules = mesecon.horiz_rules_getter({{x = 1, y = 0, z = 0}})
|
2012-12-08 21:56:09 +01:00
|
|
|
|
2022-06-05 11:19:18 +02:00
|
|
|
local delayer_get_input_rules = mesecon.horiz_rules_getter({{x = -1, y = 0, z = 0}})
|
2012-12-08 21:56:09 +01:00
|
|
|
|
|
|
|
-- 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
|
|
|
|
2019-11-04 20:00:43 +01:00
|
|
|
local delaytime = { 0.1, 0.3, 0.5, 1.0 }
|
2012-08-10 21:50:07 +02:00
|
|
|
|
2019-11-04 20:00:43 +01:00
|
|
|
for i = 1, 4 do
|
2012-12-27 09:28:04 +01:00
|
|
|
|
2019-11-04 20:00:43 +01:00
|
|
|
-- Delayer definition defaults
|
|
|
|
local def = {
|
2012-06-21 20:33:01 +02:00
|
|
|
drawtype = "nodebox",
|
2021-04-09 20:24:41 +02:00
|
|
|
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or nil,
|
2012-08-10 21:50:07 +02:00
|
|
|
walkable = true,
|
2012-06-21 20:33:01 +02:00
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2024-06-08 13:43:47 +02:00
|
|
|
fixed = { -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 },
|
2012-06-21 20:33:01 +02:00
|
|
|
},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
2024-06-08 13:43:47 +02:00
|
|
|
fixed = {
|
|
|
|
{ -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }, -- bottom slab
|
|
|
|
{ -6/16, -7/16, -6/16, 6/16, -6/16, 6/16 }
|
|
|
|
},
|
2012-06-21 20:33:01 +02:00
|
|
|
},
|
2012-03-29 22:11:17 +02:00
|
|
|
paramtype = "light",
|
2012-06-21 20:33:01 +02:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
sunlight_propagates = true,
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2019-11-04 20:00:43 +01:00
|
|
|
delayer_time = delaytime[i],
|
2022-05-05 16:57:53 +02:00
|
|
|
sounds = mesecon.node_sound.stone,
|
2019-11-04 20:00:43 +01:00
|
|
|
on_blast = mesecon.on_blastnode,
|
|
|
|
drop = "mesecons_delayer:delayer_off_1",
|
2024-01-22 18:29:02 +01:00
|
|
|
delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i),
|
|
|
|
delayer_offstate = "mesecons_delayer:delayer_off_"..tostring(i),
|
2019-11-04 20:00:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
-- Deactivated delayer definition defaults
|
|
|
|
local off_groups = {bendy=2,snappy=1,dig_immediate=2}
|
|
|
|
if i > 1 then
|
|
|
|
off_groups.not_in_creative_inventory = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
local off_state = {
|
2022-12-01 18:33:19 +01:00
|
|
|
description = S("Delayer"),
|
2024-06-08 13:43:47 +02:00
|
|
|
inventory_image = "jeija_gate_off.png^jeija_delayer.png",
|
|
|
|
wield_image = "jeija_gate_off.png^jeija_delayer.png",
|
2019-11-04 20:00:43 +01:00
|
|
|
tiles = {
|
2024-06-08 13:43:47 +02:00
|
|
|
"jeija_microcontroller_bottom.png^jeija_gate_output_off.png^jeija_gate_off.png^"..
|
|
|
|
"jeija_delayer.png^mesecons_delayer_"..tostring(i)..".png",
|
|
|
|
"jeija_microcontroller_bottom.png^jeija_gate_output_off.png",
|
|
|
|
"jeija_gate_side.png^jeija_gate_side_output_off.png",
|
|
|
|
"jeija_gate_side.png",
|
|
|
|
"jeija_gate_side.png",
|
|
|
|
"jeija_gate_side.png",
|
2019-11-04 20:00:43 +01:00
|
|
|
},
|
|
|
|
groups = off_groups,
|
|
|
|
on_punch = function(pos, node, puncher)
|
2020-12-10 11:53:50 +01:00
|
|
|
if minetest.is_protected(pos, puncher and puncher:get_player_name() or "") then
|
2019-11-04 20:00:43 +01:00
|
|
|
return
|
2012-12-08 21:56:09 +01:00
|
|
|
end
|
2019-11-04 20:00:43 +01:00
|
|
|
|
|
|
|
minetest.swap_node(pos, {
|
|
|
|
name = "mesecons_delayer:delayer_off_"..tostring(i % 4 + 1),
|
|
|
|
param2 = node.param2
|
|
|
|
})
|
2012-12-08 21:56:09 +01:00
|
|
|
end,
|
|
|
|
mesecons = {
|
|
|
|
receptor =
|
|
|
|
{
|
|
|
|
state = mesecon.state.off,
|
|
|
|
rules = delayer_get_output_rules
|
|
|
|
},
|
|
|
|
effector =
|
|
|
|
{
|
|
|
|
rules = delayer_get_input_rules,
|
2024-01-22 18:29:02 +01:00
|
|
|
action_off = delayer_deactivate,
|
2012-12-27 09:28:04 +01:00
|
|
|
action_on = delayer_activate
|
2012-12-08 21:56:09 +01:00
|
|
|
}
|
2017-10-07 00:44:49 +02:00
|
|
|
},
|
2019-11-04 20:00:43 +01:00
|
|
|
}
|
|
|
|
for k, v in pairs(def) do
|
|
|
|
off_state[k] = off_state[k] or v
|
|
|
|
end
|
|
|
|
minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), off_state)
|
2012-03-29 22:11:17 +02:00
|
|
|
|
2019-11-04 20:00:43 +01:00
|
|
|
-- Activated delayer definition defaults
|
|
|
|
local on_state = {
|
2022-12-01 18:33:19 +01:00
|
|
|
description = S("You hacker you"),
|
2024-06-08 13:43:47 +02:00
|
|
|
inventory_image = "jeija_gate_on.png^jeija_delayer.png",
|
|
|
|
wield_image = "jeija_gate_on.png^jeija_delayer.png",
|
2012-08-07 09:40:04 +02:00
|
|
|
tiles = {
|
2024-06-08 13:43:47 +02:00
|
|
|
"jeija_microcontroller_bottom.png^jeija_gate_output_on.png^jeija_gate_on.png^"..
|
|
|
|
"jeija_delayer.png^mesecons_delayer_"..tostring(i)..".png",
|
|
|
|
"jeija_microcontroller_bottom.png^jeija_gate_output_on.png",
|
|
|
|
"jeija_gate_side.png^jeija_gate_side_output_on.png",
|
|
|
|
"jeija_gate_side.png",
|
|
|
|
"jeija_gate_side.png",
|
|
|
|
"jeija_gate_side.png",
|
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},
|
2019-11-04 20:00:43 +01:00
|
|
|
on_punch = function(pos, node, puncher)
|
2020-12-10 11:53:50 +01:00
|
|
|
if minetest.is_protected(pos, puncher and puncher:get_player_name() or "") then
|
2019-11-04 20:00:43 +01:00
|
|
|
return
|
2012-08-13 20:17:45 +02:00
|
|
|
end
|
2019-11-04 20:00:43 +01:00
|
|
|
|
|
|
|
minetest.swap_node(pos, {
|
|
|
|
name = "mesecons_delayer:delayer_on_"..tostring(i % 4 + 1),
|
|
|
|
param2 = node.param2
|
|
|
|
})
|
2012-12-08 21:56:09 +01:00
|
|
|
end,
|
|
|
|
mesecons = {
|
|
|
|
receptor =
|
|
|
|
{
|
|
|
|
state = mesecon.state.on,
|
|
|
|
rules = delayer_get_output_rules
|
|
|
|
},
|
|
|
|
effector =
|
|
|
|
{
|
|
|
|
rules = delayer_get_input_rules,
|
2024-01-22 18:29:02 +01:00
|
|
|
action_off = delayer_deactivate,
|
|
|
|
action_on = delayer_activate
|
2012-12-08 21:56:09 +01:00
|
|
|
}
|
2017-10-07 00:44:49 +02:00
|
|
|
},
|
2019-11-04 20:00:43 +01:00
|
|
|
}
|
|
|
|
for k, v in pairs(def) do
|
|
|
|
on_state[k] = on_state[k] or v
|
|
|
|
end
|
|
|
|
minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), on_state)
|
|
|
|
|
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"},
|
2022-05-05 16:57:53 +02:00
|
|
|
{"mesecons_gamecompat:cobble","mesecons_gamecompat:cobble", "mesecons_gamecompat:cobble"},
|
2012-12-30 09:07:49 +01:00
|
|
|
}
|
|
|
|
})
|