add mob_area_spawn setting

This commit is contained in:
TenPlus1 2020-11-30 14:43:49 +00:00
parent bdea826b7c
commit a4d2918383
3 changed files with 29 additions and 3 deletions

26
api.lua
View File

@ -8,7 +8,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = {
mod = "redo",
version = "20201115",
version = "20201130",
intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {}
}
@ -58,6 +58,7 @@ local mobs_drop_items = settings:get_bool("mobs_drop_items") ~= false
local mobs_griefing = settings:get_bool("mobs_griefing") ~= false
local spawn_protected = settings:get_bool("mobs_spawn_protected") ~= false
local remove_far = settings:get_bool("remove_far_mobs") ~= false
local mob_area_spawn = settings:get_bool("mob_area_spawn")
local difficulty = tonumber(settings:get("mob_difficulty")) or 1.0
local show_health = settings:get_bool("mob_show_health") ~= false
local max_per_block = tonumber(settings:get("max_objects_per_block") or 99)
@ -3908,8 +3909,27 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
end
end
-- returns position if we have enough space to spawn mob
pos = can_spawn(pos, name)
-- should we check mob area for obstructions ?
if mob_area_spawn ~= true then
-- do we have enough height clearance to spawn mob?
local ent = minetest.registered_entities[name]
local height = max(1, math.ceil(
(ent.collisionbox[5] or 0.25) - (ent.collisionbox[2] or -0.25) - 1))
for n = 0, height do
local pos2 = {x = pos.x, y = pos.y + n, z = pos.z}
if minetest.registered_nodes[node_ok(pos2).name].walkable == true then
--print ("--- inside block", name, node_ok(pos2).name)
return
end
end
else
-- returns position if we have enough space to spawn mob
pos = can_spawn(pos, name)
end
if pos then

View File

@ -697,6 +697,9 @@ External Settings for "minetest.conf"
function.
'mob_nospawn_range' Minimum range a mob can spawn near player (def: 12)
'mob_active_limit' Number of active mobs in game, 0 for unlimited
'mob_area_spawn' When true will check surrounding area the size of the
mob for obstructions before spawning, otherwise it
defaults to checking the height of the mob only.
Players can override the spawn chance for each mob registered by adding a line
to their minetest.conf file with a new value, the lower the value the more each

View File

@ -33,3 +33,6 @@ mob_nospawn_range (Mob no-spawn range) float 12.0
# Sets maximum number of active mobs in game (0 for unlimited)
mob_active_limit (Mob Active Limit) float 0
# Enables area check when spawning mobs
mob_area_spawn (Mob Area Spawn) bool false