2020-05-27 23:31:51 +02:00
|
|
|
local selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 }
|
|
|
|
}
|
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
local nodebox = {
|
|
|
|
type = "fixed",
|
2020-05-27 23:31:51 +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 }
|
|
|
|
},
|
2014-11-29 15:08:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local function gate_rotate_rules(node, rules)
|
2012-12-10 19:46:24 +01:00
|
|
|
for rotations = 0, node.param2 - 1 do
|
2014-11-22 15:42:22 +01:00
|
|
|
rules = mesecon.rotate_rules_left(rules)
|
2012-12-10 19:46:24 +01:00
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
2012-12-10 17:19:30 +01:00
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
local function gate_get_output_rules(node)
|
|
|
|
return gate_rotate_rules(node, {{x=1, y=0, z=0}})
|
2012-12-10 19:46:24 +01:00
|
|
|
end
|
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
local function gate_get_input_rules_oneinput(node)
|
|
|
|
return gate_rotate_rules(node, {{x=-1, y=0, z=0}})
|
2012-12-10 19:46:24 +01:00
|
|
|
end
|
2012-12-10 17:19:30 +01:00
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
local function gate_get_input_rules_twoinputs(node)
|
|
|
|
return gate_rotate_rules(node, {{x=0, y=0, z=1, name="input1"},
|
|
|
|
{x=0, y=0, z=-1, name="input2"}})
|
2012-12-10 19:46:24 +01:00
|
|
|
end
|
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
local function set_gate(pos, node, state)
|
|
|
|
local gate = minetest.registered_nodes[node.name]
|
|
|
|
|
|
|
|
if mesecon.do_overheat(pos) then
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
mesecon.receptor_off(pos, gate_get_output_rules(node))
|
|
|
|
minetest.add_item(pos, gate.drop)
|
|
|
|
elseif state then
|
|
|
|
minetest.swap_node(pos, {name = gate.onstate, param2=node.param2})
|
|
|
|
mesecon.receptor_on(pos, gate_get_output_rules(node))
|
|
|
|
else
|
|
|
|
minetest.swap_node(pos, {name = gate.offstate, param2=node.param2})
|
|
|
|
mesecon.receptor_off(pos, gate_get_output_rules(node))
|
2012-12-10 19:46:24 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
local function update_gate(pos, node, link, newstate)
|
|
|
|
local gate = minetest.registered_nodes[node.name]
|
2012-09-05 06:16:32 +02:00
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
if gate.inputnumber == 1 then
|
|
|
|
set_gate(pos, node, gate.assess(newstate == "on"))
|
|
|
|
elseif gate.inputnumber == 2 then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_int(link.name, newstate == "on" and 1 or 0)
|
2012-12-10 17:19:30 +01:00
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
local val1 = meta:get_int("input1") == 1
|
|
|
|
local val2 = meta:get_int("input2") == 1
|
|
|
|
set_gate(pos, node, gate.assess(val1, val2))
|
|
|
|
end
|
2012-12-10 17:19:30 +01:00
|
|
|
end
|
|
|
|
|
2017-02-15 19:52:29 +01:00
|
|
|
local function register_gate(name, inputnumber, assess, recipe, description)
|
2014-11-29 15:08:37 +01:00
|
|
|
local get_inputrules = inputnumber == 2 and gate_get_input_rules_twoinputs or
|
|
|
|
gate_get_input_rules_oneinput
|
|
|
|
|
|
|
|
local basename = "mesecons_gates:"..name
|
|
|
|
mesecon.register_node(basename, {
|
|
|
|
description = description,
|
|
|
|
inventory_image = "jeija_gate_off.png^jeija_gate_"..name..".png",
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2014-11-29 15:08:37 +01:00
|
|
|
drawtype = "nodebox",
|
|
|
|
drop = basename.."_off",
|
2020-05-27 23:31:51 +02:00
|
|
|
selection_box = selection_box,
|
2014-11-29 15:08:37 +01:00
|
|
|
node_box = nodebox,
|
|
|
|
walkable = true,
|
2022-04-20 17:12:51 +02:00
|
|
|
sounds = mesecon.node_sound_stone_defaults,
|
2014-11-29 15:08:37 +01:00
|
|
|
assess = assess,
|
|
|
|
onstate = basename.."_on",
|
|
|
|
offstate = basename.."_off",
|
2017-04-14 21:14:17 +02:00
|
|
|
inputnumber = inputnumber,
|
|
|
|
after_dig_node = mesecon.do_cooldown,
|
2014-11-29 15:08:37 +01:00
|
|
|
},{
|
2020-05-27 23:31:51 +02:00
|
|
|
tiles = {
|
|
|
|
"jeija_microcontroller_bottom.png^".."jeija_gate_off.png^"..
|
|
|
|
"jeija_gate_output_off.png^".."jeija_gate_"..name..".png",
|
|
|
|
"jeija_microcontroller_bottom.png^".."jeija_gate_output_off.png^"..
|
|
|
|
"[transformFY",
|
|
|
|
"jeija_gate_side.png^".."jeija_gate_side_output_off.png",
|
|
|
|
"jeija_gate_side.png",
|
|
|
|
"jeija_gate_side.png",
|
|
|
|
"jeija_gate_side.png"
|
|
|
|
},
|
2015-01-03 14:04:18 +01:00
|
|
|
groups = {dig_immediate = 2, overheat = 1},
|
2014-11-29 15:08:37 +01:00
|
|
|
mesecons = { receptor = {
|
|
|
|
state = "off",
|
|
|
|
rules = gate_get_output_rules
|
|
|
|
}, effector = {
|
|
|
|
rules = get_inputrules,
|
|
|
|
action_change = update_gate
|
|
|
|
}}
|
|
|
|
},{
|
2020-05-27 23:31:51 +02:00
|
|
|
tiles = {
|
|
|
|
"jeija_microcontroller_bottom.png^".."jeija_gate_on.png^"..
|
|
|
|
"jeija_gate_output_on.png^".."jeija_gate_"..name..".png",
|
|
|
|
"jeija_microcontroller_bottom.png^".."jeija_gate_output_on.png^"..
|
|
|
|
"[transformFY",
|
|
|
|
"jeija_gate_side.png^".."jeija_gate_side_output_on.png",
|
|
|
|
"jeija_gate_side.png",
|
|
|
|
"jeija_gate_side.png",
|
|
|
|
"jeija_gate_side.png"
|
|
|
|
},
|
2015-01-03 14:04:18 +01:00
|
|
|
groups = {dig_immediate = 2, not_in_creative_inventory = 1, overheat = 1},
|
2014-11-29 15:08:37 +01:00
|
|
|
mesecons = { receptor = {
|
|
|
|
state = "on",
|
|
|
|
rules = gate_get_output_rules
|
|
|
|
}, effector = {
|
|
|
|
rules = get_inputrules,
|
|
|
|
action_change = update_gate
|
|
|
|
}}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({output = basename.."_off", recipe = recipe})
|
2012-12-10 19:46:24 +01:00
|
|
|
end
|
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
register_gate("diode", 1, function (input) return input end,
|
2017-02-15 19:52:29 +01:00
|
|
|
{{"mesecons:mesecon", "mesecons_torch:mesecon_torch_on", "mesecons_torch:mesecon_torch_on"}},
|
|
|
|
"Diode")
|
2012-12-10 17:19:30 +01:00
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
register_gate("not", 1, function (input) return not input end,
|
2017-02-15 19:52:29 +01:00
|
|
|
{{"mesecons:mesecon", "mesecons_torch:mesecon_torch_on", "mesecons:mesecon"}},
|
|
|
|
"NOT Gate")
|
2012-12-10 19:46:24 +01:00
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
register_gate("and", 2, function (val1, val2) return val1 and val2 end,
|
|
|
|
{{"mesecons:mesecon", "", ""},
|
|
|
|
{"", "mesecons_materials:silicon", "mesecons:mesecon"},
|
2017-02-15 19:52:29 +01:00
|
|
|
{"mesecons:mesecon", "", ""}},
|
|
|
|
"AND Gate")
|
2014-11-29 15:08:37 +01:00
|
|
|
|
|
|
|
register_gate("nand", 2, function (val1, val2) return not (val1 and val2) end,
|
|
|
|
{{"mesecons:mesecon", "", ""},
|
|
|
|
{"", "mesecons_materials:silicon", "mesecons_torch:mesecon_torch_on"},
|
2017-02-15 19:52:29 +01:00
|
|
|
{"mesecons:mesecon", "", ""}},
|
|
|
|
"NAND Gate")
|
2012-09-01 10:23:15 +02:00
|
|
|
|
2014-11-29 15:08:37 +01:00
|
|
|
register_gate("xor", 2, function (val1, val2) return (val1 or val2) and not (val1 and val2) end,
|
|
|
|
{{"mesecons:mesecon", "", ""},
|
|
|
|
{"", "mesecons_materials:silicon", "mesecons_materials:silicon"},
|
2017-02-15 19:52:29 +01:00
|
|
|
{"mesecons:mesecon", "", ""}},
|
|
|
|
"XOR Gate")
|
2015-11-20 20:13:59 +01:00
|
|
|
|
|
|
|
register_gate("nor", 2, function (val1, val2) return not (val1 or val2) end,
|
|
|
|
{{"mesecons:mesecon", "", ""},
|
2015-12-15 22:25:39 +01:00
|
|
|
{"", "mesecons:mesecon", "mesecons_torch:mesecon_torch_on"},
|
2017-02-15 19:52:29 +01:00
|
|
|
{"mesecons:mesecon", "", ""}},
|
|
|
|
"NOR Gate")
|
2015-11-20 20:13:59 +01:00
|
|
|
|
|
|
|
register_gate("or", 2, function (val1, val2) return (val1 or val2) end,
|
|
|
|
{{"mesecons:mesecon", "", ""},
|
|
|
|
{"", "mesecons:mesecon", "mesecons:mesecon"},
|
2017-02-15 19:52:29 +01:00
|
|
|
{"mesecons:mesecon", "", ""}},
|
|
|
|
"OR Gate")
|