diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index dc87926a9..6b2cff0e3 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -11,6 +11,8 @@ local DEATH_DELAY = 0.5 local DEFAULT_FALL_SPEED = -10 local FLOP_HEIGHT = 5.0 local FLOP_HOR_SPEED = 1.5 +local ENTITY_CRAMMING_MAX = 24 +local CRAMMING_DAMAGE = 3 local MOB_CAP = {} MOB_CAP.hostile = 70 @@ -2956,6 +2958,50 @@ local function check_item_pickup(self) end end +local function damage_mob(self,reason,damage) + if not self.health then return end + damage = floor(damage) + if damage > 0 then + self.health = self.health - damage + + effect(pos, 5, "mcl_particles_smoke.png", 1, 2, 2, nil) + + if check_for_death(self, reason, {type = reason}) then + return true + end + end +end + +local function check_entity_cramming(self) + local p = self.object:get_pos() + local oo = minetest.get_objects_inside_radius(p,1) + local mobs = {} + for _,o in pairs(oo) do + local l = o:get_luaentity() + if l and l.is_mob and l.health > 0 then table.insert(mobs,l) end + end + local clear = #mobs < ENTITY_CRAMMING_MAX + local ncram = {} + for _,l in pairs(mobs) do + if l then + if clear then + l.cram = nil + elseif l.cram == nil and not self.child then + table.insert(ncram,l) + elseif l.cram then + damage_mob(l,"cramming",CRAMMING_DAMAGE) + end + end + end + for i,l in pairs(ncram) do + if i > ENTITY_CRAMMING_MAX then + l.cram = true + else + l.cram = nil + end + end +end + -- falling and fall damage -- returns true if mob died local falling = function(self, pos) @@ -3033,16 +3079,7 @@ local falling = function(self, pos) if add ~= 0 then damage = damage + damage * (add/100) end - damage = floor(damage) - if damage > 0 then - self.health = self.health - damage - - effect(pos, 5, "mcl_particles_smoke.png", 1, 2, 2, nil) - - if check_for_death(self, "fall", {type = "fall"}) then - return true - end - end + damage_mob(self,"fall",damage) end self.old_y = self.object:get_pos().y @@ -3650,7 +3687,7 @@ local mob_step = function(self, dtime) if (self.state == "attack" and self.env_damage_timer > 1) or self.state ~= "attack" then - + check_entity_cramming(self) self.env_damage_timer = 0 -- check for environmental damage (water, fire, lava etc.)