Merge pull request 'Fix custom spawners spawning mobs regardless of light level' (#3421) from GuyLiner/MineClone2:fix-spawner into master

Reviewed-on: MineClone2/MineClone2#3421
Reviewed-by: ancientmarinerdev <ancientmariner_dev@proton.me>
This commit is contained in:
ancientmarinerdev 2023-02-17 22:43:59 +00:00
commit e8641c3c20
25 changed files with 79 additions and 9 deletions

View File

@ -503,6 +503,8 @@ function mcl_mobs.register_egg(mob, desc, background_color, overlay_color, addeg
local name = placer:get_player_name()
local privs = minetest.get_player_privs(name)
local dim = mcl_worlds.pos_to_dimension(placer:get_pos())
local mob_light_lvl = {mcl_mobs:mob_light_lvl(itemstack:get_name(),dim)}
if under.name == "mcl_mobspawners:spawner" then
if minetest.is_protected(pointed_thing.under, name) then
minetest.record_protection_violation(pointed_thing.under, name)
@ -512,7 +514,7 @@ function mcl_mobs.register_egg(mob, desc, background_color, overlay_color, addeg
minetest.chat_send_player(name, S("You need the “maphack” privilege to change the mob spawner."))
return itemstack
end
mcl_mobspawners.setup_spawner(pointed_thing.under, itemstack:get_name())
mcl_mobspawners.setup_spawner(pointed_thing.under, itemstack:get_name(), mob_light_lvl[1], mob_light_lvl[2])
if not minetest.is_creative_enabled(name) then
itemstack:take_item()
end

View File

@ -413,6 +413,8 @@ WARNING: BIOME INTEGRATION NEEDED -> How to get biome through lua??
--this is where all of the spawning information is kept
local spawn_dictionary = {}
--this is where all of the spawning information is kept for mobs that don't naturally spawn
local non_spawn_dictionary = {}
local summary_chance = 0
function mcl_mobs:spawn_setup(def)
@ -478,6 +480,47 @@ function mcl_mobs:spawn_setup(def)
summary_chance = summary_chance + chance
end
function mcl_mobs:mob_light_lvl(mob_name, dimension)
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
local mob_dimension = non_spawn_dictionary[mob_name][dimension]
if mob_name ~= nil then
return mob_dimension.min_light,mob_dimension.max_light
else
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
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
function mcl_mobs:non_spawn_specific(mob_name,dimension,min_light,max_light)
table.insert(non_spawn_dictionary, mob_name)
non_spawn_dictionary[mob_name] = {
[dimension] = {
min_light = min_light , max_light = max_light
}
}
end
function mcl_mobs:spawn_specific(name, dimension, type_of_spawning, biomes, min_light, max_light, interval, chance, aoc, min_height, max_height, day_toggle, on_spawn)
-- Do mobs spawn at all?

View File

@ -207,5 +207,6 @@ mcl_mobs.register_arrow("mobs_mc:blaze_fireball", {
end
})
-- spawn eggs
mcl_mobs:non_spawn_specific("mobs_mc:blaze", "overworld", 0, 11)
-- spawn eggs.
mcl_mobs.register_egg("mobs_mc:blaze", S("Blaze"), "#f6b201", "#fff87e", 0)

View File

@ -174,3 +174,4 @@ mcl_mobs.register_egg("mobs_mc:enderdragon", S("Ender Dragon"), "#252525", "#b31
mcl_wip.register_wip_item("mobs_mc:enderdragon")
mcl_mobs:non_spawn_specific("mobs_mc:enderdragon","overworld",0,minetest.LIGHT_MAX+1)

View File

@ -39,3 +39,4 @@ mcl_mobs.register_mob("mobs_mc:endermite", {
})
mcl_mobs.register_egg("mobs_mc:endermite", S("Endermite"), "#161616", "#6d6d6d", 0)
mcl_mobs:non_spawn_specific("mobs_mc:endermite","overworld",0,7)

View File

@ -139,6 +139,6 @@ mcl_mobs.register_arrow("mobs_mc:fireball", {
mcl_mobs:non_spawn_specific("mobs_mc:ghast","overworld","0","7")
-- spawn eggs
mcl_mobs.register_egg("mobs_mc:ghast", S("Ghast"), "#f9f9f9", "#bcbcbc", 0)

View File

@ -131,5 +131,7 @@ minetest.LIGHT_MAX+1,
mcl_vars.mg_nether_min,
mcl_vars.mg_nether_max)
mcl_mobs:non_spawn_specific("mobs_mc:hoglin","overworld",0,7)
-- spawn eggs
mcl_mobs.register_egg("mobs_mc:hoglin", S("Hoglin"), "#85682e", "#2b2140", 0)

View File

@ -206,3 +206,4 @@ function mobs_mc.check_iron_golem_summon(pos)
end
end
end
mcl_mobs:non_spawn_specific("mobs_mc:iron_golem","overworld",0,minetest.LIGHT_MAX+1)

View File

@ -283,6 +283,7 @@ piglin_brute.group_attack = { "mobs_mc:piglin", "mobs_mc:piglin_brute" }
mcl_mobs.register_mob("mobs_mc:piglin_brute", piglin_brute)
mcl_mobs:non_spawn_specific("mobs_mc:piglin","overworld",0,7)
-- Regular spawning in the Nether
mcl_mobs:spawn_specific(
"mobs_mc:piglin",
@ -299,7 +300,7 @@ minetest.LIGHT_MAX+1,
3,
mcl_vars.mg_lava_nether_max,
mcl_vars.mg_nether_max)
mcl_mobs:non_spawn_specific("mobs_mc:sword_piglin","overworld",0,7)
mcl_mobs:spawn_specific(
"mobs_mc:sword_piglin",
"nether",

View File

@ -122,3 +122,4 @@ pillager = {
mcl_mobs.register_mob("mobs_mc:pillager", pillager)
mcl_mobs.register_egg("mobs_mc:pillager", S("Pillager"), "#532f36", "#959b9b", 0)
mcl_mobs:non_spawn_specific("mobs_mc:pillager","overworld",0,7)

View File

@ -178,7 +178,7 @@ mcl_mobs.register_arrow("mobs_mc:shulkerbullet", {
mcl_mobs.register_egg("mobs_mc:shulker", S("Shulker"), "#946694", "#4d3852", 0)
mcl_mobs:non_spawn_specific("mobs_mc:shulker","overworld",0,minetest.LIGHT_MAX+1)
--[[
mcl_mobs:spawn_specific(
"mobs_mc:shulker",

View File

@ -56,3 +56,4 @@ mcl_mobs.register_mob("mobs_mc:silverfish", {
})
mcl_mobs.register_egg("mobs_mc:silverfish", S("Silverfish"), "#6d6d6d", "#313131", 0)
mcl_mobs:non_spawn_specific("mobs_mc:silverfish","overworld",0,11)

View File

@ -118,3 +118,4 @@ mcl_vars.mg_nether_max)
--]]
-- spawn eggs
mcl_mobs.register_egg("mobs_mc:witherskeleton", S("Wither Skeleton"), "#141414", "#474d4d", 0)
mcl_mobs:non_spawn_specific("mobs_mc:witherskeleton","overworld",0,7)

View File

@ -278,7 +278,6 @@ swamp_light_max,
4,
swamp_min,
swamp_max)
-- Magma cube
local magma_cube_big = {
description = S("Magma Cube"),
@ -431,6 +430,11 @@ nether_max)
-- spawn eggs
mcl_mobs.register_egg("mobs_mc:magma_cube_big", S("Magma Cube"), "#350000", "#fcfc00")
-- non_spawn_specific is typically for mobs who don't spawn in the overworld, or mobs that don't spawn
-- naturally. However, slimes are a particular case where they spawn under different conditions in the same
-- dimension.
mcl_mobs:non_spawn_specific("mobs_mc:slime_big","overworld",0,minetest.LIGHT_MAX+1)
mcl_mobs:non_spawn_specific("mobs_mc:magma_cube_big","overworld",0, minetest.LIGHT_MAX+1)
mcl_mobs.register_egg("mobs_mc:slime_big", S("Slime"), "#52a03e", "#7ebf6d")
-- FIXME: add spawn eggs for small and tiny slimes and magma cubes

View File

@ -197,3 +197,4 @@ end
-- Spawn egg
mcl_mobs.register_egg("mobs_mc:snowman", S("Snow Golem"), "#f2f2f2", "#fd8f47", 0)
mcl_mobs:non_spawn_specific("mobs_mc:snowman","overworld",0,minetest.LIGHT_MAX+1)

View File

@ -246,3 +246,4 @@ mcl_mobs:spawn_setup({
-- spawn eggs
mcl_mobs.register_egg("mobs_mc:strider", S("Strider"), "#000000", "#FF0000", 0)
mcl_mobs:non_spawn_specific("mobs_mc:strider","nether",0,minetest.LIGHT_MAX+1)

View File

@ -95,3 +95,4 @@ mcl_mobs.register_mob("mobs_mc:vex", {
-- spawn eggs
mcl_mobs.register_egg("mobs_mc:vex", S("Vex"), "#7a90a4", "#e8edf1", 0)
mcl_mobs:non_spawn_specific("mobs_mc:vex","overworld",0,7)

View File

@ -2199,4 +2199,5 @@ mobs_mc.water_level+1,
mcl_vars.mg_overworld_max)
--]]
-- spawn eggs
mcl_mobs:non_spawn_specific("mobs_mc:villager","overworld", 0, minetest.LIGHT_MAX+1)
mcl_mobs.register_egg("mobs_mc:villager", S("Villager"), "#563d33", "#bc8b72", 0)

View File

@ -90,3 +90,4 @@ mcl_mobs.register_mob("mobs_mc:evoker", {
-- spawn eggs
mcl_mobs.register_egg("mobs_mc:evoker", S("Evoker"), "#959b9b", "#1e1c1a", 0)
mcl_mobs:non_spawn_specific("mobs_mc:evoker","overworld",0,7)

View File

@ -66,3 +66,4 @@ mcl_mobs.register_mob("mobs_mc:illusioner", {
})
mcl_mobs.register_egg("mobs_mc:illusioner", S("Illusioner"), "#3f5cbb", "#8a8686", 0)
mcl_mobs:non_spawn_specific("mobs_mc:illusioner","overworld",0,7)

View File

@ -78,3 +78,4 @@ mcl_mobs.register_mob("mobs_mc:vindicator", {
-- spawn eggs
mcl_mobs.register_egg("mobs_mc:vindicator", S("Vindicator"), "#959b9b", "#275e61", 0)
mcl_mobs:non_spawn_specific("mobs_mc:vindicator","overworld",0,7)

View File

@ -106,5 +106,5 @@ mcl_mobs.register_arrow("mobs_mc:potion_arrow", {
-- spawn eggs
mcl_mobs.register_egg("mobs_mc:witch", S("Witch"), "#340000", "#51a03e", 0, true)
mcl_mobs:non_spawn_specific("mobs_mc:witch","overworld",0,7)
mcl_wip.register_wip_item("mobs_mc:witch")

View File

@ -132,3 +132,4 @@ mcl_mobs.register_arrow("mobs_mc:wither_skull", {
mcl_mobs.register_egg("mobs_mc:wither", S("Wither"), "#4f4f4f", "#4f4f4f", 0, true)
mcl_wip.register_wip_item("mobs_mc:wither")
mcl_mobs:non_spawn_specific("mobs_mc:wither","overworld",0,minetest.LIGHT_MAX+1)

View File

@ -153,3 +153,4 @@ mcl_vars.mg_nether_max)
-- spawn eggs
mcl_mobs.register_egg("mobs_mc:pigman", S("Zombie Pigman"), "#ea9393", "#4c7129", 0)
mcl_mobs:non_spawn_specific("mobs_mc:pigman","overworld",0,minetest.LIGHT_MAX+1)

View File

@ -317,7 +317,9 @@ minetest.register_node("mcl_mobspawners:spawner", {
if obj then
obj:remove()
end
if not minetest.is_creative_enabled(name) then
mcl_experience.throw_xp(pos, math.random(15, 43))
end
end,
on_punch = function(pos)