Change the jammer mesecons functions overriding (see https://gist.github.com/HybridDog/45ddedf3cb33db330815)

This commit is contained in:
paly2 2015-12-23 14:36:07 +01:00
parent f59def1aa1
commit 6a8c6574f5

View File

@ -36,49 +36,41 @@ local function is_jammed(pos)
return false return false
end end
minetest.after(0, function() -- After load all mods minetest.after(0, function() -- After load all mods, override some functions
function mesecon.turnon(pos, link) -- Overwrite mesecons function. local current_pos
local frontiers = {{pos = pos, link = link}}
local depth = 1 local actual_node_get = minetest.get_node_or_nil
while frontiers[depth] do local function temp_node_get(pos, ...)
local f = frontiers[depth] current_pos = pos
local node = minetest.get_node_or_nil(f.pos) return actual_node_get(pos, ...)
end
-- area not loaded, postpone action local actual_turnon = mesecon.turnon
if not node then function mesecon.turnon(...)
mesecon.queue:add_action(f.pos, "turnon", {link}, nil, true) minetest.get_node_or_nil = temp_node_get
elseif is_jammed(f.pos) then -- JAMMER --local v = actual_turnon(pos, ...) commented because mesecon.turnon now doesn't return sth
return actual_turnon(...)
elseif mesecon.is_conductor_off(node, f.link) then minetest.get_node_or_nil = actual_node_get
local rules = mesecon.conductor_get_rules(node) current_pos = nil
--return v
end
minetest.swap_node(f.pos, {name = mesecon.get_conductor_on(node, f.link), local actual_is_conductor_off = mesecon.is_conductor_off
param2 = node.param2}) function mesecon.is_conductor_off(...)
if current_pos
-- call turnon on neighbors: normal rules and is_jammed(current_pos) then
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do return
local np = mesecon.addPosRule(f.pos, r)
-- area not loaded, postpone action
if not minetest.get_node_or_nil(np) then
mesecon.queue:add_action(np, "turnon", {rulename},
nil, true)
else
local links = mesecon.rules_link_rule_all(f.pos, r)
for _, l in ipairs(links) do
table.insert(frontiers, {pos = np, link = l})
end
end
end
elseif mesecon.is_effector(node.name) then
mesecon.changesignal(f.pos, node, f.link, mesecon.state.on, depth)
if mesecon.is_effector_off(node.name) then
mesecon.activate(f.pos, node, f.link, depth)
end
end
depth = depth + 1
end end
return actual_is_conductor_off(...)
end
local actual_is_effector = mesecon.is_effector
function mesecon.is_effector(...)
if current_pos
and is_jammed(current_pos) then
return
end
return actual_is_effector(...)
end end
end) end)