From b9c2c3bd0afbd673870dd0c92ea85869330bf896 Mon Sep 17 00:00:00 2001 From: kabou Date: Wed, 9 Mar 2022 00:01:23 +0100 Subject: [PATCH] Add check for unknown nodes. * Check if node has a definition table before attempting to evaluate attributes. * Define local variable to cache multiple accesses to `registered_nodes[]` and improve readability. * Reduce redundant `== false` condition check. --- mods/ENTITIES/mobs_mc/3_shared.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/3_shared.lua b/mods/ENTITIES/mobs_mc/3_shared.lua index fce0850b45..e30e41cf3e 100644 --- a/mods/ENTITIES/mobs_mc/3_shared.lua +++ b/mods/ENTITIES/mobs_mc/3_shared.lua @@ -50,8 +50,10 @@ mobs_mc.make_owner_teleport_function = function(dist, teleport_check_interval) local telepos_below = {x=telepos.x, y=telepos.y-1, z=telepos.z} table.remove(check_offsets, r) -- Long story short, spawn on a platform - if minetest.registered_nodes[minetest.get_node(telepos).name].walkable == false and - minetest.registered_nodes[minetest.get_node(telepos_below).name].walkable == true then + local trynode = minetest.registered_nodes[minetest.get_node(telepos).name] + local trybelownode = minetest.registered_nodes[minetest.get_node(telepos_below).name] + if trynode and not trynode.walkable and + trybelownode and trybelownode.walkable then -- Correct position found! Let's teleport. self.object:set_pos(telepos) return