From be2fcc925ae01177888032d57617b600eb25b56b Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sun, 12 Nov 2023 06:30:57 +0000 Subject: [PATCH] Optimize code by checking invulnerability1st before the rest and drop checking the others when true --- mods/ENTITIES/mcl_mobs/combat.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index 53b993249..af5f9bd6e 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -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)