forked from Mirrorlandia_minetest/mesecons
Fix when there are several rules with different specials
This commit is contained in:
parent
b3f3692622
commit
fb417d45a7
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user