mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-12-25 18:00:19 +01:00
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
|
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
local np = mesecon:addPosRule(pos, rule)
|
||||||
local link, rulename = mesecon:rules_link(pos, np, rules)
|
local rulenames = mesecon:rules_link_rule_all(pos, rule)
|
||||||
if link then
|
for _, rulename in ipairs(rulenames) do
|
||||||
mesecon:turnon(np, rulename)
|
mesecon:turnon(np, rulename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -126,8 +126,8 @@ function mesecon:receptor_off_i(pos, rules)
|
|||||||
rules = rules or mesecon.rules.default
|
rules = rules or mesecon.rules.default
|
||||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
local np = mesecon:addPosRule(pos, rule)
|
||||||
local link, rulename = mesecon:rules_link(pos, np, rules)
|
local rulenames = mesecon:rules_link_rule_all(pos, rule)
|
||||||
if link then
|
for _, rulename in ipairs(rulenames) do
|
||||||
if not mesecon:connected_to_receptor(np, mesecon:invertRule(rule)) then
|
if not mesecon:connected_to_receptor(np, mesecon:invertRule(rule)) then
|
||||||
mesecon:turnoff(np, rulename)
|
mesecon:turnoff(np, rulename)
|
||||||
else
|
else
|
||||||
|
@ -429,9 +429,9 @@ function mesecon:turnon(pos, rulename)
|
|||||||
|
|
||||||
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
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)
|
mesecon:turnon(np, rulename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -462,9 +462,9 @@ function mesecon:turnoff(pos, rulename)
|
|||||||
|
|
||||||
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
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)
|
mesecon:turnoff(np, rulename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -563,23 +563,24 @@ function mesecon:rules_link(output, input, dug_outputrules) --output/input are p
|
|||||||
return false
|
return false
|
||||||
end
|
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 input = mesecon:addPosRule(output, rule)
|
||||||
local inputnode = minetest.get_node(input)
|
local inputnode = minetest.get_node(input)
|
||||||
local inputrules = mesecon:get_any_inputrules (inputnode)
|
local inputrules = mesecon:get_any_inputrules (inputnode)
|
||||||
if not inputrules then
|
if not inputrules then
|
||||||
return
|
return {}
|
||||||
end
|
end
|
||||||
|
local rules = {}
|
||||||
|
|
||||||
for _, inputrule in ipairs(mesecon:flattenrules(inputrules)) do
|
for _, inputrule in ipairs(mesecon:flattenrules(inputrules)) do
|
||||||
-- Check if input accepts from output
|
-- Check if input accepts from output
|
||||||
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then
|
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then
|
||||||
if inputrule.sx == nil or rule.sx == nil or mesecon:cmpSpecial(inputrule, rule) 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
|
end
|
||||||
end
|
end
|
||||||
return false
|
return rules
|
||||||
end
|
end
|
||||||
|
|
||||||
function mesecon:rules_link_anydir(pos1, pos2)
|
function mesecon:rules_link_anydir(pos1, pos2)
|
||||||
|
Loading…
Reference in New Issue
Block a user