1
0
Fork 0

Add group spawning minimum attribute

This commit is contained in:
cora 2022-07-17 02:20:12 +02:00 committed by Gitea
parent a077e4535f
commit a68343b71d
1 changed files with 13 additions and 7 deletions

View File

@ -386,15 +386,18 @@ local function get_water_spawn(p)
end end
end end
local function spawn_group(p,mob,spawn_on,group_max) local function spawn_group(p,mob,spawn_on,group_max,group_min)
local nn = minetest.find_nodes_in_area(vector.offset(p,-3,-3,-3),vector.offset(p,3,3,3),spawn_on) if not group_min then group_min = 1 end
local nn = minetest.find_nodes_in_area(vector.offset(p,-5,-3,-5),vector.offset(p,5,3,5),spawn_on)
local o
if not nn or #nn < 1 then if not nn or #nn < 1 then
nn = {} nn = {}
table.insert(nn,p) table.insert(nn,p)
end end
for i = 1, math.random(group_max) do for i = 1, math.random(group_min,group_max) do
minetest.add_entity(nn[math.random(#nn)],mob) o = minetest.add_entity(nn[math.random(#nn)],mob)
end end
return o
end end
if mobs_spawn then if mobs_spawn then
@ -461,7 +464,7 @@ if mobs_spawn then
end end
local mob_def = mob_library_worker_table[mob_index] local mob_def = mob_library_worker_table[mob_index]
local mob_type = minetest.registered_entities[mob_def.name].type local mob_type = minetest.registered_entities[mob_def.name].type
local spawn_in_group = minetest.registered_entities[mob_def.name].spawn_in_group local spawn_in_group = minetest.registered_entities[mob_def.name].spawn_in_group or 4
if mob_def if mob_def
and spawning_position.y >= mob_def.min_height and spawning_position.y >= mob_def.min_height
and spawning_position.y <= mob_def.max_height and spawning_position.y <= mob_def.max_height
@ -483,10 +486,13 @@ if mobs_spawn then
end end
end end
--everything is correct, spawn mob --everything is correct, spawn mob
local object = minetest.add_entity(spawning_position, mob_def.name) local object
if spawn_in_group then if spawn_in_group then
spawn_group(spawning_position,mob_def.name,{gotten_node},spawn_in_group) object = spawn_group(spawning_position,mob_def.name,{gotten_node},spawn_in_group,spawn_in_group_min)
else object = minetest.add_entity(spawning_position, mob_def.name)
end end
if object then if object then
return mob_def.on_spawn and mob_def.on_spawn(object, spawning_position) return mob_def.on_spawn and mob_def.on_spawn(object, spawning_position)
end end