1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-16 18:01:40 +00:00

Use vector type in core.parse_coordinates()

This commit is contained in:
sfan5 2025-08-10 17:03:52 +02:00
parent b6065797ce
commit 7c88996210

View file

@ -853,22 +853,22 @@ Intended to be used in chat command parameter parsing.
Parameters: Parameters:
* x, y, z: Parsed x, y, and z coordinates as strings * x, y, z: Parsed x, y, and z coordinates as strings
* relative_to: Position to which to compare the position * relative_to: Optional position vector as reference point
Syntax of x, y and z: Syntax of x, y and z:
* "<number>": return as number * "<number>": use as number
* "~<number>": return <number> + player position on this axis * "~<number>": use <number> + reference point on this axis
* "~": return player position on this axis * "~": use reference point on this axis
Returns: a vector or nil for invalid input or if player does not exist Returns: a vector or nil for invalid input
]] ]]
function core.parse_coordinates(x, y, z, relative_to) function core.parse_coordinates(x, y, z, relative_to)
if not relative_to then if not relative_to then
x, y, z = tonumber(x), tonumber(y), tonumber(z) x, y, z = tonumber(x), tonumber(y), tonumber(z)
return x and y and z and { x = x, y = y, z = z } return x and y and z and vector.new(x, y, z)
end end
local rx = core.parse_relative_number(x, relative_to.x) local rx = core.parse_relative_number(x, relative_to.x)
local ry = core.parse_relative_number(y, relative_to.y) local ry = core.parse_relative_number(y, relative_to.y)
local rz = core.parse_relative_number(z, relative_to.z) local rz = core.parse_relative_number(z, relative_to.z)
return rx and ry and rz and { x = rx, y = ry, z = rz } return rx and ry and rz and vector.new(rx, ry, rz)
end end