1
0
Fork 0

Fix check_position and change spawn check to stages

respiration
ancientmarinerdev 2023-03-16 19:32:43 +00:00 committed by Gitea
parent b8b47e55e1
commit e7449a65d8
1 changed files with 31 additions and 21 deletions

View File

@ -542,7 +542,7 @@ function mcl_mobs:non_spawn_specific(mob_name,dimension,min_light,max_light)
} }
end 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) 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, check_position)
-- Do mobs spawn at all? -- Do mobs spawn at all?
if not mobs_spawn then if not mobs_spawn then
@ -579,6 +579,7 @@ function mcl_mobs:spawn_specific(name, dimension, type_of_spawning, biomes, min_
spawn_dictionary[key]["min_height"] = min_height spawn_dictionary[key]["min_height"] = min_height
spawn_dictionary[key]["max_height"] = max_height spawn_dictionary[key]["max_height"] = max_height
spawn_dictionary[key]["day_toggle"] = day_toggle spawn_dictionary[key]["day_toggle"] = day_toggle
spawn_dictionary[key]["check_position"] = check_position
summary_chance = summary_chance + chance summary_chance = summary_chance + chance
end end
@ -653,7 +654,8 @@ end
local function spawn_check(pos, spawn_def) local function spawn_check(pos, spawn_def)
if not spawn_def then return end if not spawn_def or not pos then return end
dbg_spawn_attempts = dbg_spawn_attempts + 1 dbg_spawn_attempts = dbg_spawn_attempts + 1
local dimension = mcl_worlds.pos_to_dimension(pos) local dimension = mcl_worlds.pos_to_dimension(pos)
local mob_def = minetest.registered_entities[spawn_def.name] local mob_def = minetest.registered_entities[spawn_def.name]
@ -676,25 +678,33 @@ local function spawn_check(pos, spawn_def)
local is_bedrock = gotten_node == "mcl_core:bedrock" local is_bedrock = gotten_node == "mcl_core:bedrock"
local is_grass = minetest.get_item_group(gotten_node,"grass_block") ~= 0 local is_grass = minetest.get_item_group(gotten_node,"grass_block") ~= 0
if pos and spawn_def if pos.y >= spawn_def.min_height
and pos.y >= spawn_def.min_height
and pos.y <= spawn_def.max_height and pos.y <= spawn_def.max_height
and spawn_def.dimension == dimension and spawn_def.dimension == dimension
and biome_check(spawn_def.biomes, gotten_biome) and biome_check(spawn_def.biomes, gotten_biome) then
and (is_ground or spawn_def.type_of_spawning ~= "ground")
--minetest.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 (spawn_def.type_of_spawning ~= "ground" or not is_leaf)
and has_room(mob_def,pos) and has_room(mob_def,pos)
and (spawn_def.check_position and spawn_def.check_position(pos) or true) and (spawn_def.check_position and spawn_def.check_position(pos) or spawn_def.check_position == nil)
and (not is_farm_animal(spawn_def.name) or is_grass) and (not is_farm_animal(spawn_def.name) or is_grass)
and (spawn_def.type_of_spawning ~= "water" or is_water) and (spawn_def.type_of_spawning ~= "water" or is_water)
and ( not spawn_protected or not minetest.is_protected(pos, "") ) and ( not spawn_protected or not minetest.is_protected(pos, "") )
and not is_bedrock then and not is_bedrock then
minetest.log("Level 2 spawn check passed")
--only need to poll for node light if everything else worked --only need to poll for node light if everything else worked
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 if gotten_light >= spawn_def.min_light and gotten_light <= spawn_def.max_light then
minetest.log("Level 3 spawn check passed")
return true return true
end end
end end
end
return false return false
end end