forked from Mirrorlandia_minetest/mesecons
Nodebox piston pushers! Fix a few piston bugs such as pistons pushing pistons, pistons pushing blocks into pushers causing blocks to get deleted, and many more. As a side effect, players can no longer simply walk through piston pushers. Additionally, pistons will only remove their own pushers, and not those of neighboring pistons as well. Remove ENABLE_PISTON_ANIMATION option (not compatible with nodebox piston pushers).
This commit is contained in:
parent
d3a4c2cb34
commit
9736b0f61e
@ -1,4 +1,3 @@
|
|||||||
-- SETTINGS
|
-- SETTINGS
|
||||||
ENABLE_PISTON_ANIMATION=true
|
|
||||||
BLINKY_PLANT_INTERVAL=3
|
BLINKY_PLANT_INTERVAL=3
|
||||||
ENABLE_TEMPEREST=true
|
ENABLE_TEMPEREST=false
|
||||||
|
@ -1,18 +1,42 @@
|
|||||||
--PISTONS
|
--PISTONS
|
||||||
--registration normal one:
|
--registration normal one:
|
||||||
minetest.register_node("mesecons_pistons:piston_normal", {
|
minetest.register_node("mesecons_pistons:piston_normal", {
|
||||||
|
description = "Piston",
|
||||||
tile_images = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_side.png"},
|
tile_images = {"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},
|
groups = {cracky=3},
|
||||||
paramtype2="facedir",
|
paramtype2 = "facedir",
|
||||||
description="Piston",
|
after_dig_node = function(pos, oldnode)
|
||||||
after_dig_node = function(pos)
|
local dir = mesecon:piston_get_direction(oldnode)
|
||||||
local objs = minetest.env:get_objects_inside_radius(pos, 2)
|
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
|
||||||
for k, obj in pairs(objs) do
|
|
||||||
if obj:get_entity_name() == "mesecons_pistons:piston_pusher_normal" then
|
--ensure piston is extended
|
||||||
obj:remove()
|
local checknode = minetest.env:get_node(pos)
|
||||||
|
if checknode.name == "mesecons_pistons:piston_pusher_normal" then
|
||||||
|
if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
|
||||||
|
minetest.env:remove_node(pos) --remove the pusher
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
--registration sticky one:
|
||||||
|
minetest.register_node("mesecons_pistons:piston_sticky", {
|
||||||
|
description = "Sticky Piston",
|
||||||
|
tile_images = {"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},
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
after_dig_node = 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
|
||||||
|
|
||||||
|
--ensure piston is extended
|
||||||
|
local checknode = minetest.env:get_node(pos)
|
||||||
|
if checknode.name == "mesecons_pistons:piston_pusher_sticky" then
|
||||||
|
if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
|
||||||
|
minetest.env:remove_node(pos) --remove the pusher
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
@ -24,22 +48,6 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
--registration sticky one:
|
|
||||||
minetest.register_node("mesecons_pistons:piston_sticky", {
|
|
||||||
tile_images = {"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},
|
|
||||||
paramtype2="facedir",
|
|
||||||
description="Sticky Piston",
|
|
||||||
after_dig_node = function(pos)
|
|
||||||
local objs = minetest.env:get_objects_inside_radius(pos, 2)
|
|
||||||
for k, obj in pairs(objs) do
|
|
||||||
if obj:get_entity_name() == "mesecons_pistons:piston_pusher_sticky" then
|
|
||||||
obj:remove()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "mesecons_pistons:piston_sticky",
|
output = "mesecons_pistons:piston_sticky",
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -48,31 +56,65 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
-- get push direction
|
minetest.register_node("mesecons_pistons:piston_pusher_normal", {
|
||||||
function mesecon:piston_get_direction(pos)
|
drawtype = "nodebox",
|
||||||
local param2 = minetest.env:get_node(pos).param2
|
tile_images = {"jeija_piston_pusher_normal.png"},
|
||||||
if param2 == 3 then
|
paramtype = "light",
|
||||||
return {x=1, y=0, z=0}
|
paramtype2 = "facedir",
|
||||||
elseif param2 == 2 then
|
diggable = false,
|
||||||
return {x=0, y=0, z=1}
|
selection_box = {
|
||||||
elseif param2 == 1 then
|
type = "fixed",
|
||||||
return {x=-1, y=0, z=0}
|
fixed = {
|
||||||
else --param2 == 0
|
{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
|
||||||
return {x=0, y=0, z=-1}
|
{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
|
||||||
end
|
},
|
||||||
end
|
},
|
||||||
|
node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {
|
||||||
|
{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
|
||||||
|
{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
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",
|
||||||
|
tile_images = {"jeija_piston_pusher_sticky.png"},
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
diggable = false,
|
||||||
|
selection_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {
|
||||||
|
{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
|
||||||
|
{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {
|
||||||
|
{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
|
||||||
|
{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
-- Push action
|
-- Push action
|
||||||
mesecon:register_on_signal_on(function (pos, node)
|
mesecon:register_on_signal_on(function(pos, node)
|
||||||
if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
|
if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local dir = mesecon:piston_get_direction(pos)
|
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
|
||||||
|
|
||||||
--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 + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --first node being pushed
|
local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
|
||||||
local checknode = minetest.env:get_node(checkpos)
|
local checknode = minetest.env:get_node(checkpos)
|
||||||
while checknode.name ~= "air"
|
while checknode.name ~= "air"
|
||||||
and checknode.name ~= "ignore"
|
and checknode.name ~= "ignore"
|
||||||
@ -87,32 +129,24 @@ mesecon:register_on_signal_on(function (pos, node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--check for collision with stopper
|
--check for collision with stopper
|
||||||
checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
|
|
||||||
checknode = minetest.env:get_node(checkpos)
|
checknode = minetest.env:get_node(checkpos)
|
||||||
if mesecon:is_mvps_stopper(checknode.name) then
|
if mesecon:is_mvps_stopper(checknode.name) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
|
||||||
end
|
end
|
||||||
|
|
||||||
--add pusher entity
|
checknode = minetest.env:get_node(pos)
|
||||||
local object
|
minetest.env:dig_node(pos) --remove the first node
|
||||||
if node.name == "mesecons_pistons:piston_normal" then --normal piston
|
|
||||||
object = minetest.env:add_entity(pos, "mesecons_pistons:piston_pusher_normal")
|
|
||||||
else --sticky piston
|
|
||||||
object = minetest.env:add_entity(pos, "mesecons_pistons:piston_pusher_sticky")
|
|
||||||
end
|
|
||||||
|
|
||||||
--move pusher forward
|
--add pusher
|
||||||
if ENABLE_PISTON_ANIMATION then
|
if node.name == "mesecons_pistons:piston_normal" then
|
||||||
object:setvelocity({x=dir.x * 4, y=dir.y * 4, z=dir.z * 4})
|
minetest.env:add_node(pos, {name="mesecons_pistons:piston_pusher_normal", param2=node.param2})
|
||||||
else
|
else
|
||||||
object:moveto(pos, false)
|
minetest.env:add_node(pos, {name="mesecons_pistons:piston_pusher_sticky", param2=node.param2})
|
||||||
end
|
end
|
||||||
|
|
||||||
--move nodes forward
|
--move nodes forward
|
||||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node being pushed
|
|
||||||
checknode = minetest.env:get_node(pos)
|
|
||||||
minetest.env:dig_node(pos) --remove the first node
|
|
||||||
for i = 1, count do
|
for i = 1, count do
|
||||||
--move to the next node
|
--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
|
||||||
@ -126,78 +160,49 @@ end)
|
|||||||
|
|
||||||
--Pull action (sticky only)
|
--Pull action (sticky only)
|
||||||
mesecon:register_on_signal_off(function(pos, node)
|
mesecon:register_on_signal_off(function(pos, node)
|
||||||
if node.name ~= "mesecons_pistons:piston_sticky" and node.name ~= "mesecons_pistons:piston_normal" then
|
if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--remove piston pusher
|
local dir = mesecon:piston_get_direction(node)
|
||||||
local found = false --whether or not the piston was extended
|
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
|
||||||
local objects = minetest.env:get_objects_inside_radius(pos, 2)
|
|
||||||
for k, object in pairs(objects) do
|
--ensure piston is extended
|
||||||
local name = object:get_luaentity().name
|
local checknode = minetest.env:get_node(pos)
|
||||||
if name == "mesecons_pistons:piston_pusher_normal" or name == "mesecons_pistons:piston_pusher_sticky" then
|
if checknode.name ~= "mesecons_pistons:piston_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_pusher_sticky" then
|
||||||
found = true
|
return
|
||||||
object:remove()
|
end
|
||||||
end
|
if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
|
||||||
|
return --piston is not extended
|
||||||
end
|
end
|
||||||
|
|
||||||
--retract piston
|
--retract piston
|
||||||
if found and node.name == "mesecons_pistons:piston_sticky" then
|
minetest.env:remove_node(pos) --remove pusher
|
||||||
local dir = mesecon:piston_get_direction(pos)
|
if node.name == "mesecons_pistons:piston_sticky" then --retract block
|
||||||
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
|
local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
|
||||||
local checknode = minetest.env:get_node(pos)
|
checknode = minetest.env:get_node(checkpos)
|
||||||
if checknode.name == "air"
|
if checknode.name ~= "air"
|
||||||
or checknode.name == "default:water_source"
|
and checknode.name ~= "ignore"
|
||||||
or checknode.name == "default:water_flowing"
|
and checknode.name ~= "default:water_source"
|
||||||
or checknode.name == "default:lava_source"
|
and checknode.name ~= "default:water_flowing"
|
||||||
or checknode.name == "default:lava_flowing" then
|
and checknode.name ~= "default:lava_source"
|
||||||
local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
|
and checknode.name ~= "default:lava_flowing"
|
||||||
local checknode = minetest.env:get_node(checkpos)
|
and not mesecon:is_mvps_stopper(checknode.name) then
|
||||||
if checknode.name ~= "air"
|
minetest.env:place_node(pos, checknode)
|
||||||
and checknode.name ~= "ignore"
|
minetest.env:dig_node(checkpos)
|
||||||
and checknode.name ~= "default:water_source"
|
|
||||||
and checknode.name ~= "default:water_flowing"
|
|
||||||
and checknode.name ~= "default:lava_source"
|
|
||||||
and checknode.name ~= "default:lava_flowing" then
|
|
||||||
minetest.env:place_node(pos, checknode)
|
|
||||||
minetest.env:dig_node(checkpos)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--Piston Animation
|
-- get push direction
|
||||||
local PISTON_PUSHER_NORMAL = {
|
function mesecon:piston_get_direction(node)
|
||||||
physical = false,
|
if node.param2 == 3 then
|
||||||
visual = "sprite",
|
return {x=1, y=0, z=0}
|
||||||
textures = {"default_wood.png", "default_wood.png", "jeija_piston_pusher_normal.png", "jeija_piston_pusher_normal.png", "jeija_piston_pusher_normal.png", "jeija_piston_pusher_normal.png"},
|
elseif node.param2 == 2 then
|
||||||
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
return {x=0, y=0, z=1}
|
||||||
visual = "cube",
|
elseif node.param2 == 1 then
|
||||||
timer=0,
|
return {x=-1, y=0, z=0}
|
||||||
}
|
else --node.param2 == 0
|
||||||
|
return {x=0, y=0, z=-1}
|
||||||
function PISTON_PUSHER_NORMAL:on_step(dtime)
|
|
||||||
self.timer = self.timer+dtime
|
|
||||||
if self.timer >= 0.24 then
|
|
||||||
self.object:setvelocity({x=0, y=0, z=0})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local PISTON_PUSHER_STICKY = {
|
|
||||||
physical = false,
|
|
||||||
visual = "sprite",
|
|
||||||
textures = {"default_wood.png", "default_wood.png", "jeija_piston_pusher_sticky.png", "jeija_piston_pusher_sticky.png", "jeija_piston_pusher_sticky.png", "jeija_piston_pusher_sticky.png"},
|
|
||||||
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
|
||||||
visual = "cube",
|
|
||||||
timer = 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
function PISTON_PUSHER_STICKY:on_step(dtime)
|
|
||||||
self.timer=self.timer+dtime
|
|
||||||
if self.timer >= 0.24 then
|
|
||||||
self.object:setvelocity({x=0, y=0, z=0})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_entity("mesecons_pistons:piston_pusher_normal", PISTON_PUSHER_NORMAL)
|
|
||||||
minetest.register_entity("mesecons_pistons:piston_pusher_sticky", PISTON_PUSHER_STICKY)
|
|
Loading…
Reference in New Issue
Block a user