From cd1c8bd92ea724f3319f8c84c8968be52b65521c Mon Sep 17 00:00:00 2001 From: GuyLiner Date: Thu, 16 Feb 2023 16:46:41 -0500 Subject: [PATCH] Refactored logic for getting light levels for mobs Removed mob_light_table, simplied loop, changed return values and fixed dimension priority error in loop. Slimes also don't have a hardcoded exception for their light levels anymore, and instead are apart of spawn specific. --- mods/ENTITIES/mcl_mobs/spawning.lua | 55 ++++++++++------------------- 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 891cd518d..507652a95 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -481,51 +481,34 @@ function mcl_mobs:spawn_setup(def) end function mcl_mobs:mob_light_lvl(mob_name, dimension) - local mob_light_table = {} + local spawn_dictionary_consolidated = {} --see if the mob exists in the nonspawn dictionary, if so then return light values if non_spawn_dictionary[mob_name] ~= nil then - if non_spawn_dictionary[mob_name][dimension] ~= nil then - mob_light_table = { - ["min_light"] = non_spawn_dictionary[mob_name][dimension].min_light, - ["max_light"] = non_spawn_dictionary[mob_name][dimension].max_light - } - return mob_light_table + local mob_dimension = non_spawn_dictionary[mob_name][dimension] + if mob_name ~= nil then + return mob_dimension.min_light,mob_dimension.max_light else - mob_light_table = { - ["min_light"] = non_spawn_dictionary[mob_name]["overworld"].min_light, - ["max_light"] = non_spawn_dictionary[mob_name]["overworld"].max_light - } - return mob_light_table + return non_spawn_dictionary[mob_name]["overworld"].min_light, non_spawn_dictionary[mob_name]["overworld"].max_light end --if the mob doesn't exist in non_spawn, check spawn_dictonary else for i,v in pairs(spawn_dictionary) do - local big_slime_search = string.find(spawn_dictionary[i].name,".*slime.*") - if spawn_dictionary[i].name == mob_name and spawn_dictionary[i].dimension == dimension and not big_slime_search then - mob_light_table = { - ["min_light"] = spawn_dictionary[i].min_light, - ["max_light"] = spawn_dictionary[i].max_light - } - return mob_light_table - - elseif spawn_dictionary[i].name == mob_name and spawn_dictionary[i].dimension == "overworld" and not big_slime_search then - mob_light_table = { - ["min_light"] = spawn_dictionary[i].min_light, - ["max_light"] = spawn_dictionary[i].max_light - } - return mob_light_table - elseif big_slime_search then - --custom spawners with slimes are broken in minecraft (they don't spawn unless in slime chunk) so we'll make sure they're broken in mcl2 as well :) - --if slimes chunks get added in the future, change this. - --Mobs will also have their light levels set to this for custom spawners if they don't appear in spawn_dictionary or non_spawn_dictionary - mob_light_table = { - ["min_light"] = -1, - ["max_light"] = -1 - } - return mob_light_table - end + if spawn_dictionary[spawn_dictionary[i].name] == nil then + spawn_dictionary_consolidated[spawn_dictionary[i].name] = {} + end + spawn_dictionary_consolidated[spawn_dictionary[i].name][dimension] = { + ["min_light"] = spawn_dictionary[i].min_light, + ["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 end end