mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-19 09:31:07 +01:00
Add nil checks when mob is damaged
This commit is contained in:
parent
02d7f20cc9
commit
600eadedea
1 changed files with 29 additions and 11 deletions
|
@ -547,7 +547,7 @@ local check_for_death = function(self, cause, cmi_cause)
|
||||||
|
|
||||||
-- has health actually changed?
|
-- has health actually changed?
|
||||||
if self.health == self.old_health and self.health > 0 then
|
if self.health == self.old_health and self.health > 0 then
|
||||||
return
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local damaged = self.health < self.old_health
|
local damaged = self.health < self.old_health
|
||||||
|
@ -745,7 +745,7 @@ local do_env_damage = function(self)
|
||||||
-- remove mob if beyond map limits
|
-- remove mob if beyond map limits
|
||||||
if not within_limits(pos, 0) then
|
if not within_limits(pos, 0) then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -755,7 +755,9 @@ local do_env_damage = function(self)
|
||||||
|
|
||||||
effect(pos, 5, "tnt_smoke.png")
|
effect(pos, 5, "tnt_smoke.png")
|
||||||
|
|
||||||
if check_for_death(self, "light", {type = "light"}) then return end
|
if check_for_death(self, "light", {type = "light"}) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -797,7 +799,9 @@ local do_env_damage = function(self)
|
||||||
self.health = self.health - self.rain_damage
|
self.health = self.health - self.rain_damage
|
||||||
|
|
||||||
if check_for_death(self, "rain", {type = "environment",
|
if check_for_death(self, "rain", {type = "environment",
|
||||||
pos = pos, node = self.standing_in}) then return end
|
pos = pos, node = self.standing_in}) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -814,7 +818,9 @@ local do_env_damage = function(self)
|
||||||
effect(pos, 5, "tnt_smoke.png", nil, nil, 1, nil)
|
effect(pos, 5, "tnt_smoke.png", nil, nil, 1, nil)
|
||||||
|
|
||||||
if check_for_death(self, "water", {type = "environment",
|
if check_for_death(self, "water", {type = "environment",
|
||||||
pos = pos, node = self.standing_in}) then return end
|
pos = pos, node = self.standing_in}) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- lava damage
|
-- lava damage
|
||||||
|
@ -828,7 +834,9 @@ local do_env_damage = function(self)
|
||||||
effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
|
effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
|
||||||
|
|
||||||
if check_for_death(self, "lava", {type = "environment",
|
if check_for_death(self, "lava", {type = "environment",
|
||||||
pos = pos, node = self.standing_in}) then return end
|
pos = pos, node = self.standing_in}) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- fire damage
|
-- fire damage
|
||||||
|
@ -842,7 +850,9 @@ local do_env_damage = function(self)
|
||||||
effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
|
effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
|
||||||
|
|
||||||
if check_for_death(self, "fire", {type = "environment",
|
if check_for_death(self, "fire", {type = "environment",
|
||||||
pos = pos, node = self.standing_in}) then return end
|
pos = pos, node = self.standing_in}) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- damage_per_second node check
|
-- damage_per_second node check
|
||||||
|
@ -853,7 +863,9 @@ local do_env_damage = function(self)
|
||||||
effect(pos, 5, "tnt_smoke.png")
|
effect(pos, 5, "tnt_smoke.png")
|
||||||
|
|
||||||
if check_for_death(self, "dps", {type = "environment",
|
if check_for_death(self, "dps", {type = "environment",
|
||||||
pos = pos, node = self.standing_in}) then return end
|
pos = pos, node = self.standing_in}) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Drowning damage
|
-- Drowning damage
|
||||||
|
@ -882,7 +894,9 @@ local do_env_damage = function(self)
|
||||||
self.health = self.health - dmg
|
self.health = self.health - dmg
|
||||||
end
|
end
|
||||||
if check_for_death(self, "drowning", {type = "environment",
|
if check_for_death(self, "drowning", {type = "environment",
|
||||||
pos = pos, node = self.standing_in}) then return end
|
pos = pos, node = self.standing_in}) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
else
|
else
|
||||||
self.breath = math.min(self.breath_max, self.breath + 1)
|
self.breath = math.min(self.breath_max, self.breath + 1)
|
||||||
end
|
end
|
||||||
|
@ -902,7 +916,9 @@ local do_env_damage = function(self)
|
||||||
self.health = self.health - 2
|
self.health = self.health - 2
|
||||||
|
|
||||||
if check_for_death(self, "suffocation", {type = "environment",
|
if check_for_death(self, "suffocation", {type = "environment",
|
||||||
pos = pos, node = self.standing_in}) then return end
|
pos = pos, node = self.standing_in}) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
check_for_death(self, "", {type = "unknown"})
|
check_for_death(self, "", {type = "unknown"})
|
||||||
|
@ -3146,7 +3162,9 @@ local mob_step = function(self, dtime)
|
||||||
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.)
|
||||||
do_env_damage(self)
|
if do_env_damage(self) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- node replace check (cow eats grass etc.)
|
-- node replace check (cow eats grass etc.)
|
||||||
replace(self, pos)
|
replace(self, pos)
|
||||||
|
|
Loading…
Reference in a new issue