summaryrefslogtreecommitdiff
path: root/mesecons_pistons
diff options
context:
space:
mode:
authorAnthony Zhang <azhang9@gmail.com>2012-10-02 17:09:39 -0400
committerAnthony Zhang <azhang9@gmail.com>2012-10-02 17:09:39 -0400
commitdcd2f94ba95a3cf9203de12e0b2e650494ef4e5c (patch)
tree72064ba1cbbe124ecdf24a1fa8e4d6f12c9c9f6f /mesecons_pistons
parentcd8fd55fe3bdc587a76094ab8830b0ea96e6bbfc (diff)
downloadmesecons-dcd2f94ba95a3cf9203de12e0b2e650494ef4e5c.tar
mesecons-dcd2f94ba95a3cf9203de12e0b2e650494ef4e5c.tar.gz
mesecons-dcd2f94ba95a3cf9203de12e0b2e650494ef4e5c.tar.bz2
mesecons-dcd2f94ba95a3cf9203de12e0b2e650494ef4e5c.tar.xz
mesecons-dcd2f94ba95a3cf9203de12e0b2e650494ef4e5c.zip
New pistons activation mechanism, fixes many of the issues reported when pushing mesecons around. Side effect is that it might be somewhat slower, and it waits a tiny delay before extending or retracting. This should be unnoticable in normal use.
Diffstat (limited to 'mesecons_pistons')
-rw-r--r--mesecons_pistons/init.lua102
1 files changed, 55 insertions, 47 deletions
diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua
index 3e3f75e..8436a0d 100644
--- a/mesecons_pistons/init.lua
+++ b/mesecons_pistons/init.lua
@@ -5,7 +5,7 @@ minetest.register_node("mesecons_pistons:piston_normal", {
tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_side.png"},
groups = {cracky=3, mesecon = 2},
paramtype2 = "facedir",
- after_dig_node = function(pos, oldnode)
+ after_destruct = function(pos, oldnode)
local dir = mesecon:piston_get_direction(oldnode)
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
@@ -17,6 +17,10 @@ minetest.register_node("mesecons_pistons:piston_normal", {
end
end
end,
+ on_timer = function(pos, elapsed)
+ mesecon:piston_push(pos, minetest.env:get_node(pos))
+ return false
+ end,
})
mesecon:register_effector("mesecons_pistons:piston_normal", "mesecons_pistons:piston_normal")
@@ -26,7 +30,7 @@ minetest.register_node("mesecons_pistons:piston_sticky", {
tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_sticky_side.png"},
groups = {cracky=3, mesecon = 2},
paramtype2 = "facedir",
- after_dig_node = function(pos, oldnode)
+ after_destruct = function(pos, oldnode)
local dir = mesecon:piston_get_direction(oldnode)
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
@@ -38,6 +42,10 @@ minetest.register_node("mesecons_pistons:piston_sticky", {
end
end
end,
+ on_timer = function(pos, elapsed)
+ mesecon:piston_push(pos, minetest.env:get_node(pos))
+ return false
+ end,
})
mesecon:register_effector("mesecons_pistons:piston_sticky", "mesecons_pistons:piston_sticky")
@@ -80,9 +88,6 @@ minetest.register_node("mesecons_pistons:piston_pusher_normal", {
},
})
-mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal")
-mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky")
-
minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
drawtype = "nodebox",
tiles = {
@@ -112,12 +117,55 @@ minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
},
})
+mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal")
+mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky")
+
-- Push action
mesecon:register_on_signal_on(function(pos, node)
if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
return
end
+ local timer = minetest.env:get_node_timer(pos)
+ timer:set(1.0, 0)
+end)
+
+--Pull action
+mesecon:register_on_signal_off(function(pos, node)
+ if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
+ return
+ end
+
+ local dir = mesecon:piston_get_direction(node)
+ pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the node to be replaced
+
+ --ensure piston is extended
+ local checknode = minetest.env:get_node(pos)
+ if checknode.name ~= "mesecons_pistons:piston_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_pusher_sticky" then
+ return
+ end
+ if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
+ return --piston is not extended
+ end
+
+ --retract piston
+ minetest.env:remove_node(pos) --remove pusher
+ if node.name == "mesecons_pistons:piston_sticky" then --retract block
+ local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
+ checknode = minetest.env:get_node(checkpos)
+ if checknode.name ~= "air"
+ and checknode.name ~= "ignore"
+ and minetest.registered_nodes[checknode.name].liquidtype == "none"
+ and not mesecon:is_mvps_stopper(checknode.name) then
+ minetest.env:set_node(pos, checknode)
+ minetest.env:remove_node(checkpos)
+ mesecon:updatenode(checkpos)
+ end
+ end
+ nodeupdate(pos)
+end)
+
+function mesecon:piston_push(pos, node)
local dir = mesecon:piston_get_direction(node)
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node being pushed
@@ -170,49 +218,9 @@ mesecon:register_on_signal_on(function(pos, node)
mesecon:updatenode(pos)
checknode = nextnode
end
-end)
-
---Pull action
-mesecon:register_on_signal_off(function(pos, node)
- if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
- return
- end
-
- local dir = mesecon:piston_get_direction(node)
- pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the node to be replaced
-
- --ensure piston is extended
- local checknode = minetest.env:get_node(pos)
- if checknode.name ~= "mesecons_pistons:piston_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_pusher_sticky" then
- return
- end
- if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
- return --piston is not extended
- end
-
- --retract piston
- minetest.env:remove_node(pos) --remove pusher
- if node.name ~= "mesecons_pistons:piston_sticky" then
- nodeupdate(pos)
- end
- if node.name == "mesecons_pistons:piston_sticky" then --retract block
- local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
- checknode = minetest.env:get_node(checkpos)
- if checknode.name ~= "air"
- and checknode.name ~= "ignore"
- and minetest.registered_nodes[checknode.name].liquidtype == "none"
- and not mesecon:is_mvps_stopper(checknode.name) then
- minetest.env:set_node(pos, checknode)
- minetest.env:remove_node(checkpos)
- mesecon:updatenode(checkpos)
- end
- end
- if node.name == "mesecons_pistons:piston_sticky" then
- nodeupdate(pos)
- end
-end)
+end
--- get push direction
+-- get piston direction
function mesecon:piston_get_direction(node)
if node.param2 == 3 then
return {x=1, y=0, z=0}