diff --git a/mods/ITEMS/REDSTONE/mesecons/init.lua b/mods/ITEMS/REDSTONE/mesecons/init.lua index 4ef690b8de..3286c0cef4 100644 --- a/mods/ITEMS/REDSTONE/mesecons/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons/init.lua @@ -81,13 +81,6 @@ mesecon.queue:add_function("receptor_on", function (pos, rules) for _, rulename in ipairs(rulenames) do mesecon.turnon(np, rulename) end - if rule.spread then - if minetest.get_item_group(minetest.get_node(np).name, "opaque") == 1 then - for _, neighbor in ipairs(mesecon.mcl_get_neighbors(np)) do - mesecon.turnon(neighbor.pos, vector.add(rule, neighbor.link)) - end - end - end end mesecon.vm_commit() @@ -117,19 +110,6 @@ mesecon.queue:add_function("receptor_off", function (pos, rules) mesecon.vm_abort() end end - if rule.spread then - if minetest.get_item_group(minetest.get_node(np).name, "opaque") == 1 then - for _, neighbor in ipairs(mesecon.mcl_get_neighbors(np)) do - mesecon.vm_begin() - mesecon.changesignal(neighbor.pos, minetest.get_node(neighbor.pos), vector.add(rule, neighbor.link), mesecon.state.off, 2) - if (mesecon.turnoff(neighbor.pos, vector.add(rule, neighbor.link))) then - mesecon.vm_commit() - else - mesecon.vm_abort() - end - end - end - end end end) diff --git a/mods/ITEMS/REDSTONE/mesecons/internal.lua b/mods/ITEMS/REDSTONE/mesecons/internal.lua index 3a75a23f60..0158467219 100644 --- a/mods/ITEMS/REDSTONE/mesecons/internal.lua +++ b/mods/ITEMS/REDSTONE/mesecons/internal.lua @@ -403,12 +403,24 @@ function mesecon.turnon(pos, link) mesecon.activate(f.pos, node, f.link, depth) end end + if node and f.link.spread and minetest.get_item_group(node.name, "opaque") == 1 then + -- Call turnon on neighbors + -- Warning: A LOT of nodes need to be looked at for this to work + for _, r in ipairs(mesecon.rule2meta(f.link, mesecon.rules.mcl_alldirs_spread)) do + local np = vector.add(f.pos, r) + for _, l in ipairs(mesecon.rules_link_rule_all(f.pos, r)) do + local nlink = table.copy(l) + nlink.spread = false + table.insert(frontiers, {pos = np, link = nlink}) + end + end + end depth = depth + 1 end end --- Turn on an equipotential section starting at `pos`, which outputs in the direction of `link`. +-- Turn off an equipotential section starting at `pos`, which outputs in the direction of `link`. -- Breadth-first search. Map is abstracted away in a voxelmanip. -- Follow all all conductor paths replacing conductors that were already -- looked at, deactivating / changing all effectors along the way. @@ -464,6 +476,10 @@ function mesecon.turnoff(pos, link) depth = depth }) end + if node and f.link.spread and minetest.get_item_group(node.name, "opaque") == 1 then + -- TODO: Call turnoff on neighbors + end + depth = depth + 1 end @@ -490,8 +506,10 @@ function mesecon.rules_link_rule_all(output, rule) for _, inputrule in ipairs(mesecon.flattenrules(inputrules)) do -- Check if input accepts from output - if vector.equals(vector.add(input, inputrule), output) then - table.insert(rules, inputrule) + if vector.equals(vector.add(input, inputrule), output) then + local newrule = table.copy(inputrule) + newrule.spread = rule.spread + table.insert(rules, newrule) end end @@ -510,8 +528,11 @@ function mesecon.rules_link_rule_all_inverted(input, rule) local rules = {} for _, outputrule in ipairs(mesecon.flattenrules(outputrules)) do - if vector.equals(vector.add(output, outputrule), input) then - table.insert(rules, mesecon.invertRule(outputrule)) + if vector.equals(vector.add(output, outputrule), input) then + local newrule = table.copy(outputrule) + newrule = mesecon.invertRule(newrule) + newrule.spread = rule.spread + table.insert(rules, newrule) end end return rules diff --git a/mods/ITEMS/REDSTONE/mesecons/util.lua b/mods/ITEMS/REDSTONE/mesecons/util.lua index c848b9d3e8..7fd1f6fd31 100644 --- a/mods/ITEMS/REDSTONE/mesecons/util.lua +++ b/mods/ITEMS/REDSTONE/mesecons/util.lua @@ -198,7 +198,12 @@ function mesecon.set_bit(binary,bit,value) end function mesecon.invertRule(r) - return vector.multiply(r, -1) + local spread = r.spread + r = vector.multiply(r, -1) + if spread then + r.spread = true + end + return r end function mesecon.tablecopy(table) -- deep table copy