summaryrefslogtreecommitdiff
path: root/mesecons_pistons/init.lua
diff options
context:
space:
mode:
authorAnthony Zhang <azhang9@gmail.com>2012-07-20 22:15:49 -0400
committerAnthony Zhang <azhang9@gmail.com>2012-07-20 22:15:49 -0400
commitaa8ad0fde97a8dcfcd51027dee65174dc830fbc5 (patch)
treef028679eab3d3e5060199d3c40ffed3b3b8b730f /mesecons_pistons/init.lua
parent9736b0f61ea71d87707c7209326abf52a8d4eda9 (diff)
downloadmesecons-aa8ad0fde97a8dcfcd51027dee65174dc830fbc5.tar
mesecons-aa8ad0fde97a8dcfcd51027dee65174dc830fbc5.tar.gz
mesecons-aa8ad0fde97a8dcfcd51027dee65174dc830fbc5.tar.bz2
mesecons-aa8ad0fde97a8dcfcd51027dee65174dc830fbc5.tar.xz
mesecons-aa8ad0fde97a8dcfcd51027dee65174dc830fbc5.zip
Fix off-by-one error in piston length calculation and change the node pushing to make use of the fact that minetest.env:place_node() is apparently a no-op if the node is not air or liquid.
Diffstat (limited to 'mesecons_pistons/init.lua')
-rw-r--r--mesecons_pistons/init.lua36
1 files changed, 21 insertions, 15 deletions
diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua
index a484dfd..b3269bc 100644
--- a/mesecons_pistons/init.lua
+++ b/mesecons_pistons/init.lua
@@ -115,28 +115,34 @@ mesecon:register_on_signal_on(function(pos, node)
--determine the number of nodes that need to be pushed
local count = 0
local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
- local checknode = minetest.env:get_node(checkpos)
- while checknode.name ~= "air"
- and checknode.name ~= "ignore"
- and checknode.name ~= "default:water_source"
- and checknode.name ~= "default:water_flowing"
- and checknode.name ~= "default:lava_source"
- and checknode.name ~= "default:lava_flowing" do
+ while true do
+ local checknode = minetest.env:get_node(checkpos)
+
+ --check for collision with stopper
+ if mesecon:is_mvps_stopper(checknode.name) then
+ return
+ end
+
+ --check for column end
+ if checknode.name == "air"
+ or checknode.name == "ignore"
+ or checknode.name == "default:water_source"
+ or checknode.name == "default:water_flowing"
+ or checknode.name == "default:lava_source"
+ or checknode.name == "default:lava_flowing" then
+ break
+ end
+
--limit piston pushing capacity
count = count + 1
if count > 15 then
return
end
- --check for collision with stopper
- checknode = minetest.env:get_node(checkpos)
- if mesecon:is_mvps_stopper(checknode.name) then
- return
- end
checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
end
- checknode = minetest.env:get_node(pos)
+ local checknode = minetest.env:get_node(pos)
minetest.env:dig_node(pos) --remove the first node
--add pusher
@@ -148,11 +154,11 @@ mesecon:register_on_signal_on(function(pos, node)
--move nodes forward
for i = 1, count do
- --move to the next node
- pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z
+ pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the next node
--move the node forward
local nextnode = minetest.env:get_node(pos)
+ minetest.env:dig_node(pos)
minetest.env:place_node(pos, checknode)
checknode = nextnode
end