1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-12-25 02:00:21 +01:00

only spawn mob if player is within active area (useful for world anchors and force loaded areas)

This commit is contained in:
TenPlus1 2019-06-30 19:10:37 +01:00
parent 26cc611ad4
commit 38232d5ef4

24
api.lua
View File

@ -3374,11 +3374,13 @@ end -- END mobs:register_mob function
-- count how many mobs of one type are inside an area -- count how many mobs of one type are inside an area
-- will also return true for second value if player is inside area
local count_mobs = function(pos, type) local count_mobs = function(pos, type)
local total = 0 local total = 0
local objs = minetest.get_objects_inside_radius(pos, aoc_range * 2) local objs = minetest.get_objects_inside_radius(pos, aoc_range * 2)
local ent local ent
local players
for n = 1, #objs do for n = 1, #objs do
@ -3390,10 +3392,12 @@ local count_mobs = function(pos, type)
if ent and ent.name and ent.name == type then if ent and ent.name and ent.name == type then
total = total + 1 total = total + 1
end end
else
players = true
end end
end end
return total return total, players
end end
@ -3404,8 +3408,6 @@ function mobs:spawn_abm_check(pos, node, name)
-- return true to stop spawning mob -- return true to stop spawning mob
end end
local mod_technic = minetest.get_modpath("technic") or
minetest.get_modpath("simple_anchor")
function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
interval, chance, aoc, min_height, max_height, day_toggle, on_spawn) interval, chance, aoc, min_height, max_height, day_toggle, on_spawn)
@ -3464,7 +3466,12 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
end end
-- get total number of this mob in area -- get total number of this mob in area
local num_mob = count_mobs(pos, name) local num_mob, is_pla = count_mobs(pos, name)
if not is_pla then
--print ("--- no players within active area, will not spawn " .. name)
return
end
if num_mob >= aoc then if num_mob >= aoc then
--print ("--- too many " .. name .. " in area", num_mob .. "/" .. aoc) --print ("--- too many " .. name .. " in area", num_mob .. "/" .. aoc)
@ -3510,15 +3517,6 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
return return
end end
-- do not spawn if world anchor block is nearby
if mod_technic
and #minetest.find_nodes_in_area(
{x = pos.x - 32, y = pos.y - 32, z = pos.z - 32},
{x = pos.x + 32, y = pos.y + 32, z = pos.z + 32},
{"technic:admin_anchor", "simple_anchor:loader_block"}) > 0 then
return
end
-- only spawn away from player -- only spawn away from player
local objs = minetest.get_objects_inside_radius(pos, 8) local objs = minetest.get_objects_inside_radius(pos, 8)