Skip to content

Commit

Permalink
Fix #182, bug when placing wire crossings next to a powered source
Browse files Browse the repository at this point in the history
In case this fix creates new bugs, please report them.
  • Loading branch information
Jeija committed Nov 21, 2014
1 parent dcf1f79 commit 1b9f1b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 11 additions & 5 deletions mesecons/internal.lua
Expand Up @@ -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
Expand All @@ -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:
Expand Down
10 changes: 7 additions & 3 deletions mesecons/services.lua
Expand Up @@ -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
Expand Down

0 comments on commit 1b9f1b8

Please sign in to comment.