forked from Mirrorlandia_minetest/mesecons
Fix piston duplication bug, simplify piston handling, limit piston push distance to 15 blocks. Remove deprecated object:get_entity_name() call, and some obselete settings.
This commit is contained in:
parent
04bcc458d9
commit
64a452da24
@ -1,5 +1,4 @@
|
|||||||
-- SETTINGS
|
-- SETTINGS
|
||||||
ENABLE_PISTON_ANIMATION=0
|
ENABLE_PISTON_ANIMATION=true
|
||||||
BLINKY_PLANT_INTERVAL=3
|
BLINKY_PLANT_INTERVAL=3
|
||||||
OLD_PISTON_DIRECTION=0
|
ENABLE_TEMPEREST=true
|
||||||
ENABLE_TEMPEREST=1
|
|
||||||
|
@ -41,208 +41,133 @@ minetest.register_node("mesecons_pistons:piston_sticky", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = '"mesecons_pistons:piston_sticky" 1',
|
output = "mesecons_pistons:piston_sticky",
|
||||||
recipe = {
|
recipe = {
|
||||||
{'"mesecons_materials:glue"'},
|
{"mesecons_materials:glue"},
|
||||||
{'"mesecons_pistons:piston_normal"'},
|
{"mesecons_pistons:piston_normal"},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
-- get push direction normal
|
-- get push direction
|
||||||
function mesecon:piston_get_direction(pos)
|
function mesecon:piston_get_direction(pos)
|
||||||
local direction = {x=0, y=0, z=0}
|
local param2 = minetest.env:get_node(pos).param2
|
||||||
if OLD_PISTON_DIRECTION==1 then
|
if param2 == 3 then
|
||||||
getactivated=0
|
return {x=1, y=0, z=0}
|
||||||
local lpos={x=pos.x, y=pos.y, z=pos.z}
|
elseif param2 == 2 then
|
||||||
local getactivated=0
|
return {x=0, y=0, z=1}
|
||||||
local rules=mesecon:get_rules("piston")
|
elseif param2 == 1 then
|
||||||
|
return {x=-1, y=0, z=0}
|
||||||
getactivated=getactivated+mesecon:is_power_on(pos, rules[1].x, rules[1].y, rules[1].z)
|
else --param2 == 0
|
||||||
if getactivated>0 then direction.y=-1 return direction end
|
return {x=0, y=0, z=-1}
|
||||||
getactivated=getactivated+mesecon:is_power_on(pos, rules[2].x, rules[2].y, rules[2].z)
|
|
||||||
if getactivated>0 then direction.y=1 return direction end
|
|
||||||
for k=3, 5 do
|
|
||||||
getactivated=getactivated+mesecon:is_power_on(pos, rules[k].x, rules[k].y, rules[k].z)
|
|
||||||
end
|
|
||||||
if getactivated>0 then direction.z=1 return direction end
|
|
||||||
|
|
||||||
for n=6, 8 do
|
|
||||||
getactivated=getactivated+mesecon:is_power_on(pos, rules[n].x, rules[n].y, rules[n].z)
|
|
||||||
end
|
|
||||||
|
|
||||||
if getactivated>0 then direction.z=-1 return direction end
|
|
||||||
|
|
||||||
for j=9, 11 do
|
|
||||||
getactivated=getactivated+mesecon:is_power_on(pos, rules[j].x, rules[j].y, rules[j].z)
|
|
||||||
end
|
|
||||||
|
|
||||||
if getactivated>0 then direction.x=-1 return direction end
|
|
||||||
|
|
||||||
for l=12, 14 do
|
|
||||||
getactivated=getactivated+mesecon:is_power_on(pos, rules[l].x, rules[l].y, rules[l].z)
|
|
||||||
end
|
|
||||||
if getactivated>0 then direction.x=1 return direction end
|
|
||||||
else
|
|
||||||
local node=minetest.env:get_node(pos)
|
|
||||||
if node.param2==3 then
|
|
||||||
return {x=1, y=0, z=0}
|
|
||||||
end
|
|
||||||
if node.param2==2 then
|
|
||||||
return {x=0, y=0, z=1}
|
|
||||||
end
|
|
||||||
if node.param2==1 then
|
|
||||||
return {x=-1, y=0, z=0}
|
|
||||||
end
|
|
||||||
if node.param2==0 then
|
|
||||||
return {x=0, y=0, z=-1}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return direction
|
|
||||||
end
|
|
||||||
|
|
||||||
-- get pull/push direction sticky
|
|
||||||
function mesecon:sticky_piston_get_direction(pos)
|
|
||||||
if OLD_PISTON_DIRECTION==1 then
|
|
||||||
getactivated=0
|
|
||||||
local direction = {x=0, y=0, z=0}
|
|
||||||
local lpos={x=pos.x, y=pos.y, z=pos.z}
|
|
||||||
local getactivated=0
|
|
||||||
local rules=mesecon:get_rules("piston")
|
|
||||||
|
|
||||||
getactivated=getactivated+mesecon:is_power_off(pos, rules[1].x, rules[1].y, rules[1].z)
|
|
||||||
if getactivated>0 then direction.y=-1 return direction end
|
|
||||||
getactivated=getactivated+mesecon:is_power_off(pos, rules[2].x, rules[2].y, rules[2].z)
|
|
||||||
if getactivated>0 then direction.y=1 return direction end
|
|
||||||
|
|
||||||
for k=3, 5 do
|
|
||||||
getactivated=getactivated+mesecon:is_power_off(pos, rules[k].x, rules[k].y, rules[k].z)
|
|
||||||
end
|
|
||||||
if getactivated>0 then direction.z=1 return direction end
|
|
||||||
|
|
||||||
for n=6, 8 do
|
|
||||||
getactivated=getactivated+mesecon:is_power_off(pos, rules[n].x, rules[n].y, rules[n].z)
|
|
||||||
end
|
|
||||||
|
|
||||||
if getactivated>0 then direction.z=-1 return direction end
|
|
||||||
|
|
||||||
for j=9, 11 do
|
|
||||||
getactivated=getactivated+mesecon:is_power_off(pos, rules[j].x, rules[j].y, rules[j].z)
|
|
||||||
end
|
|
||||||
|
|
||||||
if getactivated>0 then direction.x=-1 return direction end
|
|
||||||
|
|
||||||
for l=12, 14 do
|
|
||||||
getactivated=getactivated+mesecon:is_power_off(pos, rules[l].x, rules[l].y, rules[l].z)
|
|
||||||
end
|
|
||||||
if getactivated>0 then direction.x=1 return direction end
|
|
||||||
else
|
|
||||||
local node=minetest.env:get_node(pos)
|
|
||||||
if node.param2==3 then
|
|
||||||
return {x=1, y=0, z=0}
|
|
||||||
end
|
|
||||||
if node.param2==2 then
|
|
||||||
return {x=0, y=0, z=1}
|
|
||||||
end
|
|
||||||
if node.param2==1 then
|
|
||||||
return {x=-1, y=0, z=0}
|
|
||||||
end
|
|
||||||
if node.param2==0 then
|
|
||||||
return {x=0, y=0, z=-1}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return direction
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 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" or node.name=="mesecons_pistons:piston_sticky") then
|
if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
|
||||||
local direction=mesecon:piston_get_direction(pos)
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local checknode={}
|
local dir = mesecon:piston_get_direction(pos)
|
||||||
local checkpos={x=pos.x, y=pos.y, z=pos.z}
|
|
||||||
repeat -- Check if it collides with a stopper
|
|
||||||
checkpos={x=checkpos.x+direction.x, y=checkpos.y+direction.y, z=checkpos.z+direction.z}
|
|
||||||
checknode=minetest.env:get_node(checkpos)
|
|
||||||
if mesecon:is_mvps_stopper(checknode.name) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
until checknode.name=="air"
|
|
||||||
or checknode.name=="ignore"
|
|
||||||
or checknode.name=="default:water"
|
|
||||||
or checknode.name=="default:water_flowing"
|
|
||||||
|
|
||||||
local obj={}
|
--determine the number of nodes that need to be pushed
|
||||||
if node.name=="mesecons_pistons:piston_normal" then
|
local count = 0
|
||||||
obj=minetest.env:add_entity(pos, "mesecons_pistons:piston_pusher_normal")
|
local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --first node being pushed
|
||||||
elseif node.name=="mesecons_pistons:piston_sticky" then
|
local checknode = minetest.env:get_node(checkpos)
|
||||||
obj=minetest.env:add_entity(pos, "mesecons_pistons:piston_pusher_sticky")
|
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
|
||||||
|
--limit piston pushing capacity
|
||||||
|
count = count + 1
|
||||||
|
if count > 15 then
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if ENABLE_PISTON_ANIMATION==1 then
|
|
||||||
obj:setvelocity({x=direction.x*4, y=direction.y*4, z=direction.z*4})
|
|
||||||
else
|
|
||||||
obj:moveto({x=pos.x+direction.x, y=pos.y+direction.y, z=pos.z+direction.z}, false)
|
|
||||||
end
|
|
||||||
|
|
||||||
local np = {x=pos.x+direction.x, y=pos.y+direction.y, z=pos.z+direction.z}
|
|
||||||
local coln = minetest.env:get_node(np)
|
|
||||||
|
|
||||||
or checknode.name=="ignore"
|
|
||||||
or checknode.name=="default:water"
|
|
||||||
or checknode.name=="default:water_flowing"
|
|
||||||
|
|
||||||
if coln.name ~= "air" and coln.name ~="water" then
|
--check for collision with stopper
|
||||||
local thisp= {x=np.x, y=np.y, z=np.z}
|
checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
|
||||||
local thisnode=minetest.env:get_node(thisp)
|
checknode = minetest.env:get_node(checkpos)
|
||||||
local nextnode={}
|
if mesecon:is_mvps_stopper(checknode.name) then
|
||||||
minetest.env:dig_node(thisp)
|
return
|
||||||
repeat
|
|
||||||
thisp.x=thisp.x+direction.x
|
|
||||||
thisp.y=thisp.y+direction.y
|
|
||||||
thisp.z=thisp.z+direction.z
|
|
||||||
nextnode=minetest.env:get_node(thisp)
|
|
||||||
minetest.env:place_node(thisp, {name=thisnode.name})
|
|
||||||
nodeupdate(thisp)
|
|
||||||
thisnode=nextnode
|
|
||||||
until thisnode.name=="air"
|
|
||||||
or thisnode.name=="ignore"
|
|
||||||
or thisnode.name=="default:water"
|
|
||||||
or thisnode.name=="default:water_flowing"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--add pusher entity
|
||||||
|
local object
|
||||||
|
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
|
||||||
|
if ENABLE_PISTON_ANIMATION then
|
||||||
|
object:setvelocity({x=dir.x * 4, y=dir.y * 4, z=dir.z * 4})
|
||||||
|
else
|
||||||
|
object:moveto(pos, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
--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
|
||||||
|
--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
|
||||||
|
local nextnode = minetest.env:get_node(pos)
|
||||||
|
minetest.env:place_node(pos, checknode)
|
||||||
|
checknode = nextnode
|
||||||
|
end
|
||||||
end)
|
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" or node.name=="mesecons_pistons:piston_normal" then
|
if node.name ~= "mesecons_pistons:piston_sticky" and node.name ~= "mesecons_pistons:piston_normal" then
|
||||||
local objs = minetest.env:get_objects_inside_radius(pos, 2)
|
return
|
||||||
for k, obj in pairs(objs) do
|
end
|
||||||
local obj_name = obj:get_entity_name()
|
|
||||||
if obj_name == "mesecons_pistons:piston_pusher_normal" or obj_name == "mesecons_pistons:piston_pusher_sticky" then
|
|
||||||
obj:remove()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if node.name=="mesecons_pistons:piston_sticky" then
|
--remove piston pusher
|
||||||
local direction=mesecon:sticky_piston_get_direction(pos)
|
local found = false --whether or not the piston was extended
|
||||||
local np = {x=pos.x+direction.x, y=pos.y+direction.y, z=pos.z+direction.z}
|
local objects = minetest.env:get_objects_inside_radius(pos, 2)
|
||||||
local coln = minetest.env:get_node(np)
|
for k, object in pairs(objects) do
|
||||||
if coln.name == "air" or coln.name =="water" then
|
local name = object:get_luaentity().name
|
||||||
local thisp= {x=np.x+direction.x, y=np.y+direction.y, z=np.z+direction.z}
|
if name == "mesecons_pistons:piston_pusher_normal" or name == "mesecons_pistons:piston_pusher_sticky" then
|
||||||
local thisnode=minetest.env:get_node(thisp)
|
found = true
|
||||||
if thisnode.name~="air" and thisnode.name~="water" and not mesecon:is_mvps_stopper(thisnode.name) then
|
object:remove()
|
||||||
local newpos={}
|
end
|
||||||
local oldpos={}
|
end
|
||||||
minetest.env:place_node(np, {name=thisnode.name})
|
|
||||||
minetest.env:dig_node(thisp)
|
--retract piston
|
||||||
end
|
if found and node.name == "mesecons_pistons:piston_sticky" then
|
||||||
end
|
local dir = mesecon:piston_get_direction(pos)
|
||||||
|
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 checknode = minetest.env:get_node(pos)
|
||||||
|
if checknode.name == "air"
|
||||||
|
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
|
||||||
|
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(checkpos)
|
||||||
|
if 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" then
|
||||||
|
minetest.env:place_node(pos, checknode)
|
||||||
|
minetest.env:dig_node(checkpos)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--Piston Animation
|
--Piston Animation
|
||||||
local PISTON_PUSHER_NORMAL={
|
local PISTON_PUSHER_NORMAL = {
|
||||||
physical = false,
|
physical = false,
|
||||||
visual = "sprite",
|
visual = "sprite",
|
||||||
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"},
|
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"},
|
||||||
@ -252,24 +177,24 @@ local PISTON_PUSHER_NORMAL={
|
|||||||
}
|
}
|
||||||
|
|
||||||
function PISTON_PUSHER_NORMAL:on_step(dtime)
|
function PISTON_PUSHER_NORMAL:on_step(dtime)
|
||||||
self.timer=self.timer+dtime
|
self.timer = self.timer+dtime
|
||||||
if self.timer>=0.24 then
|
if self.timer >= 0.24 then
|
||||||
self.object:setvelocity({x=0, y=0, z=0})
|
self.object:setvelocity({x=0, y=0, z=0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local PISTON_PUSHER_STICKY={
|
local PISTON_PUSHER_STICKY = {
|
||||||
physical = false,
|
physical = false,
|
||||||
visual = "sprite",
|
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"},
|
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},
|
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
||||||
visual = "cube",
|
visual = "cube",
|
||||||
timer=0,
|
timer = 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
function PISTON_PUSHER_STICKY:on_step(dtime)
|
function PISTON_PUSHER_STICKY:on_step(dtime)
|
||||||
self.timer=self.timer+dtime
|
self.timer=self.timer+dtime
|
||||||
if self.timer>=0.24 then
|
if self.timer >= 0.24 then
|
||||||
self.object:setvelocity({x=0, y=0, z=0})
|
self.object:setvelocity({x=0, y=0, z=0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
local set_node_on
|
local set_node_on
|
||||||
local set_node_off
|
local set_node_off
|
||||||
|
|
||||||
if ENABLE_TEMPEREST==1 then
|
if ENABLE_TEMPEREST then
|
||||||
set_node_on = function(pos)
|
set_node_on = function(pos)
|
||||||
local node = minetest.env:get_node(pos)
|
local node = minetest.env:get_node(pos)
|
||||||
if node.name=="mesecons_temperest:mesecon_socket_off" then
|
if node.name=="mesecons_temperest:mesecon_socket_off" then
|
||||||
@ -185,7 +185,7 @@ minetest.register_craft({
|
|||||||
})
|
})
|
||||||
|
|
||||||
--TEMPEREST-INVERTER
|
--TEMPEREST-INVERTER
|
||||||
if ENABLE_TEMPEREST==1 then
|
if ENABLE_TEMPEREST then
|
||||||
minetest.register_node("mesecons_temperest:mesecon_inverter_off", {
|
minetest.register_node("mesecons_temperest:mesecon_inverter_off", {
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
@ -241,6 +241,4 @@ if ENABLE_TEMPEREST==1 then
|
|||||||
{'"mesecons:mesecon_off"', '"default:steel_ingot"', '"mesecons:mesecon_off"'},
|
{'"mesecons:mesecon_off"', '"default:steel_ingot"', '"mesecons:mesecon_off"'},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user