Cleanup and improve piston code

This commit is contained in:
Jeija
2012-12-16 11:58:43 +01:00
parent ae4bd1e21c
commit a1852204fb
5 changed files with 69 additions and 47 deletions

View File

@ -297,9 +297,7 @@ function mesecon:turnon(pos)
mesecon:turnon(np)
end
end
end
if mesecon:is_effector(node.name) then
elseif mesecon:is_effector(node.name) then
mesecon:changesignal(pos, node)
if mesecon:is_effector_off(node.name) then
mesecon:activate(pos, node)
@ -321,9 +319,7 @@ function mesecon:turnoff(pos)
mesecon:turnoff(np)
end
end
end
if mesecon:is_effector(node.name) then
elseif mesecon:is_effector(node.name) then
mesecon:changesignal(pos, node)
if mesecon:is_effector_on(node.name)
and not mesecon:is_powered(pos) then

View File

@ -8,6 +8,10 @@ mesecon.on_placenode = function (pos, node)
mesecon:changesignal(pos, node)
mesecon:activate(pos, node)
end
elseif mesecon:is_conductor_on(node.name) then
mesecon:swap_node(pos, mesecon:get_conductor_off(node.name))
elseif mesecon:is_effector_on (node.name) then
mesecon:deactivate(pos, node)
end
end

View File

@ -6,6 +6,15 @@ function mesecon:swap_node(pos, name)
minetest.env:get_meta(pos):from_table(data)
end
function mesecon:move_node(pos, newpos)
local node = minetest.env:get_node(pos)
local meta = minetest.env:get_meta(pos):to_table()
minetest.env:remove_node(pos)
minetest.env:add_node(newpos, node)
minetest.env:get_meta(pos):from_table(meta)
end
function mesecon:addPosRule(p, r)
return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z}
end

View File

@ -216,10 +216,10 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old)
if mesecon:rules_link_anydir(pos, zpympos) then zp = 1 end
if mesecon:rules_link_anydir(pos, zmympos) then zm = 1 end
if mesecon:rules_link(pos, xpypos) then xpy = 1 else xpy = 0 end
if mesecon:rules_link(pos, zpypos) then zpy = 1 else zpy = 0 end
if mesecon:rules_link(pos, xmypos) then xmy = 1 else xmy = 0 end
if mesecon:rules_link(pos, zmypos) then zmy = 1 else zmy = 0 end
if mesecon:rules_link_anydir(pos, xpypos) then xpy = 1 else xpy = 0 end
if mesecon:rules_link_anydir(pos, zpypos) then zpy = 1 else zpy = 0 end
if mesecon:rules_link_anydir(pos, xmypos) then xmy = 1 else xmy = 0 end
if mesecon:rules_link_anydir(pos, zmypos) then zmy = 1 else zmy = 0 end
if xpy == 1 then xp = 1 end
if zpy == 1 then zp = 1 end