1
0
Fork 0

Add a delay before mobs start to suffocate

objects
Wuzzy 2020-05-13 22:15:46 +02:00
parent a20637f68c
commit 547080bd98
1 changed files with 19 additions and 7 deletions

View File

@ -929,6 +929,14 @@ local do_env_damage = function(self)
and (nodef.groups.disable_suffocation ~= 1) and (nodef.groups.disable_suffocation ~= 1)
and (nodef.groups.opaque == 1) then and (nodef.groups.opaque == 1) then
-- Short grace period before starting to take suffocation damage.
-- This is different from players, who take damage instantly.
-- This has been done because mobs might briefly be inside solid nodes
-- when e.g. climbing up stairs.
-- This is a bit hacky because it assumes that do_env_damage
-- is called roughly every second only.
self.suffocation_timer = self.suffocation_timer + 1
if self.suffocation_timer >= 3 then
-- 2 damage per second -- 2 damage per second
-- TODO: Deal this damage once every 1/2 second -- TODO: Deal this damage once every 1/2 second
self.health = self.health - 2 self.health = self.health - 2
@ -938,6 +946,9 @@ local do_env_damage = function(self)
return true return true
end end
end end
else
self.suffocation_timer = 0
end
return check_for_death(self, "", {type = "unknown"}) return check_for_death(self, "", {type = "unknown"})
end end
@ -3345,7 +3356,7 @@ minetest.register_entity(name, {
replace_offset = def.replace_offset or 0, replace_offset = def.replace_offset or 0,
on_replace = def.on_replace, on_replace = def.on_replace,
timer = 0, timer = 0,
env_damage_timer = 0, -- only used when state = "attack" env_damage_timer = 0,
tamed = false, tamed = false,
pause_timer = 0, pause_timer = 0,
horny = false, horny = false,
@ -3392,6 +3403,7 @@ minetest.register_entity(name, {
shoot_arrow = def.shoot_arrow, shoot_arrow = def.shoot_arrow,
sounds_child = def.sounds_child, sounds_child = def.sounds_child,
explosion_strength = def.explosion_strength, explosion_strength = def.explosion_strength,
suffocation_timer = 0,
-- End of MCL2 extensions -- End of MCL2 extensions
on_spawn = def.on_spawn, on_spawn = def.on_spawn,