From 46ee5aaa59fb067432bfb829f0389a4bb4d1bdf7 Mon Sep 17 00:00:00 2001 From: kabou Date: Sun, 20 Mar 2022 18:11:30 +0100 Subject: [PATCH] Fix undefined luaentity crash. * Add nil check to get_luaentity() access. * Cache get_luaentity() call in local var. --- mods/ENTITIES/mcl_mobs/api.lua | 4 ++-- mods/PLAYER/mcl_playerplus/init.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index c38c8eafa..ca47d4be7 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -222,8 +222,8 @@ local collision = function(self) for _,object in pairs(minetest.get_objects_inside_radius(pos, width)) do - if object:is_player() - or (object:get_luaentity()._cmi_is_mob == true and object ~= self.object) then + local ent = object:get_luaentity() + if object:is_player() or (ent and ent._cmi_is_mob and object ~= self.object) then local pos2 = object:get_pos() local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z} diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 45ca3c0d5..529c5bd43 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -35,8 +35,8 @@ local function player_collision(player) for _,object in pairs(minetest.get_objects_inside_radius(pos, width)) do - if object and (object:is_player() - or (object:get_luaentity()._cmi_is_mob == true and object ~= player)) then + local ent = object:get_luaentity() + if (object:is_player() or (ent and ent._cmi_is_mob and object ~= player)) then local pos2 = object:get_pos() local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z}