From 11e36749267fc53d40c681a1e86d09878017b231 Mon Sep 17 00:00:00 2001 From: codiac Date: Tue, 19 Sep 2023 11:18:40 +1000 Subject: [PATCH] Use MC 1.18 light levels to control mob spawning --- mods/ENTITIES/mcl_mobs/spawning.lua | 40 +++++++++++++++++++---------- settingtypes.txt | 12 +++++++++ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index c677aeacf..5a07dd55b 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -2,6 +2,12 @@ local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs local mob_class = mcl_mobs.mob_class +local modern_lighting = minetest.settings:get_bool("mcl_mobs_modern_lighting", true) +local nether_threshold = tonumber(minetest.settings:get("mcl_mobs_nether_threshold")) or 11 +local end_threshold = tonumber(minetest.settings:get("mcl_mobs_end_threshold")) or 0 +local overworld_threshold = tonumber(minetest.settings:get("mcl_mobs_overworld_threshold")) or 0 +local overworld_sky_threshold = tonumber(minetest.settings:get("mcl_mobs_overworld_sky_threshold")) or 7 + local get_node = minetest.get_node local get_item_group = minetest.get_item_group local get_node_light = minetest.get_node_light @@ -709,9 +715,6 @@ local function spawn_check(pos, spawn_def) and spawn_def.dimension == dimension and biome_check(spawn_def.biomes, gotten_biome) then - --mcl_log("Level 1 spawn check passed") - --minetest.log("Mob: " .. mob_def.name) - if (is_ground or spawn_def.type_of_spawning ~= "ground") and (spawn_def.type_of_spawning ~= "ground" or not is_leaf) and (not is_farm_animal(spawn_def.name) or is_grass) @@ -721,20 +724,31 @@ local function spawn_check(pos, spawn_def) and (spawn_def.check_position and spawn_def.check_position(pos) or spawn_def.check_position == nil) and ( not spawn_protected or not minetest.is_protected(pos, "") ) then - --mcl_log("Level 2 spawn check passed") + if modern_lighting then + local my_node = get_node(pos) + local sky_light = minetest.get_natural_light(pos) + local art_light = minetest.get_artificial_light(my_node.param1) - local gotten_light = get_node_light(pos) - if gotten_light >= spawn_def.min_light and gotten_light <= spawn_def.max_light then - --mcl_log("Level 3 spawn check passed") - return true + if dimension == "nether" then + if art_light <= nether_threshold then + return true + end + elseif dimension == "end" then + if art_light <= end_threshold then + return true + end + elseif dimension == "overworld" then + if art_light <= overworld_threshold and sky_light <= overworld_sky_threshold then + return true + end + end else - --mcl_log("Spawn check level 3 failed") + local gotten_light = get_node_light(pos) + if gotten_light >= spawn_def.min_light and gotten_light <= spawn_def.max_light then + return true + end end - else - --mcl_log("Spawn check level 2 failed") end - else - --mcl_log("Spawn check level 1 failed") end return false end diff --git a/settingtypes.txt b/settingtypes.txt index c5d5d32c1..827059145 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -173,6 +173,18 @@ mcl_mob_active_range (Active mob range) int 48 0 256 # Zombie siege raid (default:false) mcl_raids_zombie_siege (Zombie siege raid) bool false +# Use MC 1.18 light levels to control monster spawning. +# Disable to use older mob specific light levels. +mcl_mobs_modern_lighting (Use MC 1.18 light rules for spawning) bool true + +# These only take effect if mcl_mobs_modern_lighting is enabled +# Light levels greater than these block monsters spawning +# See https://minecraft.fandom.com/wiki/Light#Internal_light_level +mcl_mobs_nether_threshold (Artificial light threshold to stop spawns in the Nether) int 11 0 14 +mcl_mobs_end_threshold (Artificial light threshold to stop spawns in the End) int 0 0 14 +mcl_mobs_overworld_threshold (Artificial light threshold to stop spawns in the Overworld) int 0 0 14 +mcl_mobs_overworld_sky_threshold (Skylight threshold to stop spawns in the Overworld) int 7 0 14 + [Audio] # Enable flame sound. flame_sound (Flame sound) bool true