From b4cbc528a34ff0d0ea8d5a0bdcd8904a038e3d43 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 21 May 2022 18:30:06 +0200 Subject: [PATCH 1/6] mcl_mobs: add entity_cramming --- mods/ENTITIES/mcl_mobs/api.lua | 54 +++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index dc87926a9c..1de5b1c869 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2956,6 +2956,48 @@ 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 entity_cramming_max = 24 +local cramming_damage = 3 +local function check_entity_cramming(self) + local p = self.object:get_pos() + local oo = minetest.get_objects_inside_radius(p,1) + local clear = false + if #oo < entity_cramming_max then clear = true end + local ncram = {} + for _,o in pairs(oo) do + local l = o:get_luaentity() + if l and clear then + l.cram = nil + ncram = {} + elseif l and l.cram == nil then + table.insert(ncram,l) + elseif l and l.cram then + damage_mob(l,"cramming",cramming_damage) + end + end + for i,l in ipairs(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 +3075,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 @@ -3537,6 +3570,7 @@ end -- main mob function local mob_step = function(self, dtime) check_item_pickup(self) + check_entity_cramming(self) if not self.fire_resistant then mcl_burning.tick(self.object, dtime, self) end From 85b599edba7884640b330f0c63e694c91875c6e4 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 21 May 2022 21:36:38 +0200 Subject: [PATCH 2/6] entity cramming: check less often --- mods/ENTITIES/mcl_mobs/api.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 1de5b1c869..4423652223 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2982,10 +2982,9 @@ local function check_entity_cramming(self) local l = o:get_luaentity() if l and clear then l.cram = nil - ncram = {} elseif l and l.cram == nil then table.insert(ncram,l) - elseif l and l.cram then + elseif not clear and l and l.cram then damage_mob(l,"cramming",cramming_damage) end end @@ -3570,7 +3569,6 @@ end -- main mob function local mob_step = function(self, dtime) check_item_pickup(self) - check_entity_cramming(self) if not self.fire_resistant then mcl_burning.tick(self.object, dtime, self) end @@ -3684,7 +3682,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.) From fb4f21cba05c4b5f247a696de4f43a8e1df40fdb Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 22 May 2022 17:16:03 +0200 Subject: [PATCH 3/6] entity cramming: spare the children --- mods/ENTITIES/mcl_mobs/api.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 4423652223..b21707065e 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2982,7 +2982,7 @@ local function check_entity_cramming(self) local l = o:get_luaentity() if l and clear then l.cram = nil - elseif l and l.cram == nil then + elseif l and l.cram == nil and not self.child then table.insert(ncram,l) elseif not clear and l and l.cram then damage_mob(l,"cramming",cramming_damage) From 87f50d64235fe4e8a4929463e27deb28281d15e3 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 23 May 2022 16:50:33 +0200 Subject: [PATCH 4/6] entity cramming: clean up check logic --- mods/ENTITIES/mcl_mobs/api.lua | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index b21707065e..959c59ff1b 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2975,20 +2975,21 @@ local cramming_damage = 3 local function check_entity_cramming(self) local p = self.object:get_pos() local oo = minetest.get_objects_inside_radius(p,1) - local clear = false - if #oo < entity_cramming_max then clear = true end + local clear = #oo < entity_cramming_max local ncram = {} for _,o in pairs(oo) do local l = o:get_luaentity() - if l and clear then - l.cram = nil - elseif l and l.cram == nil and not self.child then - table.insert(ncram,l) - elseif not clear and l and l.cram then - damage_mob(l,"cramming",cramming_damage) + 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 ipairs(ncram) do + for i,l in pairs(ncram) do if i > entity_cramming_max then l.cram = true else From af7dc0fb8f9643e21693ade92abe8b8b61aa5d2e Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 24 May 2022 13:43:55 +0200 Subject: [PATCH 5/6] change "constant" declaration to match mcl_mobs --- mods/ENTITIES/mcl_mobs/api.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 959c59ff1b..645eea86e0 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 @@ -2970,12 +2972,10 @@ local function damage_mob(self,reason,damage) end end -local entity_cramming_max = 24 -local cramming_damage = 3 local function check_entity_cramming(self) local p = self.object:get_pos() local oo = minetest.get_objects_inside_radius(p,1) - local clear = #oo < entity_cramming_max + local clear = #oo < ENTITY_CRAMMING_MAX local ncram = {} for _,o in pairs(oo) do local l = o:get_luaentity() @@ -2985,12 +2985,12 @@ local function check_entity_cramming(self) elseif l.cram == nil and not self.child then table.insert(ncram,l) elseif l.cram then - damage_mob(l,"cramming",cramming_damage) + damage_mob(l,"cramming",CRAMMING_DAMAGE) end end end for i,l in pairs(ncram) do - if i > entity_cramming_max then + if i > ENTITY_CRAMMING_MAX then l.cram = true else l.cram = nil From 47fa43825cafb6b0829c6a3f0f504be9c98c6a67 Mon Sep 17 00:00:00 2001 From: cora Date: Wed, 25 May 2022 16:57:16 +0200 Subject: [PATCH 6/6] count only mobs for cramming --- mods/ENTITIES/mcl_mobs/api.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 645eea86e0..6b2cff0e37 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2975,10 +2975,14 @@ end local function check_entity_cramming(self) local p = self.object:get_pos() local oo = minetest.get_objects_inside_radius(p,1) - local clear = #oo < ENTITY_CRAMMING_MAX - local ncram = {} + 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