Skip to content

Commit

Permalink
add mob_area_spawn setting
Browse files Browse the repository at this point in the history
  • Loading branch information
tenplus1 committed Nov 30, 2020
1 parent bdea826 commit a4d2918
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
26 changes: 23 additions & 3 deletions api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a4d2918

Please sign in to comment.