Fix bug of teletool not working when y<0

master
Wuzzy 2015-02-16 02:32:53 +01:00
parent fa9d331afd
commit 60065e94cd
1 changed files with 8 additions and 4 deletions

View File

@ -10,19 +10,23 @@ teletool.settings = {}
function teletool.teleport(player, pointed_thing)
local pos = pointed_thing.above
local over1 = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
local src = player:getpos()
local dest = {x=pos.x, y=math.ceil(pos.y)-0.5, z=pos.z}
local destnode = minetest.get_node(dest)
local over = {x=dest.x, y=dest.y+1, z=dest.z}
local destnode = minetest.get_node({x=dest.x, y=math.ceil(dest.y), z=dest.z})
local overnode = minetest.get_node({x=over.x, y=math.ceil(over.y), z=over.z})
minetest.log("action", "[teletool] dest: "..minetest.pos_to_string(dest))
minetest.log("action", "[teletool] over: "..minetest.pos_to_string(over))
-- This trick prevents the player's head to spawn in a walkable node if the player clicked on the lower side of a node
-- NOTE: This piece of code must be updated as soon the collision boxes of players become configurable
if minetest.registered_nodes[over1.name].walkable then
if minetest.registered_nodes[overnode.name].walkable then
dest.y = dest.y - 1
end
-- The destination must be collision free
local destnode = minetest.get_node(dest)
destnode = minetest.get_node({x=dest.x, y=math.ceil(dest.y), z=dest.z})
if minetest.registered_nodes[destnode.name].walkable then
return false
end