Merge pull request 'Use MC 1.18+ light levels to control mob spawning' (#3946) from spawn_lighting into master

Reviewed-on: MineClone2/MineClone2#3946
Reviewed-by: the-real-herowl <the-real-herowl@noreply.git.minetest.land>
This commit is contained in:
the-real-herowl 2023-10-22 01:35:00 +00:00
commit 59f3b53a51
8 changed files with 91 additions and 13 deletions

View File

@ -287,6 +287,7 @@ function mcl_mobs.register_mob(name, def)
spawn_in_group_min = def.spawn_in_group_min, spawn_in_group_min = def.spawn_in_group_min,
noyaw = def.noyaw or false, noyaw = def.noyaw or false,
particlespawners = def.particlespawners, particlespawners = def.particlespawners,
spawn_check = def.spawn_check,
-- End of MCL2 extensions -- End of MCL2 extensions
on_spawn = def.on_spawn, on_spawn = def.on_spawn,
on_blast = def.on_blast or function(self,damage) on_blast = def.on_blast or function(self,damage)

View File

@ -2,6 +2,13 @@
local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs
local mob_class = mcl_mobs.mob_class 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 overworld_passive_threshold = tonumber(minetest.settings:get("mcl_mobs_overworld_passive_threshold")) or 7
local get_node = minetest.get_node local get_node = minetest.get_node
local get_item_group = minetest.get_item_group local get_item_group = minetest.get_item_group
local get_node_light = minetest.get_node_light local get_node_light = minetest.get_node_light
@ -709,9 +716,6 @@ local function spawn_check(pos, spawn_def)
and spawn_def.dimension == dimension and spawn_def.dimension == dimension
and biome_check(spawn_def.biomes, gotten_biome) then 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") if (is_ground or spawn_def.type_of_spawning ~= "ground")
and (spawn_def.type_of_spawning ~= "ground" or not is_leaf) and (spawn_def.type_of_spawning ~= "ground" or not is_leaf)
and (not is_farm_animal(spawn_def.name) or is_grass) and (not is_farm_animal(spawn_def.name) or is_grass)
@ -721,20 +725,42 @@ 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 (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 and ( not spawn_protected or not minetest.is_protected(pos, "") ) then
--mcl_log("Level 2 spawn check passed")
local gotten_light = get_node_light(pos) 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") if modern_lighting then
return true local my_node = get_node(pos)
local sky_light = minetest.get_natural_light(pos)
local art_light = minetest.get_artificial_light(my_node.param1)
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 mob_type == "monster" 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 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
end
else else
--mcl_log("Spawn check level 3 failed") if gotten_light >= spawn_def.min_light and gotten_light <= spawn_def.max_light then
return true
end
end end
else
--mcl_log("Spawn check level 2 failed")
end end
else
--mcl_log("Spawn check level 1 failed")
end end
return false return false
end end

View File

@ -2,6 +2,18 @@
local S = minetest.get_translator("mobs_mc") 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", { mcl_mobs.register_mob("mobs_mc:bat", {
description = S("Bat"), description = S("Bat"),
type = "animal", type = "animal",
@ -50,6 +62,7 @@ mcl_mobs.register_mob("mobs_mc:bat", {
jump = false, jump = false,
fly = true, fly = true,
makes_footstep_sound = false, makes_footstep_sound = false,
spawn_check = spawn_check,
}) })

View File

@ -11,6 +11,9 @@ local mod_target = minetest.get_modpath("mcl_target")
--################### BLAZE --################### BLAZE
--################### --###################
local function spawn_check(pos, environmental_light, artificial_light, sky_light)
return artificial_light <= 11
end
mcl_mobs.register_mob("mobs_mc:blaze", { mcl_mobs.register_mob("mobs_mc:blaze", {
description = S("Blaze"), description = S("Blaze"),
@ -137,6 +140,7 @@ mcl_mobs.register_mob("mobs_mc:blaze", {
}, },
}) })
end, end,
spawn_check = spawn_check,
}) })
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(

View File

@ -219,6 +219,10 @@ mcl_mobs.register_mob("mobs_mc:sword_piglin", sword_piglin)
-- Zombified Piglin -- -- Zombified Piglin --
local function spawn_check(pos, environmental_light, artificial_light, sky_light)
return artificial_light <= 11
end
local zombified_piglin = { local zombified_piglin = {
description = S("Zombie Piglin"), description = S("Zombie Piglin"),
-- type="animal", passive=false: This combination is needed for a neutral mob which becomes hostile, if attacked -- 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, jump = true,
makes_footstep_sound = true, makes_footstep_sound = true,
spawn_check = spawn_check,
walk_velocity = .8, walk_velocity = .8,
run_velocity = 2.6, run_velocity = 2.6,
pathfinding = 1, pathfinding = 1,

View File

@ -4,6 +4,10 @@
local S = minetest.get_translator("mobs_mc") 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", { mcl_mobs.register_mob("mobs_mc:silverfish", {
description = S("Silverfish"), description = S("Silverfish"),
type = "monster", type = "monster",
@ -53,6 +57,7 @@ mcl_mobs.register_mob("mobs_mc:silverfish", {
view_range = 16, view_range = 16,
attack_type = "dogfight", attack_type = "dogfight",
damage = 1, damage = 1,
spawn_check = spawn_check,
}) })
mcl_mobs.register_egg("mobs_mc:silverfish", S("Silverfish"), "#6d6d6d", "#313131", 0) mcl_mobs.register_egg("mobs_mc:silverfish", S("Silverfish"), "#6d6d6d", "#313131", 0)

View File

@ -161,6 +161,16 @@ local spawn_children_on_die = function(child_mob, spawn_distance, eject_speed)
end end
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 -- Slime
local slime_big = { local slime_big = {
description = S("Slime"), description = S("Slime"),
@ -213,6 +223,7 @@ local slime_big = {
spawn_small_alternative = "mobs_mc:slime_small", spawn_small_alternative = "mobs_mc:slime_small",
on_die = spawn_children_on_die("mobs_mc:slime_small", 1.0, 1.5), on_die = spawn_children_on_die("mobs_mc:slime_small", 1.0, 1.5),
use_texture_alpha = true, use_texture_alpha = true,
spawn_check = slime_spawn_check,
} }
mcl_mobs.register_mob("mobs_mc:slime_big", slime_big) mcl_mobs.register_mob("mobs_mc:slime_big", slime_big)

View File

@ -194,6 +194,19 @@ mcl_mob_active_range (Active mob range) int 48 0 256
# Zombie siege raid (default:false) # Zombie siege raid (default:false)
mcl_raids_zombie_siege (Zombie siege raid) bool 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 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 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] [Audio]
# Enable flame sound. # Enable flame sound.
flame_sound (Flame sound) bool true flame_sound (Flame sound) bool true