1
0
Fork 0

Use the dot product mathematical formula

This commit is contained in:
Eliy21 2023-11-20 13:55:55 +00:00
parent 7b7a9a34e5
commit ce1f09f679
1 changed files with 5 additions and 4 deletions

View File

@ -718,12 +718,13 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
if hitter and is_player then
local wielditem = hitter:get_wielded_item()
local hv = hitter:get_velocity()
local dir_dot = (hv.x * dir.x) + (hv.z * dir.z)
local player_mag = math.sqrt((hv.x * hv.x) + (hv.z * hv.z))
local mob_mag = math.sqrt((v.x * v.x) + (v.z * v.z))
kb = kb + 9 * mcl_enchanting.get_enchantment(wielditem, "knockback")
-- add player velocity to mob knockback
if (dir.x >= 0 and hv.x >= 0 and v.x <= hv.x) or (dir.x <= 0 and hv.x <= 0 and v.x >= hv.x) then
if (dir.z >= 0 and hv.z >= 0 and v.z <= hv.z) or (dir.z <= 0 and hv.z <= 0 and v.z >= hv.z) then
kb = kb + ((math.abs(hv.x) + math.abs(hv.z)) * r)
end
if dir_dot > 0 and mob_mag <= player_mag * 0.8 then
kb = kb + ((math.abs(hv.x) + math.abs(hv.z)) * r)
end
elseif luaentity and luaentity._knockback then
kb = kb + luaentity._knockback