forked from VoxeLibre/VoxeLibre
Optimize code by checking invulnerability1st before the rest and drop checking the others when true
This commit is contained in:
parent
5ebe9f549b
commit
be2fcc925a
|
@ -532,6 +532,14 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- invulnerability time
|
||||||
|
local invul_time = 0.4
|
||||||
|
|
||||||
|
-- check for invulnerability
|
||||||
|
if tflp <= invul_time then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local is_player = hitter:is_player()
|
local is_player = hitter:is_player()
|
||||||
|
|
||||||
if is_player then
|
if is_player then
|
||||||
|
@ -553,9 +561,6 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
|
||||||
local weapon = hitter:get_wielded_item()
|
local weapon = hitter:get_wielded_item()
|
||||||
local punch_interval = 1.4
|
local punch_interval = 1.4
|
||||||
|
|
||||||
-- invulnerability time
|
|
||||||
local invul_time = 0.4
|
|
||||||
|
|
||||||
-- exhaust attacker
|
-- exhaust attacker
|
||||||
if is_player then
|
if is_player then
|
||||||
mcl_hunger.exhaust(hitter:get_player_name(), mcl_hunger.EXHAUST_ATTACK)
|
mcl_hunger.exhaust(hitter:get_player_name(), mcl_hunger.EXHAUST_ATTACK)
|
||||||
|
@ -603,11 +608,6 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check for invulnerability
|
|
||||||
if tflp <= invul_time then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- healing
|
-- healing
|
||||||
if damage <= -1 then
|
if damage <= -1 then
|
||||||
self.health = self.health - math.floor(damage)
|
self.health = self.health - math.floor(damage)
|
||||||
|
|
Loading…
Reference in New Issue