summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesecons/init.lua8
-rw-r--r--mesecons/internal.lua19
2 files changed, 14 insertions, 13 deletions
diff --git a/mesecons/init.lua b/mesecons/init.lua
index 17fa443..640af4d 100644
--- a/mesecons/init.lua
+++ b/mesecons/init.lua
@@ -106,8 +106,8 @@ function mesecon:receptor_on_i(pos, rules)
for _, rule in ipairs(mesecon:flattenrules(rules)) do
local np = mesecon:addPosRule(pos, rule)
- local link, rulename = mesecon:rules_link(pos, np, rules)
- if link then
+ local rulenames = mesecon:rules_link_rule_all(pos, rule)
+ for _, rulename in ipairs(rulenames) do
mesecon:turnon(np, rulename)
end
end
@@ -126,8 +126,8 @@ function mesecon:receptor_off_i(pos, rules)
rules = rules or mesecon.rules.default
for _, rule in ipairs(mesecon:flattenrules(rules)) do
local np = mesecon:addPosRule(pos, rule)
- local link, rulename = mesecon:rules_link(pos, np, rules)
- if link then
+ local rulenames = mesecon:rules_link_rule_all(pos, rule)
+ for _, rulename in ipairs(rulenames) do
if not mesecon:connected_to_receptor(np, mesecon:invertRule(rule)) then
mesecon:turnoff(np, rulename)
else
diff --git a/mesecons/internal.lua b/mesecons/internal.lua
index a76d5e8..de91b92 100644
--- a/mesecons/internal.lua
+++ b/mesecons/internal.lua
@@ -429,9 +429,9 @@ function mesecon:turnon(pos, rulename)
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
local np = mesecon:addPosRule(pos, rule)
- local link, rulename = mesecon:rules_link_rule(pos, rule)
+ local rulenames = mesecon:rules_link_rule_all(pos, rule)
- if link then
+ for _, rulename in ipairs(rulenames) do
mesecon:turnon(np, rulename)
end
end
@@ -462,9 +462,9 @@ function mesecon:turnoff(pos, rulename)
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
local np = mesecon:addPosRule(pos, rule)
- local link, rulename = mesecon:rules_link_rule(pos, rule)
+ local rulenames = mesecon:rules_link_rule_all(pos, rule)
- if link then
+ for _, rulename in ipairs(rulenames) do
mesecon:turnoff(np, rulename)
end
end
@@ -563,23 +563,24 @@ function mesecon:rules_link(output, input, dug_outputrules) --output/input are p
return false
end
-function mesecon:rules_link_rule(output, rule) --output/input are positions (outputrules optional, used if node has been dug), second return value: the name of the affected input rule
+function mesecon:rules_link_rule_all(output, rule) --output/input are positions (outputrules optional, used if node has been dug), second return value: affected input rules
local input = mesecon:addPosRule(output, rule)
local inputnode = minetest.get_node(input)
local inputrules = mesecon:get_any_inputrules (inputnode)
if not inputrules then
- return
+ return {}
end
-
+ local rules = {}
+
for _, inputrule in ipairs(mesecon:flattenrules(inputrules)) do
-- Check if input accepts from output
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then
if inputrule.sx == nil or rule.sx == nil or mesecon:cmpSpecial(inputrule, rule) then
- return true, inputrule
+ rules[#rules+1] = inputrule
end
end
end
- return false
+ return rules
end
function mesecon:rules_link_anydir(pos1, pos2)