forked from minetest-mods/mesecons
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:
parent
dcf1f799c5
commit
1b9f1b8c13
@ -597,14 +597,18 @@ function mesecon:is_powered(pos, rule)
|
|||||||
local rules = mesecon:get_any_inputrules(node)
|
local rules = mesecon:get_any_inputrules(node)
|
||||||
if not rules then return false end
|
if not rules then return false end
|
||||||
|
|
||||||
|
-- List of nodes that send out power to pos
|
||||||
|
local sourcepos = {}
|
||||||
|
|
||||||
if not rule then
|
if not rule then
|
||||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||||
local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
|
local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
|
||||||
for _, rname in ipairs(rulenames) do
|
for _, rname in ipairs(rulenames) do
|
||||||
local np = mesecon:addPosRule(pos, rname)
|
local np = mesecon:addPosRule(pos, rname)
|
||||||
local nn = minetest.get_node(np)
|
local nn = minetest.get_node(np)
|
||||||
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname)) or mesecon:is_receptor_on (nn.name)) then
|
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname))
|
||||||
return true
|
or mesecon:is_receptor_on (nn.name)) then
|
||||||
|
table.insert(sourcepos, np)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -614,12 +618,14 @@ function mesecon:is_powered(pos, rule)
|
|||||||
local np = mesecon:addPosRule(pos, rname)
|
local np = mesecon:addPosRule(pos, rname)
|
||||||
local nn = minetest.get_node(np)
|
local nn = minetest.get_node(np)
|
||||||
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname)) or mesecon:is_receptor_on (nn.name)) then
|
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
|
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
|
end
|
||||||
|
|
||||||
--Rules rotation Functions:
|
--Rules rotation Functions:
|
||||||
|
@ -9,11 +9,15 @@ mesecon.on_placenode = function (pos, node)
|
|||||||
-- Conductors: Send turnon signal when powered or replace by respective offstate conductor
|
-- Conductors: Send turnon signal when powered or replace by respective offstate conductor
|
||||||
-- if placed conductor is an onstate one
|
-- if placed conductor is an onstate one
|
||||||
if mesecon:is_conductor(node.name) then
|
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
|
-- also call receptor_on if itself is powered already, so that neighboring
|
||||||
-- conductors will be activated (when pushing an on-conductor with a piston)
|
-- conductors will be activated (when pushing an on-conductor with a piston)
|
||||||
mesecon:turnon (pos)
|
for _, s in ipairs(sources) do
|
||||||
mesecon:receptor_on (pos, mesecon:conductor_get_rules(node))
|
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
|
elseif mesecon:is_conductor_off(node.name) then
|
||||||
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node)})
|
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node)})
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user