diff options
author | Jeija <norrepli@gmail.com> | 2012-12-16 11:58:43 +0100 |
---|---|---|
committer | Jeija <norrepli@gmail.com> | 2012-12-16 11:58:43 +0100 |
commit | a1852204fbc2bd056f3286f316c94076d5fd7e2b (patch) | |
tree | d22f0e97a9100088cc0557360b4662a9498ef192 /mesecons | |
parent | ae4bd1e21c2c79f0925beff6a8952a8a2fb16220 (diff) | |
download | mesecons-a1852204fbc2bd056f3286f316c94076d5fd7e2b.tar mesecons-a1852204fbc2bd056f3286f316c94076d5fd7e2b.tar.gz mesecons-a1852204fbc2bd056f3286f316c94076d5fd7e2b.tar.bz2 mesecons-a1852204fbc2bd056f3286f316c94076d5fd7e2b.tar.xz mesecons-a1852204fbc2bd056f3286f316c94076d5fd7e2b.zip |
Cleanup and improve piston code
Diffstat (limited to 'mesecons')
-rw-r--r-- | mesecons/internal.lua | 8 | ||||
-rw-r--r-- | mesecons/services.lua | 4 | ||||
-rw-r--r-- | mesecons/util.lua | 9 | ||||
-rw-r--r-- | mesecons/wires.lua | 8 |
4 files changed, 19 insertions, 10 deletions
diff --git a/mesecons/internal.lua b/mesecons/internal.lua index 419a337..bde0593 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -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 diff --git a/mesecons/services.lua b/mesecons/services.lua index c82e06b..ada9351 100644 --- a/mesecons/services.lua +++ b/mesecons/services.lua @@ -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 diff --git a/mesecons/util.lua b/mesecons/util.lua index b95cf6e..2871c0a 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -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 diff --git a/mesecons/wires.lua b/mesecons/wires.lua index f5c0f3b..6c5f6ef 100644 --- a/mesecons/wires.lua +++ b/mesecons/wires.lua @@ -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 |