forked from Mirrorlandia_minetest/mesecons
Fix #276: Fix bugs in block forceloading in turnon / turnoff
Thanks to @Hawk777 for reporting this problem
This commit is contained in:
parent
acd41b5773
commit
7c7595fd7d
@ -381,27 +381,38 @@ function mesecon.turnon(pos, link)
|
|||||||
|
|
||||||
-- area not loaded, postpone action
|
-- area not loaded, postpone action
|
||||||
if not node then
|
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
|
elseif mesecon.is_conductor_off(node, f.link) then
|
||||||
local rules = mesecon.conductor_get_rules(node)
|
local rules = mesecon.conductor_get_rules(node)
|
||||||
|
|
||||||
minetest.swap_node(f.pos, {name = mesecon.get_conductor_on(node, f.link),
|
-- Success: If false, at least one neighboring node is unloaded,
|
||||||
param2 = node.param2})
|
-- 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
|
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do
|
||||||
local np = vector.add(f.pos, r)
|
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
|
if not mesecon.get_node_force(np) then
|
||||||
mesecon.queue:add_action(np, "turnon", {rulename},
|
success = false
|
||||||
nil, true)
|
break
|
||||||
else
|
else
|
||||||
local links = mesecon.rules_link_rule_all(f.pos, r)
|
neighborlinks[minetest.hash_node_position(np)] = mesecon.rules_link_rule_all(f.pos, r)
|
||||||
for _, l in ipairs(links) do
|
|
||||||
table.insert(frontiers, {pos = np, link = l})
|
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
elseif mesecon.is_effector(node.name) then
|
elseif mesecon.is_effector(node.name) then
|
||||||
mesecon.changesignal(f.pos, node, f.link, mesecon.state.on, depth)
|
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
|
-- area not loaded, postpone action
|
||||||
if not node then
|
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
|
elseif mesecon.is_conductor_on(node, f.link) then
|
||||||
local rules = mesecon.conductor_get_rules(node)
|
local rules = mesecon.conductor_get_rules(node)
|
||||||
|
|
||||||
minetest.swap_node(f.pos, {name = mesecon.get_conductor_off(node, f.link),
|
-- Success: If false, at least one neighboring node is unloaded,
|
||||||
param2 = node.param2})
|
-- 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
|
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do
|
||||||
local np = vector.add(f.pos, r)
|
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
|
if not mesecon.get_node_force(np) then
|
||||||
mesecon.queue:add_action(np, "turnoff", {rulename},
|
success = false
|
||||||
nil, true)
|
break
|
||||||
else
|
else
|
||||||
local links = mesecon.rules_link_rule_all(f.pos, r)
|
neighborlinks[minetest.hash_node_position(np)] = mesecon.rules_link_rule_all(f.pos, r)
|
||||||
for _, l in ipairs(links) do
|
|
||||||
table.insert(frontiers, {pos = np, link = l})
|
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
elseif mesecon.is_effector(node.name) then
|
elseif mesecon.is_effector(node.name) then
|
||||||
mesecon.changesignal(f.pos, node, f.link, mesecon.state.off, depth)
|
mesecon.changesignal(f.pos, node, f.link, mesecon.state.off, depth)
|
||||||
|
Loading…
Reference in New Issue
Block a user