Fix #276: Fix bugs in block forceloading in turnon / turnoff

Thanks to @Hawk777 for reporting this problem
This commit is contained in:
Jeija 2016-07-25 10:01:43 +02:00
parent acd41b5773
commit 7c7595fd7d
1 changed files with 53 additions and 31 deletions

View File

@ -381,27 +381,38 @@ function mesecon.turnon(pos, link)
-- area not loaded, postpone action
if not node then
mesecon.queue:add_action(f.pos, "turnon", {link}, nil, true)
mesecon.queue:add_action(f.pos, "turnon", {f.link}, nil, true)
elseif mesecon.is_conductor_off(node, f.link) then
local rules = mesecon.conductor_get_rules(node)
minetest.swap_node(f.pos, {name = mesecon.get_conductor_on(node, f.link),
param2 = node.param2})
-- Success: If false, at least one neighboring node is unloaded,
-- postpone turning on action
local success = true
local neighborlinks = {}
-- call turnon on neighbors: normal rules
-- call turnon on neighbors
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do
local np = vector.add(f.pos, r)
-- area not loaded, postpone action
-- Neighboring node not loaded, postpone turning on current node
-- since we can't even know if neighboring node has matching rules
if not mesecon.get_node_force(np) then
mesecon.queue:add_action(np, "turnon", {rulename},
nil, true)
success = false
break
else
local links = mesecon.rules_link_rule_all(f.pos, r)
for _, l in ipairs(links) do
table.insert(frontiers, {pos = np, link = l})
neighborlinks[minetest.hash_node_position(np)] = mesecon.rules_link_rule_all(f.pos, r)
end
end
if success then
minetest.swap_node(f.pos, {name = mesecon.get_conductor_on(node, f.link),
param2 = node.param2})
for npos, l in pairs(neighborlinks) do
table.insert(frontiers, {pos = minetest.get_position_from_hash(npos), link = l})
end
else
mesecon.queue:add_action(f.pos, "turnon", {f.link}, nil, true)
end
elseif mesecon.is_effector(node.name) then
mesecon.changesignal(f.pos, node, f.link, mesecon.state.on, depth)
@ -427,27 +438,38 @@ function mesecon.turnoff(pos, link)
-- area not loaded, postpone action
if not node then
mesecon.queue:add_action(f.pos, "turnoff", {link}, nil, true)
mesecon.queue:add_action(f.pos, "turnoff", {f.link}, nil, true)
elseif mesecon.is_conductor_on(node, f.link) then
local rules = mesecon.conductor_get_rules(node)
minetest.swap_node(f.pos, {name = mesecon.get_conductor_off(node, f.link),
param2 = node.param2})
-- Success: If false, at least one neighboring node is unloaded,
-- postpone turning on action
local success = true
local neighborlinks = {}
-- call turnoff on neighbors: normal rules
-- call turnoff on neighbors
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do
local np = vector.add(f.pos, r)
-- area not loaded, postpone action
-- Neighboring node not loaded, postpone turning off current node
-- since we can't even know if neighboring node has matching rules
if not mesecon.get_node_force(np) then
mesecon.queue:add_action(np, "turnoff", {rulename},
nil, true)
success = false
break
else
local links = mesecon.rules_link_rule_all(f.pos, r)
for _, l in ipairs(links) do
table.insert(frontiers, {pos = np, link = l})
neighborlinks[minetest.hash_node_position(np)] = mesecon.rules_link_rule_all(f.pos, r)
end
end
if success then
minetest.swap_node(f.pos, {name = mesecon.get_conductor_off(node, f.link),
param2 = node.param2})
for npos, l in pairs(neighborlinks) do
table.insert(frontiers, {pos = minetest.get_position_from_hash(npos), link = l})
end
else
mesecon.queue:add_action(f.pos, "turnoff", {f.link}, nil, true)
end
elseif mesecon.is_effector(node.name) then
mesecon.changesignal(f.pos, node, f.link, mesecon.state.off, depth)