1
0
Fork 0

spawn in groups

This commit is contained in:
cora 2022-07-05 12:55:14 +02:00
parent 44abef44e1
commit f202ed8327
5 changed files with 15 additions and 0 deletions

View File

@ -4036,6 +4036,7 @@ minetest.register_entity(name, {
fire_resistant = def.fire_resistant or false, fire_resistant = def.fire_resistant or false,
fire_damage_resistant = def.fire_damage_resistant or false, fire_damage_resistant = def.fire_damage_resistant or false,
ignited_by_sunlight = def.ignited_by_sunlight or false, ignited_by_sunlight = def.ignited_by_sunlight or false,
spawn_in_group = def.spawn_in_group,
-- End of MCL2 extensions -- End of MCL2 extensions
on_spawn = def.on_spawn, on_spawn = def.on_spawn,

View File

@ -386,6 +386,13 @@ local function get_water_spawn(p)
end end
end end
local function spawn_group(p,mob,spawn_on,group_max)
local nn = minetest.find_nodes_in_area(vector.offset(p,-3,-3,-3),vector.offset(p,3,3,3),spawn_on)
for i = 1, math.random(group_max) do
minetest.add_entity(nn[math.random(#nn)],mob)
end
end
if mobs_spawn then if mobs_spawn then
local perlin_noise local perlin_noise
@ -449,6 +456,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
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
@ -470,6 +478,9 @@ if mobs_spawn then
end end
--everything is correct, spawn mob --everything is correct, spawn mob
local object = minetest.add_entity(spawning_position, mob_def.name) local object = minetest.add_entity(spawning_position, mob_def.name)
if spawn_in_group then
spawn_group(spawning_position,mob_def.name,{gotten_node},spawn_in_group)
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

View File

@ -40,6 +40,7 @@ local cod = {
xp_max = 3, xp_max = 3,
armor = 100, armor = 100,
rotate = 180, rotate = 180,
spawn_in_group = 10,
tilt_swim = true, tilt_swim = true,
collisionbox = {-0.3, 0.0, -0.3, 0.3, 0.79, 0.3}, collisionbox = {-0.3, 0.0, -0.3, 0.3, 0.79, 0.3},
visual = "mesh", visual = "mesh",

View File

@ -42,6 +42,7 @@ local dolphin = {
walk_chance = 100, walk_chance = 100,
breath_max = 120, breath_max = 120,
rotate = 180, rotate = 180,
spawn_in_group = 3,
tilt_swim = true, tilt_swim = true,
collisionbox = {-0.3, 0.0, -0.3, 0.3, 0.79, 0.3}, collisionbox = {-0.3, 0.0, -0.3, 0.3, 0.79, 0.3},
visual = "mesh", visual = "mesh",

View File

@ -19,6 +19,7 @@ local salmon = {
xp_min = 1, xp_min = 1,
xp_max = 3, xp_max = 3,
armor = 100, armor = 100,
spawn_in_group = 5,
tilt_swim = true, tilt_swim = true,
collisionbox = {-0.4, 0.0, -0.4, 0.4, 0.79, 0.4}, collisionbox = {-0.4, 0.0, -0.4, 0.4, 0.79, 0.4},
visual = "mesh", visual = "mesh",