Fix #182, bug when placing wire crossings next to a powered source

In case this fix creates new bugs, please report them.
This commit is contained in:
Jeija 2014-11-21 22:04:39 +01:00
parent dcf1f799c5
commit 1b9f1b8c13
2 changed files with 18 additions and 8 deletions

View File

@ -597,14 +597,18 @@ function mesecon:is_powered(pos, rule)
local rules = mesecon:get_any_inputrules(node)
if not rules then return false end
-- List of nodes that send out power to pos
local sourcepos = {}
if not rule then
for _, rule in ipairs(mesecon:flattenrules(rules)) do
local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
for _, rname in ipairs(rulenames) do
local np = mesecon:addPosRule(pos, rname)
local nn = minetest.get_node(np)
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname)) or mesecon:is_receptor_on (nn.name)) then
return true
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname))
or mesecon:is_receptor_on (nn.name)) then
table.insert(sourcepos, np)
end
end
end
@ -614,12 +618,14 @@ function mesecon:is_powered(pos, rule)
local np = mesecon:addPosRule(pos, rname)
local nn = minetest.get_node(np)
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname)) or mesecon:is_receptor_on (nn.name)) then
return true
sourcepos.insert(np)
end
end
end
return false
-- Return FALSE if not powered, return list of sources if is powered
if (#sourcepos == 0) then return false
else return sourcepos end
end
--Rules rotation Functions:

View File

@ -9,11 +9,15 @@ mesecon.on_placenode = function (pos, node)
-- Conductors: Send turnon signal when powered or replace by respective offstate conductor
-- if placed conductor is an onstate one
if mesecon:is_conductor(node.name) then
if mesecon:is_powered(pos) then
local sources = mesecon:is_powered(pos)
if sources then
-- also call receptor_on if itself is powered already, so that neighboring
-- conductors will be activated (when pushing an on-conductor with a piston)
mesecon:turnon (pos)
mesecon:receptor_on (pos, mesecon:conductor_get_rules(node))
for _, s in ipairs(sources) do
local rule = {x = pos.x - s.x, y = pos.y - s.y, z = pos.z - s.z}
mesecon:turnon(pos, rule)
end
--mesecon:receptor_on (pos, mesecon:conductor_get_rules(node))
elseif mesecon:is_conductor_off(node.name) then
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node)})
end