From cafc16c41c41ede1c80910d98e51b579b6d89de8 Mon Sep 17 00:00:00 2001 From: GuyLiner Date: Sun, 26 Feb 2023 11:22:21 -0500 Subject: [PATCH] Fix #3484 If a mob was not found in the spawn_dictionary or the non_spawn dictionary and you tried to use a spawn egg to spawn that mob, the game would crash. This commit prevents that from happening by adding a check for mobs that don't exist, and minetest.log throws an error. --- mods/ENTITIES/mcl_mobs/spawning.lua | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 507652a95..a9d046424 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -502,13 +502,20 @@ function mcl_mobs:mob_light_lvl(mob_name, dimension) ["max_light"] = spawn_dictionary[i].max_light } end - mob_dimension = spawn_dictionary_consolidated[mob_name][dimension] - mob_dimension_default = spawn_dictionary_consolidated[mob_name]["overworld"] - if spawn_dictionary_consolidated[mob_name] == mob_name and mob_dimension ~= nil then - return mob_dimension.min_light, mob_dimension.max_light - else - return mob_dimension_default.min_light, mob_dimension_default.max_light - end + if spawn_dictionary_consolidated[mob_name] ~= nil then + mob_dimension = spawn_dictionary_consolidated[mob_name][dimension] + mob_dimension_default = spawn_dictionary_consolidated[mob_name]["overworld"] + if spawn_dictionary_consolidated[mob_name] == mob_name and mob_dimension ~= nil then + return mob_dimension.min_light, mob_dimension.max_light + else + return mob_dimension_default.min_light, mob_dimension_default.max_light + end + else + minetest.log("error", "There are no light levels for this mob") + --default light values if mob's light values don't exist in either dictionary + return 0, minetest.LIGHT_MAX+1 + end + end end