mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
FIX spawning
This commit is contained in:
parent
19d662dee4
commit
52124bd201
1 changed files with 11 additions and 15 deletions
|
@ -25,6 +25,7 @@ local math_ceil = math.ceil
|
||||||
local math_cos = math.cos
|
local math_cos = math.cos
|
||||||
local math_sin = math.sin
|
local math_sin = math.sin
|
||||||
local math_sqrt = math.sqrt
|
local math_sqrt = math.sqrt
|
||||||
|
local math_abs = math.abs
|
||||||
|
|
||||||
local vector_distance = vector.distance
|
local vector_distance = vector.distance
|
||||||
local vector_new = vector.new
|
local vector_new = vector.new
|
||||||
|
@ -286,11 +287,7 @@ local function count_mobs_total(mob_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function count_mobs_add_entry (mobs_list, mob_cat)
|
local function count_mobs_add_entry (mobs_list, mob_cat)
|
||||||
if mobs_list[mob_cat] then
|
mobs_list[mob_cat] = (mobs_list[mob_cat] or 0) + 1
|
||||||
mobs_list[mob_cat] = mobs_list[mob_cat] + 1
|
|
||||||
else
|
|
||||||
mobs_list[mob_cat] = 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--categorise_by can be name or type or spawn_class
|
--categorise_by can be name or type or spawn_class
|
||||||
|
@ -616,14 +613,14 @@ local function get_next_mob_spawn_pos(pos)
|
||||||
xoff, yoff, zoff = xoff * dd, yoff * dd, zoff * dd
|
xoff, yoff, zoff = xoff * dd, yoff * dd, zoff * dd
|
||||||
local goal_pos = vector.offset(pos, xoff, yoff, zoff)
|
local goal_pos = vector.offset(pos, xoff, yoff, zoff)
|
||||||
|
|
||||||
if not ( math.abs(goal_pos.x) <= SPAWN_MAPGEN_LIMIT and math.abs(goal_pos.y) <= SPAWN_MAPGEN_LIMIT and math.abs(goal_pos.z) <= SPAWN_MAPGEN_LIMIT ) then
|
if not (math_abs(goal_pos.x) <= SPAWN_MAPGEN_LIMIT and math_abs(goal_pos.y) <= SPAWN_MAPGEN_LIMIT and math_abs(goal_pos.z) <= SPAWN_MAPGEN_LIMIT) then
|
||||||
mcl_log("Pos outside mapgen limits: " .. minetest.pos_to_string(goal_pos))
|
mcl_log("Pos outside mapgen limits: " .. minetest.pos_to_string(goal_pos))
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Calculate upper/lower y limits
|
-- Calculate upper/lower y limits
|
||||||
local d2 = xoff*xoff + zoff*zoff -- squared distance in x,z plane only
|
local d2 = xoff*xoff + zoff*zoff -- squared distance in x,z plane only
|
||||||
local y1 = math_sqrt( MOB_SPAWN_ZONE_OUTER_SQ - d2 ) -- absolue value of distance to outer sphere
|
local y1 = math_sqrt(MOB_SPAWN_ZONE_OUTER_SQ - d2) -- absolue value of distance to outer sphere
|
||||||
|
|
||||||
local y_min, y_max
|
local y_min, y_max
|
||||||
if d2 >= MOB_SPAWN_ZONE_INNER_SQ then
|
if d2 >= MOB_SPAWN_ZONE_INNER_SQ then
|
||||||
|
@ -632,7 +629,7 @@ local function get_next_mob_spawn_pos(pos)
|
||||||
y_max = pos.y + y1
|
y_max = pos.y + y1
|
||||||
else
|
else
|
||||||
-- Inner region, y range spans between inner and outer spheres
|
-- Inner region, y range spans between inner and outer spheres
|
||||||
local y2 = math_sqrt( MOB_SPAWN_ZONE_INNER_SQ - d2 )
|
local y2 = math_sqrt(MOB_SPAWN_ZONE_INNER_SQ - d2)
|
||||||
if goal_pos.y > pos.y then
|
if goal_pos.y > pos.y then
|
||||||
-- Upper hemisphere
|
-- Upper hemisphere
|
||||||
y_min = pos.y + y2
|
y_min = pos.y + y2
|
||||||
|
@ -683,7 +680,6 @@ local function biome_check(biome_list, biome_goal)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -761,15 +757,15 @@ local function spawn_check(pos, spawn_def)
|
||||||
-- do not spawn ground mobs on leaves
|
-- do not spawn ground mobs on leaves
|
||||||
if spawn_def.type_of_spawning == "ground" and (not node_def.groups.solid or node_def.groups.leaves) then return end
|
if spawn_def.type_of_spawning == "ground" and (not node_def.groups.solid or node_def.groups.leaves) then return end
|
||||||
-- water mobs only on water
|
-- water mobs only on water
|
||||||
if spawn_def.type_of_spawning == "water" and node_def.groups.water then return end
|
if spawn_def.type_of_spawning == "water" and not node_def.groups.water then return end
|
||||||
-- lava mobs only on lava
|
-- lava mobs only on lava
|
||||||
if spawn_def.type_of_spawning == "lava" and node_def.groups.lava then return end
|
if spawn_def.type_of_spawning == "lava" and not node_def.groups.lava then return end
|
||||||
-- farm animals on grass only
|
-- farm animals on grass only
|
||||||
if is_farm_animal(spawn_def.name) and node_def.groups.grass_block then return end
|
if is_farm_animal(spawn_def.name) and not node_def.groups.grass_block then return end
|
||||||
|
|
||||||
---- More expensive calls:
|
---- More expensive calls:
|
||||||
-- check the biome
|
-- check the biome
|
||||||
if not biome_check(spawn_def.biomes, get_biome_name(pos)) then return end
|
if spawn_def.biomes ~= list_of_all_biomes and not biome_check(spawn_def.biomes, get_biome_name(pos)) then return end
|
||||||
-- check if there is enough room
|
-- check if there is enough room
|
||||||
local mob_def = minetest.registered_entities[spawn_def.name]
|
local mob_def = minetest.registered_entities[spawn_def.name]
|
||||||
if not has_room(mob_def,pos) then return end
|
if not has_room(mob_def,pos) then return end
|
||||||
|
@ -805,12 +801,12 @@ local function spawn_check(pos, spawn_def)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
-- passive threshold is apparently the same in all dimensions ...
|
-- passive threshold is apparently the same in all dimensions ...
|
||||||
return gotten_light < overworld_passive_threshold
|
return gotten_light > overworld_passive_threshold
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_mobs.spawn(pos,id)
|
function mcl_mobs.spawn(pos,id)
|
||||||
local def = minetest.registered_entities[id] or minetest.registered_entities["mobs_mc:"..id] or minetest.registered_entities["extra_mobs:"..id]
|
local def = minetest.registered_entities[id] or minetest.registered_entities["mobs_mc:"..id] or minetest.registered_entities["extra_mobs:"..id]
|
||||||
if not def or (def.can_spawn and not def.can_spawn(pos)) or not def.is_mob then
|
if not pos or not def or (def.can_spawn and not def.can_spawn(pos)) or not def.is_mob then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
dbg_spawn_counts[def.name] = (dbg_spawn_counts[def.name] or 0) + 1
|
dbg_spawn_counts[def.name] = (dbg_spawn_counts[def.name] or 0) + 1
|
||||||
|
|
Loading…
Reference in a new issue