mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-08-21 13:34:11 +02:00
Fix movestones (thanks MarkTraceur).
This commit is contained in:
parent
4200757ba3
commit
3c7d2b2e25
@ -3,42 +3,43 @@
|
|||||||
function mesecon:get_movestone_direction(pos)
|
function mesecon:get_movestone_direction(pos)
|
||||||
getactivated=0
|
getactivated=0
|
||||||
local direction = {x=0, y=0, z=0}
|
local direction = {x=0, y=0, z=0}
|
||||||
local lpos={x=pos.x, y=pos.y, z=pos.z}
|
local lpos
|
||||||
|
|
||||||
local getactivated=0
|
local getactivated=0
|
||||||
local rules=mesecon:get_rules("movestone")
|
local rules=mesecon:get_rules("movestone")
|
||||||
|
|
||||||
lpos.x=pos.x+0.499
|
lpos={x=pos.x+1, y=pos.y, z=pos.z}
|
||||||
|
for n=1, 3 do
|
||||||
for k=1, 3 do
|
if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
|
||||||
getactivated=getactivated+mesecon:is_power_on(lpos, rules[k].x, rules[k].y, rules[k].z)
|
direction.z=-1
|
||||||
end
|
|
||||||
if getactivated>0 then direction.x=-1 return direction end
|
|
||||||
lpos=pos
|
|
||||||
lpos.x=pos.x-0.499
|
|
||||||
|
|
||||||
for n=4, 6 do
|
|
||||||
getactivated=getactivated+mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z)
|
|
||||||
end
|
|
||||||
|
|
||||||
if getactivated>0 then direction.x=1 return direction end
|
|
||||||
lpos=pos
|
|
||||||
lpos.z=pos.z+0.499
|
|
||||||
|
|
||||||
for j=7, 9 do
|
|
||||||
getactivated=getactivated+mesecon:is_power_on(lpos, rules[j].x, rules[j].y, rules[j].z)
|
|
||||||
end
|
|
||||||
|
|
||||||
if getactivated>0 then direction.z=-1 return direction end
|
|
||||||
lpos=pos
|
|
||||||
lpos.z=pos.z-0.499
|
|
||||||
|
|
||||||
for l=10, 12 do
|
|
||||||
getactivated=getactivated+mesecon:is_power_on(lpos, rules[l].x, rules[l].y, rules[l].z)
|
|
||||||
end
|
|
||||||
if getactivated>0 then direction.z=1 return direction end
|
|
||||||
return direction
|
return direction
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
lpos={x=pos.x-1, y=pos.y, z=pos.z}
|
||||||
|
for n=4, 6 do
|
||||||
|
if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
|
||||||
|
direction.z=1
|
||||||
|
return direction
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
lpos={x=pos.x, y=pos.y, z=pos.z+1}
|
||||||
|
for n=7, 9 do
|
||||||
|
if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
|
||||||
|
direction.x=-1
|
||||||
|
return direction
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
lpos={x=pos.x, y=pos.y, z=pos.z-1}
|
||||||
|
for n=10, 12 do
|
||||||
|
if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
|
||||||
|
direction.x=1
|
||||||
|
return direction
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("mesecons_movestones:movestone", {
|
minetest.register_node("mesecons_movestones:movestone", {
|
||||||
tile_images = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"},
|
tile_images = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"},
|
||||||
@ -74,7 +75,7 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
|
|||||||
--colp.y=colp.y-direction.y
|
--colp.y=colp.y-direction.y
|
||||||
--colp.z=colp.z-(direction.z/2.01)
|
--colp.z=colp.z-(direction.z/2.01)
|
||||||
|
|
||||||
if (direction.x==0 and direction.y==0 and direction.z==0)
|
if not direction
|
||||||
or (minetest.env:get_node_or_nil(pos).name ~="air"
|
or (minetest.env:get_node_or_nil(pos).name ~="air"
|
||||||
and minetest.env:get_node_or_nil(pos).name ~= nil) then
|
and minetest.env:get_node_or_nil(pos).name ~= nil) then
|
||||||
minetest.env:add_node(pos, {name="mesecons_movestones:movestone"})
|
minetest.env:add_node(pos, {name="mesecons_movestones:movestone"})
|
||||||
@ -99,13 +100,13 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
|
|||||||
local thisp= {x=pos.x, y=pos.y, z=pos.z}
|
local thisp= {x=pos.x, y=pos.y, z=pos.z}
|
||||||
local thisnode=minetest.env:get_node(thisp)
|
local thisnode=minetest.env:get_node(thisp)
|
||||||
local nextnode={}
|
local nextnode={}
|
||||||
minetest.env:remove_node(thisp)
|
minetest.env:dig_node(thisp)
|
||||||
repeat
|
repeat
|
||||||
thisp.x=thisp.x+direction.x
|
thisp.x=thisp.x+direction.x
|
||||||
thisp.y=thisp.y+direction.y
|
thisp.y=thisp.y+direction.y
|
||||||
thisp.z=thisp.z+direction.z
|
thisp.z=thisp.z+direction.z
|
||||||
nextnode=minetest.env:get_node(thisp)
|
nextnode=minetest.env:get_node(thisp)
|
||||||
minetest.env:add_node(thisp, {name=thisnode.name})
|
minetest.env:place_node(thisp, {name=thisnode.name})
|
||||||
nodeupdate(thisp)
|
nodeupdate(thisp)
|
||||||
thisnode=nextnode
|
thisnode=nextnode
|
||||||
until thisnode.name=="air" or thisnode.name=="ignore" or thisnode.name=="default:water" or thisnode.name=="default:water_flowing"
|
until thisnode.name=="air" or thisnode.name=="ignore" or thisnode.name=="default:water" or thisnode.name=="default:water_flowing"
|
||||||
@ -122,10 +123,10 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
mesecon:register_on_signal_on(function (pos, node)
|
mesecon:register_on_signal_on(function (pos, node)
|
||||||
if node.name=="mesecons_movestones:movestone" then
|
if node.name=="mesecons_movestones:movestone" then
|
||||||
local direction=mesecon:get_movestone_direction({x=pos.x, y=pos.y, z=pos.z})
|
local direction=mesecon:get_movestone_direction({x=pos.x, y=pos.y, z=pos.z})
|
||||||
|
if not direction then return end
|
||||||
local checknode={}
|
local checknode={}
|
||||||
local collpos={x=pos.x, y=pos.y, z=pos.z}
|
local collpos={x=pos.x, y=pos.y, z=pos.z}
|
||||||
repeat -- Check if it collides with a stopper
|
repeat -- Check if it collides with a stopper
|
||||||
@ -183,6 +184,14 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
|
|||||||
local direction=mesecon:get_movestone_direction(colp)
|
local direction=mesecon:get_movestone_direction(colp)
|
||||||
local velocity={x=direction.x*3, y=direction.y*3, z=direction.z*3}
|
local velocity={x=direction.x*3, y=direction.y*3, z=direction.z*3}
|
||||||
|
|
||||||
|
if not direction then
|
||||||
|
--or (minetest.env:get_node_or_nil(pos).name ~="air"
|
||||||
|
--and minetest.env:get_node_or_nil(pos).name ~= nil) then
|
||||||
|
minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"})
|
||||||
|
self.object:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
self.object:setvelocity(velocity)
|
self.object:setvelocity(velocity)
|
||||||
|
|
||||||
local np = {x=pos.x+direction.x, y=pos.y+direction.y, z=pos.z+direction.z}
|
local np = {x=pos.x+direction.x, y=pos.y+direction.y, z=pos.z+direction.z}
|
||||||
@ -191,13 +200,13 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
|
|||||||
local thisp= {x=pos.x, y=pos.y, z=pos.z}
|
local thisp= {x=pos.x, y=pos.y, z=pos.z}
|
||||||
local thisnode=minetest.env:get_node(thisp)
|
local thisnode=minetest.env:get_node(thisp)
|
||||||
local nextnode={}
|
local nextnode={}
|
||||||
minetest.env:remove_node(thisp)
|
minetest.env:dig_node(thisp)
|
||||||
repeat
|
repeat
|
||||||
thisp.x=thisp.x+direction.x
|
thisp.x=thisp.x+direction.x
|
||||||
thisp.y=thisp.y+direction.y
|
thisp.y=thisp.y+direction.y
|
||||||
thisp.z=thisp.z+direction.z
|
thisp.z=thisp.z+direction.z
|
||||||
nextnode=minetest.env:get_node(thisp)
|
nextnode=minetest.env:get_node(thisp)
|
||||||
minetest.env:add_node(thisp, {name=thisnode.name})
|
minetest.env:place_node(thisp, {name=thisnode.name})
|
||||||
nodeupdate(thisp)
|
nodeupdate(thisp)
|
||||||
thisnode=nextnode
|
thisnode=nextnode
|
||||||
until thisnode.name=="air" or thisnode.name=="ignore" or thisnode.name=="default:water" or thisnode.name=="default:water_flowing"
|
until thisnode.name=="air" or thisnode.name=="ignore" or thisnode.name=="default:water" or thisnode.name=="default:water_flowing"
|
||||||
@ -217,22 +226,14 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
|
|||||||
newpos.x=thisp.x+direction.x
|
newpos.x=thisp.x+direction.x
|
||||||
newpos.y=thisp.y+direction.y
|
newpos.y=thisp.y+direction.y
|
||||||
newpos.z=thisp.z+direction.z
|
newpos.z=thisp.z+direction.z
|
||||||
minetest.env:add_node(newpos, {name=minetest.env:get_node(thisp).name})
|
minetest.env:place_node(newpos, {name=minetest.env:get_node(thisp).name})
|
||||||
nodeupdate(newpos)
|
nodeupdate(newpos)
|
||||||
oldpos={x=thisp.x, y=thisp.y, z=thisp.z}
|
oldpos={x=thisp.x, y=thisp.y, z=thisp.z}
|
||||||
thisp.x=thisp.x-direction.x
|
thisp.x=thisp.x-direction.x
|
||||||
thisp.y=thisp.y-direction.y
|
thisp.y=thisp.y-direction.y
|
||||||
thisp.z=thisp.z-direction.z
|
thisp.z=thisp.z-direction.z
|
||||||
until minetest.env:get_node(thisp).name=="air" or minetest.env:get_node(thisp).name=="ignore" or minetest.env:get_node(thisp).name=="default:water" or minetest.env:get_node(thisp).name=="default:water_flowing"
|
until minetest.env:get_node(thisp).name=="air" or minetest.env:get_node(thisp).name=="ignore" or minetest.env:get_node(thisp).name=="default:water" or minetest.env:get_node(thisp).name=="default:water_flowing"
|
||||||
minetest.env:remove_node(oldpos)
|
minetest.env:dig_node(oldpos)
|
||||||
end
|
|
||||||
|
|
||||||
if (direction.x==0 and direction.y==0 and direction.z==0) then
|
|
||||||
--or (minetest.env:get_node_or_nil(pos).name ~="air"
|
|
||||||
--and minetest.env:get_node_or_nil(pos).name ~= nil) then
|
|
||||||
minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"})
|
|
||||||
self.object:remove()
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -240,6 +241,7 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
|
|||||||
mesecon:register_on_signal_on(function (pos, node)
|
mesecon:register_on_signal_on(function (pos, node)
|
||||||
if node.name=="mesecons_movestones:sticky_movestone" then
|
if node.name=="mesecons_movestones:sticky_movestone" then
|
||||||
local direction=mesecon:get_movestone_direction({x=pos.x, y=pos.y, z=pos.z})
|
local direction=mesecon:get_movestone_direction({x=pos.x, y=pos.y, z=pos.z})
|
||||||
|
if not direction then return end
|
||||||
local checknode={}
|
local checknode={}
|
||||||
local collpos={x=pos.x, y=pos.y, z=pos.z}
|
local collpos={x=pos.x, y=pos.y, z=pos.z}
|
||||||
repeat -- Check if it collides with a stopper
|
repeat -- Check if it collides with a stopper
|
||||||
@ -269,3 +271,16 @@ mesecon:register_on_signal_on(function (pos, node)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
mesecon:add_rules("movestone", {
|
||||||
|
{x=0, y=1, z=-1},
|
||||||
|
{x=0, y=0, z=-1},
|
||||||
|
{x=0, y=-1, z=-1},
|
||||||
|
{x=0, y=1, z=1},
|
||||||
|
{x=0, y=-1, z=1},
|
||||||
|
{x=0, y=0, z=1},
|
||||||
|
{x=1, y=0, z=0},
|
||||||
|
{x=1, y=1, z=0},
|
||||||
|
{x=1, y=-1, z=0},
|
||||||
|
{x=-1, y=1, z=0},
|
||||||
|
{x=-1, y=-1, z=0},
|
||||||
|
{x=-1, y=0, z=0}})
|
Loading…
Reference in New Issue
Block a user