Make collision adjustment configurable
This commit is contained in:
parent
60065e94cd
commit
6ee2040712
37
init.lua
37
init.lua
@ -6,7 +6,20 @@ else
|
||||
end
|
||||
|
||||
teletool = {}
|
||||
|
||||
--[[ Load settings, apply default settings ]]
|
||||
teletool.settings = {}
|
||||
teletool.settings.avoid_collisions = true
|
||||
teletool.settings.adjust_head = true
|
||||
local avoid_collisions = minetest.setting_getbool("teletool_avoid_collisions")
|
||||
if avoid_collisions ~= nil then
|
||||
teletool.settings.avoid_collision = avoid_collisions
|
||||
end
|
||||
local adjust_head = minetest.setting_getbool("teletool_adjust_head")
|
||||
if adjust_head ~= nil then
|
||||
teletool.settings.adjust_head = adjust_head
|
||||
end
|
||||
|
||||
|
||||
function teletool.teleport(player, pointed_thing)
|
||||
local pos = pointed_thing.above
|
||||
@ -16,22 +29,22 @@ function teletool.teleport(player, pointed_thing)
|
||||
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[overnode.name].walkable then
|
||||
dest.y = dest.y - 1
|
||||
if teletool.settings.adjust_head then
|
||||
-- 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[overnode.name].walkable then
|
||||
dest.y = dest.y - 1
|
||||
end
|
||||
end
|
||||
|
||||
-- The destination must be collision free
|
||||
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
|
||||
if teletool.settings.avoid_collisions then
|
||||
-- The destination must be collision free
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
minetest.add_particlespawner({
|
||||
amount = 25,
|
||||
time = 0.1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user