1
0
Fork 0

Optimize code by checking invulnerability1st before the rest and drop checking the others when true

This commit is contained in:
Eliy21 2023-11-12 06:30:57 +00:00
parent 5ebe9f549b
commit be2fcc925a
1 changed files with 8 additions and 8 deletions

View File

@ -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)