2015-08-28 12:24:33 +02:00
|
|
|
local nodebox = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {{-8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }},
|
|
|
|
}
|
|
|
|
|
|
|
|
local function signalchanger_get_output_rules(node)
|
2017-04-19 20:53:18 +02:00
|
|
|
local rules = {{x=-1, y=0, z=0},
|
|
|
|
{x=1, y=0, z=0}}
|
2021-03-07 19:19:00 +01:00
|
|
|
for _ = 0, node.param2 do
|
2015-08-28 12:24:33 +02:00
|
|
|
rules = mesecon.rotate_rules_left(rules)
|
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
|
|
|
|
|
|
|
local function signalchanger_get_input_rules(node)
|
2017-04-19 20:53:18 +02:00
|
|
|
local rules = {{x=0, y=0, z=-1, name="input_on"}, {x=0, y=0, z=1, name="input_off"}}
|
2021-03-07 19:19:00 +01:00
|
|
|
for _ = 0, node.param2 do
|
2015-08-28 12:24:33 +02:00
|
|
|
rules = mesecon.rotate_rules_left(rules)
|
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
|
|
|
|
|
|
|
local update = function(pos, node, link, newstate)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_int(link.name, newstate == "on" and 1 or 0)
|
|
|
|
local input_on = meta:get_int("input_on") == 1
|
|
|
|
local input_off = meta:get_int("input_off") == 1
|
|
|
|
if input_on then
|
2015-12-17 12:56:12 +01:00
|
|
|
mesecon.receptor_on(pos, {signalchanger_get_output_rules(node)[1]})
|
|
|
|
mesecon.receptor_off(pos, {signalchanger_get_output_rules(node)[2]})
|
2015-08-28 12:24:33 +02:00
|
|
|
minetest.swap_node(pos, {name = "moremesecons_signalchanger:signalchanger_on", param2 = node.param2})
|
|
|
|
elseif input_off then
|
2015-12-17 12:56:12 +01:00
|
|
|
mesecon.receptor_off(pos, {signalchanger_get_output_rules(node)[1]})
|
|
|
|
mesecon.receptor_on(pos, {signalchanger_get_output_rules(node)[2]})
|
2015-08-28 12:24:33 +02:00
|
|
|
minetest.swap_node(pos, {name = "moremesecons_signalchanger:signalchanger_off", param2 = node.param2})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mesecon.register_node("moremesecons_signalchanger:signalchanger", {
|
|
|
|
description = "Signal Changer",
|
|
|
|
inventory_image = "moremesecons_signalchanger_off.png",
|
|
|
|
groups = {dig_immediate = 2},
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
drawtype = "nodebox",
|
|
|
|
selection_box = nodebox,
|
|
|
|
node_box = nodebox,
|
|
|
|
},{
|
|
|
|
groups = {dig_immediate = 2},
|
|
|
|
mesecons = {
|
|
|
|
receptor = {
|
|
|
|
rules = signalchanger_get_output_rules
|
|
|
|
},
|
|
|
|
effector = {
|
|
|
|
rules = signalchanger_get_input_rules,
|
|
|
|
action_change = update
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tiles = {"moremesecons_signalchanger_off.png"},
|
2015-12-17 12:56:12 +01:00
|
|
|
on_construct = function(pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
mesecon.receptor_on(pos, {signalchanger_get_output_rules(node)[2]})
|
|
|
|
end
|
2015-08-28 12:24:33 +02:00
|
|
|
},{
|
|
|
|
groups = {dig_immediate = 2, not_in_creative_inventory = 1},
|
|
|
|
mesecons = {
|
|
|
|
receptor = {
|
|
|
|
rules = signalchanger_get_output_rules,
|
|
|
|
},
|
|
|
|
effector = {
|
|
|
|
rules = signalchanger_get_input_rules,
|
|
|
|
action_change = update,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tiles = {"moremesecons_signalchanger_on.png"},
|
|
|
|
})
|
2015-08-29 12:33:03 +02:00
|
|
|
|
|
|
|
minetest.register_craft({
|
2015-08-29 17:31:01 +02:00
|
|
|
output = "moremesecons_signalchanger:signalchanger_off",
|
2017-04-23 17:45:58 +02:00
|
|
|
recipe = {{"group:mesecon_conductor_craftable","moremesecons_switchtorch:switchtorch_off","group:mesecon_conductor_craftable"}}
|
2015-08-29 12:33:03 +02:00
|
|
|
})
|