forked from VoxeLibre/VoxeLibre
Optimize code by checking invulnerability time first and dropping the rest of the check if true
This commit is contained in:
parent
c632b77cdb
commit
61c96e00ca
|
@ -537,6 +537,11 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
|
||||||
local is_player = hitter:is_player()
|
local is_player = hitter:is_player()
|
||||||
|
|
||||||
if is_player then
|
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?
|
-- is mob protected?
|
||||||
if self.protected and minetest.is_protected(self.object:get_pos(), hitter:get_player_name()) then
|
if self.protected and minetest.is_protected(self.object:get_pos(), hitter:get_player_name()) then
|
||||||
return
|
return
|
||||||
|
@ -546,11 +551,6 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
|
||||||
self.health = 0
|
self.health = 0
|
||||||
end
|
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
|
-- set/update 'drop xp' timestamp if hitted by player
|
||||||
self.xp_timestamp = time_now
|
self.xp_timestamp = time_now
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue