From 00165959af5b585ec742ef4506a4b51474d66ecf Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sun, 12 Nov 2023 12:51:31 +0000 Subject: [PATCH] Fix held attack key not hitting mobs bug (this time for sure) Reverting to old code in the previous PR but with the new optimizations kept --- mods/ENTITIES/mcl_mobs/combat.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index af5f9bd6e..53eb7492b 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -532,11 +532,10 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir) return end - -- invulnerability time - local invul_time = 0.4 + local time_now = minetest.get_us_time() - -- check for invulnerability - if tflp <= invul_time then + -- check for invulnerability time in microseconds (0.5 second) + if time_now - self.last_invul_time <= 500000 then return end @@ -665,6 +664,9 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir) -- do damage self.health = self.health - damage + -- give invulnerability + self.last_invul_time = time_now + -- skip future functions if dead, except alerting others if self:check_for_death( "hit", {type = "punch", puncher = hitter}) then die = true