forked from Mirrorlandia_minetest/mesecons
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.
This commit is contained in:
parent
9736b0f61e
commit
aa8ad0fde9
@ -115,28 +115,34 @@ mesecon:register_on_signal_on(function(pos, node)
|
|||||||
--determine the number of nodes that need to be pushed
|
--determine the number of nodes that need to be pushed
|
||||||
local count = 0
|
local count = 0
|
||||||
local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
|
local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
|
||||||
|
while true do
|
||||||
local checknode = minetest.env:get_node(checkpos)
|
local checknode = minetest.env:get_node(checkpos)
|
||||||
while checknode.name ~= "air"
|
|
||||||
and checknode.name ~= "ignore"
|
--check for collision with stopper
|
||||||
and checknode.name ~= "default:water_source"
|
if mesecon:is_mvps_stopper(checknode.name) then
|
||||||
and checknode.name ~= "default:water_flowing"
|
return
|
||||||
and checknode.name ~= "default:lava_source"
|
end
|
||||||
and checknode.name ~= "default:lava_flowing" do
|
|
||||||
|
--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
|
--limit piston pushing capacity
|
||||||
count = count + 1
|
count = count + 1
|
||||||
if count > 15 then
|
if count > 15 then
|
||||||
return
|
return
|
||||||
end
|
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
|
checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
|
||||||
end
|
end
|
||||||
|
|
||||||
checknode = minetest.env:get_node(pos)
|
local checknode = minetest.env:get_node(pos)
|
||||||
minetest.env:dig_node(pos) --remove the first node
|
minetest.env:dig_node(pos) --remove the first node
|
||||||
|
|
||||||
--add pusher
|
--add pusher
|
||||||
@ -148,11 +154,11 @@ mesecon:register_on_signal_on(function(pos, node)
|
|||||||
|
|
||||||
--move nodes forward
|
--move nodes forward
|
||||||
for i = 1, count do
|
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 --move to the next node
|
||||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z
|
|
||||||
|
|
||||||
--move the node forward
|
--move the node forward
|
||||||
local nextnode = minetest.env:get_node(pos)
|
local nextnode = minetest.env:get_node(pos)
|
||||||
|
minetest.env:dig_node(pos)
|
||||||
minetest.env:place_node(pos, checknode)
|
minetest.env:place_node(pos, checknode)
|
||||||
checknode = nextnode
|
checknode = nextnode
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user