Revert "Fix possible crash if mob dies to node damage"

This reverts commit abdb58f4ee55800d047089a6a6ad06e3a528b64b.
This commit is contained in:
Wuzzy 2022-06-09 09:05:47 +02:00
parent abdb58f4ee
commit e12e7e390c

View File

@ -106,7 +106,7 @@ local function check_for_death(self, hitter, damage)
if damage == nil then if damage == nil then
damage = 0 damage = 0
end end
local hp = self.health - damage local hp = self.object:get_hp() - damage
if hp > 0 then if hp > 0 then
self.health = hp self.health = hp
if self.sounds.damage ~= nil then if self.sounds.damage ~= nil then
@ -452,7 +452,7 @@ function mobs:register_mob(name, def)
and self.object:get_velocity().y == 0 then and self.object:get_velocity().y == 0 then
local d = (self.old_y or 0) - self.object:get_pos().y local d = (self.old_y or 0) - self.object:get_pos().y
if d > 5 then if d > 5 then
self.health = self.health - math.floor(d - 5) self.object:set_hp(self.object:get_hp() - math.floor(d - 5))
effect(self.object:get_pos(), 5, "tnt_smoke.png") effect(self.object:get_pos(), 5, "tnt_smoke.png")
if check_for_death(self) then return true end if check_for_death(self) then return true end
end end
@ -497,7 +497,7 @@ function mobs:register_mob(name, def)
and tod > 0.2 and tod > 0.2
and tod < 0.8 and tod < 0.8
and (minetest.get_node_light(pos) or 0) > 12 then and (minetest.get_node_light(pos) or 0) > 12 then
self.health = self.health - self.light_damage self.object:set_hp(self.object:get_hp() - self.light_damage)
effect(pos, 5, "tnt_smoke.png") effect(pos, 5, "tnt_smoke.png")
if check_for_death(self) then return true end if check_for_death(self) then return true end
end end
@ -511,7 +511,7 @@ function mobs:register_mob(name, def)
-- node damage -- node damage
if self.takes_node_damage == true if self.takes_node_damage == true
and nodef.damage_per_second > 0 then and nodef.damage_per_second > 0 then
self.health = self.health - nodef.damage_per_second self.object:set_hp(self.object:get_hp() - nodef.damage_per_second)
if enable_blood then if enable_blood then
effect(pos, self.blood_amount, self.blood_texture) effect(pos, self.blood_amount, self.blood_texture)
else else
@ -529,7 +529,7 @@ function mobs:register_mob(name, def)
self.breath = self.breath - 1 self.breath = self.breath - 1
if self.breath < 0 then if self.breath < 0 then
self.breath = 0 self.breath = 0
self.health = self.health - nodef.drowning self.object:set_hp(self.object:get_hp() - nodef.drowning)
effect(pos, 5, "bubble.png") effect(pos, 5, "bubble.png")
end end
if check_for_death(self) then return true end if check_for_death(self) then return true end
@ -544,7 +544,7 @@ function mobs:register_mob(name, def)
-- water damage -- water damage
if self.water_damage ~= 0 if self.water_damage ~= 0
and nodef.groups.water then and nodef.groups.water then
self.health = self.health - self.water_damage self.object:set_hp(self.object:get_hp() - self.water_damage)
effect(pos, 5, "bubble.png") effect(pos, 5, "bubble.png")
if check_for_death(self) then return true end if check_for_death(self) then return true end
end end
@ -552,7 +552,7 @@ function mobs:register_mob(name, def)
-- lava damage -- lava damage
if self.lava_damage ~= 0 if self.lava_damage ~= 0
and nodef.groups.lava then and nodef.groups.lava then
self.health = self.health - self.lava_damage self.object:set_hp(self.object:get_hp() - self.lava_damage)
effect(pos, 5, "mobs_flame.png", 8) effect(pos, 5, "mobs_flame.png", 8)
if check_for_death(self) then return true end if check_for_death(self) then return true end
end end
@ -1318,15 +1318,10 @@ function mobs:register_mob(name, def)
} }
end end
-- Initialize health. We use the 'health' field
-- for the mob health, not get_hp/set_hp!
if self.health == 0 then if self.health == 0 then
self.health = math.random (self.hp_min, self.hp_max) self.health = math.random (self.hp_min, self.hp_max)
end end
-- Note: set_hp is only used once in init time to
-- set it to a dummy value. get_hp/set_hp must
-- be ignored apart from that.
self.object:set_hp( self.health ) self.object:set_hp( self.health )
self.object:set_armor_groups({fleshy = self.armor}) self.object:set_armor_groups({fleshy = self.armor})
self.state = "stand" self.state = "stand"