From 0a5443714cbf8bbd56b160df5016da62226af2ff Mon Sep 17 00:00:00 2001 From: BlockMen Date: Sun, 25 May 2014 12:05:44 +0200 Subject: [PATCH] No more mobs flood --- init.lua | 5 +++++ spawn.lua | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/init.lua b/init.lua index 5d0fffb..678495d 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,10 @@ creatures = {} +-- Max number of mobs per mapblock +creatures.zombie_max = 3 +creatures.ghost_max = 1 +creatures.sheep_max = 4 + creatures.ANIM_STAND = 1 creatures.ANIM_SIT = 2 creatures.ANIM_LAY = 3 diff --git a/spawn.lua b/spawn.lua index c17a02d..3b4ad64 100644 --- a/spawn.lua +++ b/spawn.lua @@ -1,3 +1,4 @@ +local max_mobs_sum = creatures.zombie_max + creatures.ghost_max + creatures.sheep_max - 1 -- hostile mobs if not minetest.setting_getbool("only_peaceful_mobs") then -- zombie @@ -6,6 +7,10 @@ if not minetest.setting_getbool("only_peaceful_mobs") then interval = 40.0, chance = 7600, action = function(pos, node, active_object_count, active_object_count_wider) + -- check per mapblock max (max per creature is done by .spawn()) + if active_object_count_wider > max_mobs_sum then + return + end local n = minetest.get_node_or_nil(pos) --if n and n.name and n.name ~= "default:stone" and math.random(1,4)>3 then return end pos.y = pos.y+1 @@ -35,6 +40,10 @@ if not minetest.setting_getbool("only_peaceful_mobs") then interval = 44.0, chance = 8350, action = function(pos, node, active_object_count, active_object_count_wider) + -- check per mapblock max (max per creature is done by .spawn()) + if active_object_count_wider > max_mobs_sum then + return + end if pos.y < 0 then return end pos.y = pos.y+1 local ll = minetest.env:get_node_light(pos) @@ -69,6 +78,10 @@ minetest.register_abm({ interval = 55.0, chance = 7800, action = function(pos, node, active_object_count, active_object_count_wider) + -- check per mapblock max (max per creature is done by .spawn()) + if active_object_count_wider > max_mobs_sum then + return + end if pos.y < 0 then return end pos.y = pos.y+1 local ll = minetest.env:get_node_light(pos) or 0