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
|
||||
end
|
||||
|
||||
-- invulnerability time
|
||||
local invul_time = 0.4
|
||||
|
||||
-- check for invulnerability
|
||||
if tflp <= invul_time then
|
||||
return
|
||||
end
|
||||
|
||||
local is_player = hitter:is_player()
|
||||
|
||||
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 punch_interval = 1.4
|
||||
|
||||
-- invulnerability time
|
||||
local invul_time = 0.4
|
||||
|
||||
-- exhaust attacker
|
||||
if is_player then
|
||||
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
|
||||
|
||||
-- check for invulnerability
|
||||
if tflp <= invul_time then
|
||||
return
|
||||
end
|
||||
|
||||
-- healing
|
||||
if damage <= -1 then
|
||||
self.health = self.health - math.floor(damage)
|
||||
|
|
Loading…
Reference in New Issue