1
0
Fork 0

Merge pull request 'Add entity cramming' (#2226) from entity_cramming into master

Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/2226
Reviewed-by: Elias Fleckenstein <eliasfleckenstein@web.de>
mobs_head_rotation
cora 2022-05-26 12:21:46 +00:00
commit d887a97310
1 changed files with 48 additions and 11 deletions

View File

@ -11,6 +11,8 @@ local DEATH_DELAY = 0.5
local DEFAULT_FALL_SPEED = -10 local DEFAULT_FALL_SPEED = -10
local FLOP_HEIGHT = 5.0 local FLOP_HEIGHT = 5.0
local FLOP_HOR_SPEED = 1.5 local FLOP_HOR_SPEED = 1.5
local ENTITY_CRAMMING_MAX = 24
local CRAMMING_DAMAGE = 3
local MOB_CAP = {} local MOB_CAP = {}
MOB_CAP.hostile = 70 MOB_CAP.hostile = 70
@ -2956,6 +2958,50 @@ local function check_item_pickup(self)
end end
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 -- falling and fall damage
-- returns true if mob died -- returns true if mob died
local falling = function(self, pos) local falling = function(self, pos)
@ -3033,16 +3079,7 @@ local falling = function(self, pos)
if add ~= 0 then if add ~= 0 then
damage = damage + damage * (add/100) damage = damage + damage * (add/100)
end end
damage = floor(damage) damage_mob(self,"fall",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
end end
self.old_y = self.object:get_pos().y 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) if (self.state == "attack" and self.env_damage_timer > 1)
or self.state ~= "attack" then or self.state ~= "attack" then
check_entity_cramming(self)
self.env_damage_timer = 0 self.env_damage_timer = 0
-- check for environmental damage (water, fire, lava etc.) -- check for environmental damage (water, fire, lava etc.)