1
0
Fork 0

Optimize code by calling get_enchantment function only once

This commit is contained in:
Eliy21 2023-12-16 09:46:18 +00:00
parent cfab59d68a
commit 8fbd72c142
1 changed files with 3 additions and 2 deletions

View File

@ -282,11 +282,12 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool
end end
if hitter and hitter:is_player() and distance <= 3 then if hitter and hitter:is_player() and distance <= 3 then
local wielditem = hitter:get_wielded_item() local wielditem = hitter:get_wielded_item()
knockback = knockback + 3.22 * mcl_enchanting.get_enchantment(wielditem, "knockback") --knockback = knockback + 3 * mcl_enchanting.get_enchantment(wielditem, "knockback")
local enchant = mcl_enchanting.get_enchantment(wielditem, "knockback")
knockback = knockback + 3.22 * enchant
-- add vertical lift to knockback -- add vertical lift to knockback
local v = player:get_velocity() local v = player:get_velocity()
local invul = player:get_meta():get_int("mcl_damage:invulnerable") local invul = player:get_meta():get_int("mcl_damage:invulnerable")
local enchant = mcl_enchanting.get_enchantment(wielditem, "knockback")
if v and v.y <= 0.01 and v.y >= -0.01 and invul == 0 then if v and v.y <= 0.01 and v.y >= -0.01 and invul == 0 then
if dir.y <= 0.3 then if dir.y <= 0.3 then
if enchant == 0 then if enchant == 0 then