Propagate redstone power through opaque blocks

This commit is contained in:
Wuzzy 2018-01-20 19:04:53 +01:00
parent aaf68793fe
commit 33d978de06
3 changed files with 32 additions and 26 deletions

@ -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)

@ -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
@ -491,7 +507,9 @@ 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)
local newrule = table.copy(inputrule)
newrule.spread = rule.spread
table.insert(rules, newrule)
end
end
@ -511,7 +529,10 @@ function mesecon.rules_link_rule_all_inverted(input, rule)
for _, outputrule in ipairs(mesecon.flattenrules(outputrules)) do
if vector.equals(vector.add(output, outputrule), input) then
table.insert(rules, mesecon.invertRule(outputrule))
local newrule = table.copy(outputrule)
newrule = mesecon.invertRule(newrule)
newrule.spread = rule.spread
table.insert(rules, newrule)
end
end
return rules

@ -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