From 11e36749267fc53d40c681a1e86d09878017b231 Mon Sep 17 00:00:00 2001 From: codiac Date: Tue, 19 Sep 2023 11:18:40 +1000 Subject: [PATCH 1/5] 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 From bf4c7e1913f632d4fc7637c40fec17e3fb454290 Mon Sep 17 00:00:00 2001 From: codiac Date: Wed, 20 Sep 2023 09:24:51 +1000 Subject: [PATCH 2/5] Allow non monsters spawns too --- mods/ENTITIES/mcl_mobs/spawning.lua | 14 +++++++++++--- settingtypes.txt | 7 ++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 5a07dd55b..82870dcd3 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -7,6 +7,7 @@ local nether_threshold = tonumber(minetest.settings:get("mcl_mobs_nether_thresho 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 overworld_passive_threshold = tonumber(minetest.settings:get("mcl_mobs_overworld_passive_threshold")) or 7 local get_node = minetest.get_node local get_item_group = minetest.get_item_group @@ -724,6 +725,8 @@ 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 + local gotten_light = get_node_light(pos) + if modern_lighting then local my_node = get_node(pos) local sky_light = minetest.get_natural_light(pos) @@ -738,12 +741,17 @@ local function spawn_check(pos, spawn_def) return true end elseif dimension == "overworld" then - if art_light <= overworld_threshold and sky_light <= overworld_sky_threshold then - return true + if mob_type == "monster" then + if art_light <= overworld_threshold and sky_light <= overworld_sky_threshold then + return true + end + else + if gotten_light > overworld_passive_threshold then + return true + end end end else - 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 diff --git a/settingtypes.txt b/settingtypes.txt index 827059145..7bac3c0e8 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -178,12 +178,13 @@ mcl_raids_zombie_siege (Zombie siege raid) bool false 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 +# Light levels greater than these block mobs 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 +mcl_mobs_overworld_threshold (Artificial light threshold to stop monster spawns in the Overworld) int 0 0 14 +mcl_mobs_overworld_sky_threshold (Skylight threshold to stop monster spawns in the Overworld) int 7 0 14 +mcl_mobs_overworld_passive_threshold (Combined light threshold to stop animal and npc spawns in the Overworld) int 7 0 14 [Audio] # Enable flame sound. From 7577d37b3866ba990cf011c51d8cb1e9d47160d1 Mon Sep 17 00:00:00 2001 From: codiac Date: Wed, 20 Sep 2023 15:56:27 +1000 Subject: [PATCH 3/5] Clarify MC version for lighting --- settingtypes.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settingtypes.txt b/settingtypes.txt index 7bac3c0e8..282c0bb64 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -173,9 +173,9 @@ 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. +# 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 +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 mobs spawning From d2d7887e0f04d884da5d13080f6fa3e8634523dd Mon Sep 17 00:00:00 2001 From: codiac Date: Thu, 21 Sep 2023 14:53:32 +1000 Subject: [PATCH 4/5] Handle bat and slime light checks --- mods/ENTITIES/mcl_mobs/init.lua | 1 + mods/ENTITIES/mcl_mobs/spawning.lua | 8 ++++++-- mods/ENTITIES/mobs_mc/bat.lua | 13 +++++++++++++ mods/ENTITIES/mobs_mc/slime+magma_cube.lua | 11 +++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/init.lua b/mods/ENTITIES/mcl_mobs/init.lua index 62100c627..a16f1c23d 100644 --- a/mods/ENTITIES/mcl_mobs/init.lua +++ b/mods/ENTITIES/mcl_mobs/init.lua @@ -287,6 +287,7 @@ function mcl_mobs.register_mob(name, def) spawn_in_group_min = def.spawn_in_group_min, noyaw = def.noyaw or false, particlespawners = def.particlespawners, + spawn_check = def.spawn_check, -- End of MCL2 extensions on_spawn = def.on_spawn, on_blast = def.on_blast or function(self,damage) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 82870dcd3..9c51c0f86 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -742,11 +742,15 @@ local function spawn_check(pos, spawn_def) end elseif dimension == "overworld" then if mob_type == "monster" then - if art_light <= overworld_threshold and sky_light <= overworld_sky_threshold then + if mob_def.spawn_check then + return mob_def.spawn_check(pos, gotten_light, art_light, sky_light) + elseif art_light <= overworld_threshold and sky_light <= overworld_sky_threshold then return true end else - if gotten_light > overworld_passive_threshold then + if mob_def.spawn_check then + return mob_def.spawn_check(pos, gotten_light, art_light, sky_light) + elseif gotten_light > overworld_passive_threshold then return true end end diff --git a/mods/ENTITIES/mobs_mc/bat.lua b/mods/ENTITIES/mobs_mc/bat.lua index b5532e2ee..b8b650877 100644 --- a/mods/ENTITIES/mobs_mc/bat.lua +++ b/mods/ENTITIES/mobs_mc/bat.lua @@ -2,6 +2,18 @@ local S = minetest.get_translator("mobs_mc") +local function spawn_check(pos, environmental_light, artificial_light, sky_light) + local date = os.date("*t") + local maxlight + if (date.month == 10 and date.day >= 20) or (date.month == 11 and date.day <= 3) then + maxlight = 6 + else + maxlight = 3 + end + + return artificial_light <= maxlight +end + mcl_mobs.register_mob("mobs_mc:bat", { description = S("Bat"), type = "animal", @@ -50,6 +62,7 @@ mcl_mobs.register_mob("mobs_mc:bat", { jump = false, fly = true, makes_footstep_sound = false, + spawn_check = spawn_check, }) diff --git a/mods/ENTITIES/mobs_mc/slime+magma_cube.lua b/mods/ENTITIES/mobs_mc/slime+magma_cube.lua index c07afb6b1..9cc5191bc 100644 --- a/mods/ENTITIES/mobs_mc/slime+magma_cube.lua +++ b/mods/ENTITIES/mobs_mc/slime+magma_cube.lua @@ -161,6 +161,16 @@ local spawn_children_on_die = function(child_mob, spawn_distance, eject_speed) end end +local function slime_spawn_check(pos, environmental_light, artificial_light, sky_light) + local maxlight = swamp_light_max + + if is_slime_chunk(pos) then + maxlight = minetest.LIGHT_MAX + 1 + end + + return artificial_light <= maxlight +end + -- Slime local slime_big = { description = S("Slime"), @@ -213,6 +223,7 @@ local slime_big = { spawn_small_alternative = "mobs_mc:slime_small", on_die = spawn_children_on_die("mobs_mc:slime_small", 1.0, 1.5), use_texture_alpha = true, + spawn_check = slime_spawn_check, } mcl_mobs.register_mob("mobs_mc:slime_big", slime_big) From 95db11836180d3bd22865c75856a6a2039973bc8 Mon Sep 17 00:00:00 2001 From: codiac Date: Fri, 22 Sep 2023 09:09:35 +1000 Subject: [PATCH 5/5] Add rules for blaze, wither skeleton, silverfish --- mods/ENTITIES/mobs_mc/blaze.lua | 4 ++++ mods/ENTITIES/mobs_mc/piglin.lua | 5 +++++ mods/ENTITIES/mobs_mc/silverfish.lua | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/mods/ENTITIES/mobs_mc/blaze.lua b/mods/ENTITIES/mobs_mc/blaze.lua index 6d92de210..98cf4728a 100644 --- a/mods/ENTITIES/mobs_mc/blaze.lua +++ b/mods/ENTITIES/mobs_mc/blaze.lua @@ -11,6 +11,9 @@ local mod_target = minetest.get_modpath("mcl_target") --################### BLAZE --################### +local function spawn_check(pos, environmental_light, artificial_light, sky_light) + return artificial_light <= 11 +end mcl_mobs.register_mob("mobs_mc:blaze", { description = S("Blaze"), @@ -137,6 +140,7 @@ mcl_mobs.register_mob("mobs_mc:blaze", { }, }) end, + spawn_check = spawn_check, }) mcl_mobs:spawn_specific( diff --git a/mods/ENTITIES/mobs_mc/piglin.lua b/mods/ENTITIES/mobs_mc/piglin.lua index 4f701b3e9..27f5a72f4 100644 --- a/mods/ENTITIES/mobs_mc/piglin.lua +++ b/mods/ENTITIES/mobs_mc/piglin.lua @@ -219,6 +219,10 @@ mcl_mobs.register_mob("mobs_mc:sword_piglin", sword_piglin) -- Zombified Piglin -- +local function spawn_check(pos, environmental_light, artificial_light, sky_light) + return artificial_light <= 11 +end + local zombified_piglin = { description = S("Zombie Piglin"), -- type="animal", passive=false: This combination is needed for a neutral mob which becomes hostile, if attacked @@ -256,6 +260,7 @@ local zombified_piglin = { }, jump = true, makes_footstep_sound = true, + spawn_check = spawn_check, walk_velocity = .8, run_velocity = 2.6, pathfinding = 1, diff --git a/mods/ENTITIES/mobs_mc/silverfish.lua b/mods/ENTITIES/mobs_mc/silverfish.lua index ab659a2a0..ec8ee19bb 100644 --- a/mods/ENTITIES/mobs_mc/silverfish.lua +++ b/mods/ENTITIES/mobs_mc/silverfish.lua @@ -4,6 +4,10 @@ local S = minetest.get_translator("mobs_mc") +local function spawn_check(pos, environmental_light, artificial_light, sky_light) + return artificial_light <= 11 +end + mcl_mobs.register_mob("mobs_mc:silverfish", { description = S("Silverfish"), type = "monster", @@ -53,6 +57,7 @@ mcl_mobs.register_mob("mobs_mc:silverfish", { view_range = 16, attack_type = "dogfight", damage = 1, + spawn_check = spawn_check, }) mcl_mobs.register_egg("mobs_mc:silverfish", S("Silverfish"), "#6d6d6d", "#313131", 0)