1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-05 18:41:05 +00:00

Do not allow vector components to be nil

This commit is contained in:
sfan5 2025-05-18 22:44:20 +02:00
parent ae35f37bc3
commit a5263dc7ed
4 changed files with 58 additions and 48 deletions

View file

@ -266,15 +266,22 @@ int ModApiEnv::l_bulk_swap_node(lua_State *L)
// get_node_raw(x, y, z) -> content, param1, param2, pos_ok
int ModApiEnv::l_get_node_raw(lua_State *L)
{
GET_ENV_PTR;
GET_PLAIN_ENV_PTR;
// pos
// mirrors implementation of read_v3s16 (with the exact same rounding)
double x = lua_tonumber(L, 1);
double y = lua_tonumber(L, 2);
double z = lua_tonumber(L, 3);
v3s16 pos = doubleToInt(v3d(x, y, z), 1.0);
// Do it
v3s16 pos;
// mirrors the implementation of read_v3s16 (with the exact same rounding)
{
if (lua_isnoneornil(L, 1))
throw LuaError("X position is nil");
if (lua_isnoneornil(L, 2))
throw LuaError("Y position is nil");
if (lua_isnoneornil(L, 3))
throw LuaError("Z position is nil");
double x = lua_tonumber(L, 1);
double y = lua_tonumber(L, 2);
double z = lua_tonumber(L, 3);
pos = doubleToInt(v3d(x, y, z), 1.0);
}
bool pos_ok;
MapNode n = env->getMap().getNode(pos, &pos_ok);
// Return node and pos_ok