From 0ad415c18d8db796a2a4a0a71adb25b478f956f1 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Fri, 21 Jun 2024 18:20:01 +0200 Subject: [PATCH] Skip invalid objects in raycasts --- src/script/lua_api/l_env.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 06dc27b2d..2b3d15bea 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -155,6 +155,7 @@ void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, int LuaRaycast::l_next(lua_State *L) { GET_PLAIN_ENV_PTR; + ServerEnvironment *senv = dynamic_cast(env); bool csm = false; #ifndef SERVER @@ -163,7 +164,17 @@ int LuaRaycast::l_next(lua_State *L) LuaRaycast *o = checkObject(L, 1); PointedThing pointed; - env->continueRaycast(&o->state, &pointed); + for (;;) { + env->continueRaycast(&o->state, &pointed); + if (pointed.type != POINTEDTHING_OBJECT) + break; + if (!senv) + break; + const auto *obj = senv->getActiveObject(pointed.object_id); + if (obj && !obj->isGone()) + break; + // skip gone object + } if (pointed.type == POINTEDTHING_NOTHING) lua_pushnil(L); else