From f202ed832785ad8fef997abf7ac261540f71ae21 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 5 Jul 2022 12:55:14 +0200 Subject: [PATCH] spawn in groups --- mods/ENTITIES/mcl_mobs/api.lua | 1 + mods/ENTITIES/mcl_mobs/spawning.lua | 11 +++++++++++ mods/ENTITIES/mobs_mc/cod.lua | 1 + mods/ENTITIES/mobs_mc/dolphin.lua | 1 + mods/ENTITIES/mobs_mc/salmon.lua | 1 + 5 files changed, 15 insertions(+) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 84b24c339..998b05547 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -4036,6 +4036,7 @@ minetest.register_entity(name, { fire_resistant = def.fire_resistant or false, fire_damage_resistant = def.fire_damage_resistant or false, ignited_by_sunlight = def.ignited_by_sunlight or false, + spawn_in_group = def.spawn_in_group, -- End of MCL2 extensions on_spawn = def.on_spawn, diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index f8c94afb6..a1c8e23b5 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -386,6 +386,13 @@ local function get_water_spawn(p) 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 local perlin_noise @@ -449,6 +456,7 @@ if mobs_spawn then end local mob_def = mob_library_worker_table[mob_index] 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 and spawning_position.y >= mob_def.min_height and spawning_position.y <= mob_def.max_height @@ -470,6 +478,9 @@ if mobs_spawn then end --everything is correct, spawn mob 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 return mob_def.on_spawn and mob_def.on_spawn(object, spawning_position) end diff --git a/mods/ENTITIES/mobs_mc/cod.lua b/mods/ENTITIES/mobs_mc/cod.lua index 0d40912dc..11c6ee01f 100644 --- a/mods/ENTITIES/mobs_mc/cod.lua +++ b/mods/ENTITIES/mobs_mc/cod.lua @@ -40,6 +40,7 @@ local cod = { xp_max = 3, armor = 100, rotate = 180, + spawn_in_group = 10, tilt_swim = true, collisionbox = {-0.3, 0.0, -0.3, 0.3, 0.79, 0.3}, visual = "mesh", diff --git a/mods/ENTITIES/mobs_mc/dolphin.lua b/mods/ENTITIES/mobs_mc/dolphin.lua index f991e7495..333da3808 100644 --- a/mods/ENTITIES/mobs_mc/dolphin.lua +++ b/mods/ENTITIES/mobs_mc/dolphin.lua @@ -42,6 +42,7 @@ local dolphin = { walk_chance = 100, breath_max = 120, rotate = 180, + spawn_in_group = 3, tilt_swim = true, collisionbox = {-0.3, 0.0, -0.3, 0.3, 0.79, 0.3}, visual = "mesh", diff --git a/mods/ENTITIES/mobs_mc/salmon.lua b/mods/ENTITIES/mobs_mc/salmon.lua index b586918fb..dea502fd0 100644 --- a/mods/ENTITIES/mobs_mc/salmon.lua +++ b/mods/ENTITIES/mobs_mc/salmon.lua @@ -19,6 +19,7 @@ local salmon = { xp_min = 1, xp_max = 3, armor = 100, + spawn_in_group = 5, tilt_swim = true, collisionbox = {-0.4, 0.0, -0.4, 0.4, 0.79, 0.4}, visual = "mesh",