gate output works

This commit is contained in:
Kyle 2012-09-01 13:07:18 -07:00
parent 6147c385cc
commit f93930a478

View File

@ -1,33 +1,30 @@
gates = {"diode", "not", "nand", "and", "xor"} gates = {"diode", "not", "nand", "and", "xor"}
for g in ipairs(gates) do gate = gates[g] out = {x=1, y=0, z=0}
inonerules = {{x=-1, y=0, z=0}}
inrules = {} intworules = {{x=0, y=0, z=1},{x=0, y=0, z=-1}}
onerules = inonerules
table.insert(onerules, out)
tworules = intworules
table.insert(tworules, out)
outrules = {} outrules = {}
rules = {} outrules = table.insert(outrules, out)
table.insert(outrules, {x=1, y=0, z=0}) for g in ipairs(gates) do gate = gates[g]
table.insert(rules, {x=1, y=0, z=0})
if g < 3 then if g < 3 then
table.insert(inrules, {x=-1, y=0, z=0}) inrules = inonerules
table.insert(rules, {x=-1, y=0, z=0}) rules = onerules
else else
table.insert(inrules, {x=0, y=0, z=1}) inrules = intworules
table.insert(rules, {x=0, y=0, z=1}) rules = tworules
table.insert(inrules, {x=0, y=0, z=-1})
table.insert(rules, {x=0, y=0, z=-1})
end end
--table.insert(rules, inrules)
--table.insert(rules, outrules)
for on=0,1 do for on=0,1 do
if on == 1 then if on == 1 then
onoff = "on" onoff = "on"
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}
drop = "mesecons_gates:"..gate.."_off"
else else
onoff = "off" onoff = "off"
end
if on == 1 then
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}
else
groups = {dig_immediate=2, mesecon = 3} groups = {dig_immediate=2, mesecon = 3}
drop = nodename
end end
nodename = "mesecons_gates:"..gate.."_"..onoff nodename = "mesecons_gates:"..gate.."_"..onoff
@ -44,16 +41,11 @@ for g in ipairs(gates) do gate = gates[g]
update_gate(pos) update_gate(pos)
end, end,
groups = groups, groups = groups,
drop = drop,
}) })
mesecon:add_rules(gate,outrules) mesecon:register_effector(nodename, nodename, inrules)
mesecon:register_effector(nodename, nodename, rules)
--if on then
-- mesecon:add_receptor_node(nodename, outrules)
--end
--mesecon:add_receptor_node("mesecons_gates:and_off",
--mesecon:add_receptor_node("mesecons_gates:and_on",
end end
end end
@ -74,27 +66,19 @@ function gate_state(pos)
return true return true
end end
end end
--[[
function gate_on(pos)
if !gate_state(pos) then
minetest.env:add_node("mesecons_gates:"..get_gate(pos).."_on")
end
end
function gate_off(pos) function set_gate(pos, on)
if gate_state(pos) then gate = get_gate(pos)
minetest.env:add_node("mesecons_gates:"..get_gate(pos).."_off") local rules = {{x=1, y=0, z=0}}
end if on then
end
--]]
function set_gate(pos, open)
if open then
if not gate_state(pos) then if not gate_state(pos) then
minetest.env:add_node(pos, {name="mesecons_gates:"..get_gate(pos).."_on"}) minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_on"})
mesecon:receptor_on(pos, rules)
end end
else else
if gate_state(pos) then if gate_state(pos) then
minetest.env:add_node(pos, {name="mesecons_gates:"..get_gate(pos).."_off"}) minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_off"})
mesecon:receptor_off(pos, rules)
end end
end end
end end
@ -121,4 +105,3 @@ mesecon:register_on_signal_change(function(pos,node)
end end
end) end)