mirror of
https://github.com/OgelGames/fakelib.git
synced 2025-01-04 23:30:35 +01:00
add vector check
This commit is contained in:
parent
799c4b706d
commit
191aa0510d
2
init.lua
2
init.lua
@ -30,6 +30,8 @@ for _,file in pairs({"metadata", "inventory", "player"}) do
|
|||||||
loadfile(path.."/"..file..".lua")(check, secure_table)
|
loadfile(path.."/"..file..".lua")(check, secure_table)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dofile(path.."/misc.lua")
|
||||||
|
|
||||||
if minetest.is_singleplayer() then
|
if minetest.is_singleplayer() then
|
||||||
minetest.register_chatcommand("fakelib_test", {
|
minetest.register_chatcommand("fakelib_test", {
|
||||||
description = "Test fakelib's API.",
|
description = "Test fakelib's API.",
|
||||||
|
10
misc.lua
Normal file
10
misc.lua
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
function fakelib.is_vector(x, add_metatable)
|
||||||
|
if type(x) ~= "table" or type(x.x) ~= "number" or type(x.y) ~= "number" or type(x.z) ~= "number" then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if add_metatable and getmetatable(x) ~= vector.metatable then
|
||||||
|
setmetatable(x, vector.metatable)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
@ -26,10 +26,10 @@ function fakelib.create_player(options)
|
|||||||
if type(options.name) == "string" then
|
if type(options.name) == "string" then
|
||||||
data.name = options.name
|
data.name = options.name
|
||||||
end
|
end
|
||||||
if type(options.position) == "table" then
|
if fakelib.is_vector(options.position) then
|
||||||
data.position = vector.copy(options.position)
|
data.position = vector.copy(options.position)
|
||||||
end
|
end
|
||||||
if type(options.direction) == "table" then
|
if fakelib.is_vector(options.direction) then
|
||||||
local dir = vector.normalize(options.direction)
|
local dir = vector.normalize(options.direction)
|
||||||
data.pitch = -math.asin(dir.y)
|
data.pitch = -math.asin(dir.y)
|
||||||
data.yaw = math.atan2(-dir.x, dir.z) % (math.pi * 2)
|
data.yaw = math.atan2(-dir.x, dir.z) % (math.pi * 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user