From ce1f09f6793344077aceb9647eb284edcaedd496 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Mon, 20 Nov 2023 13:55:55 +0000 Subject: [PATCH] Use the dot product mathematical formula --- mods/ENTITIES/mcl_mobs/combat.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index 647e53be2..a63aa6940 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -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