mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-12-25 09:50:19 +01:00
Make mesecons only connect to input and output ports (e.g. of the delayer)
This commit is contained in:
parent
439af2a88b
commit
24c50571f7
@ -107,9 +107,9 @@ function mesecon:add_receptor_node(nodename, rules, get_rules) --rules table is
|
||||
rules=mesecon:get_rules("default")
|
||||
end
|
||||
mesecon.receptors[i]={}
|
||||
mesecon.receptors[i].name=nodename
|
||||
mesecon.receptors[i].rules=rules
|
||||
mesecon.receptors[i].get_rules=get_rules
|
||||
mesecon.receptors[i].name = nodename
|
||||
mesecon.receptors[i].rules = rules
|
||||
mesecon.receptors[i].get_rules = get_rules
|
||||
end
|
||||
|
||||
function mesecon:add_receptor_node_off(nodename, rules, get_rules)
|
||||
@ -122,9 +122,25 @@ function mesecon:add_receptor_node_off(nodename, rules, get_rules)
|
||||
rules=mesecon:get_rules("default")
|
||||
end
|
||||
mesecon.receptors_off[i]={}
|
||||
mesecon.receptors_off[i].name=nodename
|
||||
mesecon.receptors_off[i].rules=rules
|
||||
mesecon.receptors_off[i].get_rules=get_rules
|
||||
mesecon.receptors_off[i].name = nodename
|
||||
mesecon.receptors_off[i].rules = rules
|
||||
mesecon.receptors_off[i].get_rules = get_rules
|
||||
end
|
||||
|
||||
function mesecon:register_effector(onstate, offstate, input_rules, get_input_rules)
|
||||
local i=1
|
||||
repeat
|
||||
if mesecon.effectors[i]==nil then break end
|
||||
i=i+1
|
||||
until false
|
||||
if get_input_rules==nil and input_rules==nil then
|
||||
rules=mesecon:get_rules("default")
|
||||
end
|
||||
mesecon.effectors[i]={}
|
||||
mesecon.effectors[i].onstate = onstate
|
||||
mesecon.effectors[i].offstate = offstate
|
||||
mesecon.effectors[i].input_rules = input_rules
|
||||
mesecon.effectors[i].get_input_rules = get_input_rules
|
||||
end
|
||||
|
||||
function mesecon:receptor_on(pos, rules)
|
||||
|
@ -37,6 +37,7 @@ function mesecon:receptor_get_rules(node)
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
local i = 1
|
||||
while(mesecon.receptors_off[i] ~= nil) do
|
||||
if mesecon.receptors_off[i].name == node.name then
|
||||
if mesecon.receptors_off[i].get_rules ~= nil then
|
||||
@ -52,6 +53,64 @@ function mesecon:receptor_get_rules(node)
|
||||
return nil
|
||||
end
|
||||
|
||||
function mesecon:effector_get_input_rules(node)
|
||||
local i = 1
|
||||
while(mesecon.effectors[i] ~= nil) do
|
||||
if mesecon.effectors[i].onstate == node.name
|
||||
or mesecon.effectors[i].offstate == node.name then
|
||||
if mesecon.effectors[i].get_input_rules ~= nil then
|
||||
return mesecon.effectors[i].get_input_rules(node.param2)
|
||||
elseif mesecon.receptors[i].input_rules ~=nil then
|
||||
return mesecon.effectors[i].input_rules
|
||||
else
|
||||
return mesecon:get_rules("default")
|
||||
end
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- Helpers for nodeboxlike mesecons
|
||||
function mesecon:receptor_outputs (cpos, rpos) --cpos = conductor pos, rpos = receptor pos
|
||||
local rnode = minetest.env:get_node (rpos)
|
||||
local rules = mesecon:receptor_get_rules (rnode)
|
||||
if rules == nil then return false end
|
||||
|
||||
local i = 1
|
||||
while rules[i] ~= nil do
|
||||
if rpos.x + rules[i].x == cpos.x
|
||||
and rpos.y + rules[i].y == cpos.y
|
||||
and rpos.z + rules[i].z == cpos.z then
|
||||
return true
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:effector_inputs (cpos, rpos) --cpos = conductor pos, rpos = receptor pos
|
||||
local rnode = minetest.env:get_node (rpos)
|
||||
local rules = mesecon:effector_get_input_rules (rnode)
|
||||
if rules == nil then return false end
|
||||
|
||||
local i = 1
|
||||
while rules[i] ~= nil do
|
||||
if rpos.x + rules[i].x == cpos.x
|
||||
and rpos.y + rules[i].y == cpos.y
|
||||
and rpos.z + rules[i].z == cpos.z then
|
||||
return true
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:node_connects(cpos, rpos) --cpos = conductor pos, rpos = receptor pos
|
||||
return mesecon:receptor_outputs (cpos, rpos) or mesecon:effector_inputs (cpos, rpos)
|
||||
end
|
||||
|
||||
--Signals
|
||||
|
||||
function mesecon:activate(pos)
|
||||
|
@ -232,24 +232,51 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old)
|
||||
nodename = minetest.env:get_node(pos).name
|
||||
if string.find(nodename, "mesecons:wire_") == nil and not replace_old then return nil end
|
||||
|
||||
|
||||
--if the groups mesecon == 1 then wires won't connect to it
|
||||
xp = (minetest.get_item_group(minetest.env:get_node(xppos).name, "mesecon") > 1 or
|
||||
minetest.get_item_group(minetest.env:get_node(xpympos).name, "mesecon") > 1) and 1 or 0
|
||||
zp = (minetest.get_item_group(minetest.env:get_node(zppos).name, "mesecon") > 1 or
|
||||
minetest.get_item_group(minetest.env:get_node(zpympos).name, "mesecon") > 1) and 1 or 0
|
||||
xm = (minetest.get_item_group(minetest.env:get_node(xmpos).name, "mesecon") > 1 or
|
||||
minetest.get_item_group(minetest.env:get_node(xmympos).name, "mesecon") > 1) and 1 or 0
|
||||
zm = (minetest.get_item_group(minetest.env:get_node(zmpos).name, "mesecon") > 1 or
|
||||
minetest.get_item_group(minetest.env:get_node(zmympos).name, "mesecon") > 1) and 1 or 0
|
||||
local zmg = minetest.get_item_group(minetest.env:get_node(zmpos ).name, "mesecon")
|
||||
local zmymg = minetest.get_item_group(minetest.env:get_node(zmympos).name, "mesecon")
|
||||
local xmg = minetest.get_item_group(minetest.env:get_node(xmpos ).name, "mesecon")
|
||||
local xmymg = minetest.get_item_group(minetest.env:get_node(xmympos).name, "mesecon")
|
||||
local zpg = minetest.get_item_group(minetest.env:get_node(zppos ).name, "mesecon")
|
||||
local zpymg = minetest.get_item_group(minetest.env:get_node(zpympos).name, "mesecon")
|
||||
local xpg = minetest.get_item_group(minetest.env:get_node(xppos ).name, "mesecon")
|
||||
local xpymg = minetest.get_item_group(minetest.env:get_node(xpympos).name, "mesecon")
|
||||
|
||||
|
||||
xpy = (minetest.get_item_group(minetest.env:get_node(xpypos).name, "mesecon") > 1) and 1 or 0
|
||||
zpy = (minetest.get_item_group(minetest.env:get_node(zpypos).name, "mesecon") > 1) and 1 or 0
|
||||
xmy = (minetest.get_item_group(minetest.env:get_node(xmypos).name, "mesecon") > 1) and 1 or 0
|
||||
zmy = (minetest.get_item_group(minetest.env:get_node(zmypos).name, "mesecon") > 1) and 1 or 0
|
||||
local xpyg = minetest.get_item_group(minetest.env:get_node(xpypos).name, "mesecon")
|
||||
local zpyg = minetest.get_item_group(minetest.env:get_node(zpypos).name, "mesecon")
|
||||
local xmyg = minetest.get_item_group(minetest.env:get_node(xmypos).name, "mesecon")
|
||||
local zmyg = minetest.get_item_group(minetest.env:get_node(zmypos).name, "mesecon")
|
||||
|
||||
if ((zmg == 2) or (zmymg == 2)) == true then zm = 1 else zm = 0 end
|
||||
if ((xmg == 2) or (xmymg == 2)) == true then xm = 1 else xm = 0 end
|
||||
if ((zpg == 2) or (zpymg == 2)) == true then zp = 1 else zp = 0 end
|
||||
if ((xpg == 2) or (xpymg == 2)) == true then xp = 1 else xp = 0 end
|
||||
|
||||
if xpyg == 2 then xpy = 1 else xpy = 0 end
|
||||
if zpyg == 2 then zpy = 1 else zpy = 0 end
|
||||
if xmyg == 2 then xmy = 1 else xmy = 0 end
|
||||
if zmyg == 2 then zmy = 1 else zmy = 0 end
|
||||
|
||||
-- If group == 3 then the mesecon only connects to input and output ports
|
||||
if xpg == 3 and mesecon:node_connects(pos, xppos) then xp = 1 end
|
||||
if xmg == 3 and mesecon:node_connects(pos, xmpos) then xm = 1 end
|
||||
if zpg == 3 and mesecon:node_connects(pos, zppos) then zp = 1 end
|
||||
if zmg == 3 and mesecon:node_connects(pos, zmpos) then zm = 1 end
|
||||
|
||||
if xpymg == 3 and mesecon:node_connects(pos, xpympos) then xp = 1 end
|
||||
if xmymg == 3 and mesecon:node_connects(pos, xmympos) then xm = 1 end
|
||||
if zpymg == 3 and mesecon:node_connects(pos, zpympos) then zp = 1 end
|
||||
if zmymg == 3 and mesecon:node_connects(pos, zmympos) then zm = 1 end
|
||||
|
||||
if xpyg == 3 then if mesecon:node_connects(pos, xpypos) then xpy = 1 end end
|
||||
if zpyg == 3 then if mesecon:node_connects(pos, zpypos) then zpy = 1 end end
|
||||
if xmyg == 3 then if mesecon:node_connects(pos, xmypos) then xmy = 1 end end
|
||||
if zmyg == 3 then if mesecon:node_connects(pos, zmypos) then zmy = 1 end end
|
||||
|
||||
-- Backward compatibility
|
||||
if replace_old then
|
||||
print ("replacing")
|
||||
xp = (xp == 1 or (string.find(minetest.env:get_node(xppos ).name, "mesecons:mesecon_") ~= nil or
|
||||
string.find(minetest.env:get_node(xpympos).name, "mesecons:mesecon_") ~= nil)) and 1 or 0
|
||||
zp = (zp == 1 or (string.find(minetest.env:get_node(zppos ).name, "mesecons:mesecon_") ~= nil or
|
||||
@ -273,6 +300,7 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old)
|
||||
local nodeid = tostring(xp )..tostring(zp )..tostring(xm )..tostring(zm )..
|
||||
tostring(xpy)..tostring(zpy)..tostring(xmy)..tostring(zmy)
|
||||
|
||||
|
||||
if string.find(nodename, "_off") ~= nil then
|
||||
minetest.env:set_node(pos, {name = "mesecons:wire_"..nodeid.."_off"})
|
||||
else
|
||||
@ -287,12 +315,12 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_abm(
|
||||
{nodenames = {"mesecons:mesecon_off", "mesecons:mesecon_on"},
|
||||
interval = 2,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
mesecon:update_autoconnect(pos, false, true)
|
||||
end,
|
||||
})
|
||||
--minetest.register_abm(
|
||||
-- {nodenames = {"mesecons:mesecon_off", "mesecons:mesecon_on"},
|
||||
-- interval = 2,
|
||||
-- chance = 1,
|
||||
-- action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
-- mesecon:update_autoconnect(pos, false, true)
|
||||
-- end,
|
||||
--})
|
||||
end
|
||||
|
@ -1,9 +1,9 @@
|
||||
for i = 1, 4 do
|
||||
local groups = {}
|
||||
if i == 1 then
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2, mesecon = 2}
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2, mesecon = 3}
|
||||
else
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 2}
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}
|
||||
end
|
||||
|
||||
boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab
|
||||
@ -69,7 +69,7 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
|
||||
type = "fixed",
|
||||
fixed = boxes
|
||||
},
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2,not_in_creative_inventory=1, mesecon = 2},
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 3},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
@ -218,3 +218,8 @@ mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_1", all_rules, mesec
|
||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_2", all_rules, mesecon.delayer_get_output_rules)
|
||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_3", all_rules, mesecon.delayer_get_output_rules)
|
||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_4", all_rules, mesecon.delayer_get_output_rules)
|
||||
|
||||
mesecon:register_effector("mesecons_delayer:delayer_on_1", "mesecons_delayer:delayer_off_1", all_rules, mesecon.delayer_get_input_rules)
|
||||
mesecon:register_effector("mesecons_delayer:delayer_on_2", "mesecons_delayer:delayer_off_2", all_rules, mesecon.delayer_get_input_rules)
|
||||
mesecon:register_effector("mesecons_delayer:delayer_on_3", "mesecons_delayer:delayer_off_3", all_rules, mesecon.delayer_get_input_rules)
|
||||
mesecon:register_effector("mesecons_delayer:delayer_on_4", "mesecons_delayer:delayer_off_4", all_rules, mesecon.delayer_get_input_rules)
|
||||
|
Loading…
Reference in New Issue
Block a user