1
0
Fork 0

Optimize code by checking invulnerability time first and dropping the rest of the check if true

This commit is contained in:
Eliy21 2023-11-14 16:56:43 +00:00
parent c632b77cdb
commit 61c96e00ca
1 changed files with 5 additions and 5 deletions

View File

@ -537,6 +537,11 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
local is_player = hitter:is_player()
if is_player then
-- check for invulnerability time in microseconds (0.5 second)
if time_now - self.invul_timestamp <= 500000 then
return
end
-- is mob protected?
if self.protected and minetest.is_protected(self.object:get_pos(), hitter:get_player_name()) then
return
@ -546,11 +551,6 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
self.health = 0
end
-- check for invulnerability time in microseconds (0.5 second)
if time_now - self.invul_timestamp <= 500000 then
return
end
-- set/update 'drop xp' timestamp if hitted by player
self.xp_timestamp = time_now
end