From a8806fe04e580eabbdbe583fb27c786c07cf028e Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Wed, 13 Dec 2023 17:34:42 +0000 Subject: [PATCH 01/39] Add player invulnerability & fix not continuously damaging players when holding the attack key Player invulnerability is the same as Minecraft's Damage Immunity https://minecraft.wiki/w/Damage#Immunity The old code for some reason only allows a few damage by holding and does not continuously damage other players after a few hits --- mods/PLAYER/mcl_playerplus/init.lua | 42 ++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 6cfb15bad..ed72a43b4 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -663,6 +663,8 @@ minetest.register_on_joinplayer(function(player) lastPos = nil, swimDistance = 0, jump_cooldown = -1, -- Cooldown timer for jumping, we need this to prevent the jump exhaustion to increase rapidly + last_damage = 0, + invul_timestamp = 0, } mcl_playerplus.elytra[player] = {active = false, rocketing = 0, speed = 0} @@ -727,19 +729,35 @@ mcl_damage.register_modifier(function(obj, damage, reason) end end, -200) --- damage invulnerability -mcl_damage.register_modifier(function(obj, damage, reason) - local invul = obj:get_meta():get_int("mcl_damage:invulnerable") - if invul > 0 then - return 0 - else - obj:get_meta():set_int("mcl_damage:invulnerable", 1) - minetest.after(0.5, function() - obj:get_meta():set_int("mcl_damage:invulnerable", 0) - end) - return damage +minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage) + -- damage invulnerability + if hitter then + local name = player:get_player_name() + local time_now = minetest.get_us_time() + local invul_timestamp = mcl_playerplus_internal[name].invul_timestamp + local time_diff = time_now - invul_timestamp + -- check for invulnerability time in microseconds (0.5 second) + if time_diff <= 500000 and time_diff >= 0 then + damage = damage - mcl_playerplus_internal[name].last_damage + if damage < 0 then + damage = 0 + end + return damage + else + mcl_playerplus_internal[name].last_damage = damage + mcl_playerplus_internal[name].invul_timestamp = time_now + end end -end, -1000) + -- attack reach limit + if hitter and hitter:is_player() then + local player_pos = player:get_pos() + local hitter_pos = hitter:get_pos() + if vector.distance(player_pos, hitter_pos) > 3 then + damage = 0 + return damage + end + end +end) minetest.register_on_respawnplayer(function(player) local pos = player:get_pos() From a8c2d4534a6b52c5cbee876c1d02d6d8c164814c Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Wed, 13 Dec 2023 17:42:42 +0000 Subject: [PATCH 02/39] Nerf long pvp enchanted knockbacks especially when running --- mods/ITEMS/mcl_enchanting/enchantments.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index c6436339c..6070efda9 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -278,12 +278,15 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool end if hitter and hitter:is_player() then local wielditem = hitter:get_wielded_item() - knockback = knockback + 5 * mcl_enchanting.get_enchantment(wielditem, "knockback") + knockback = knockback + 6 * mcl_enchanting.get_enchantment(wielditem, "knockback") -- add player velocity to knockback + local v = player:get_velocity() local hv = hitter:get_velocity() local dir_dot = (hv.x * dir.x) + (hv.z * dir.z) - if dir_dot > 0 then - knockback = knockback + dir_dot * 2 + local hitter_mag = math.sqrt((hv.x * hv.x) + (hv.z * hv.z)) + local player_mag = math.sqrt((v.x * v.x) + (v.z * v.z)) + if dir_dot > 0 and player_mag <= hitter_mag * 0.625 then + knockback = knockback + hitter_mag * 0.0625 end elseif luaentity and luaentity._knockback then local kb = knockback + luaentity._knockback / 4 From 96aaf89036b3994787f75642ca49c3f6a85b4b6d Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Wed, 13 Dec 2023 18:49:08 +0000 Subject: [PATCH 03/39] Readjust pvp enchant knockback to make the running knockback difference more pronounced --- mods/ITEMS/mcl_enchanting/enchantments.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 6070efda9..44db05fe3 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -278,7 +278,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool end if hitter and hitter:is_player() then local wielditem = hitter:get_wielded_item() - knockback = knockback + 6 * mcl_enchanting.get_enchantment(wielditem, "knockback") + knockback = knockback + 5 * mcl_enchanting.get_enchantment(wielditem, "knockback") -- add player velocity to knockback local v = player:get_velocity() local hv = hitter:get_velocity() @@ -286,7 +286,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool local hitter_mag = math.sqrt((hv.x * hv.x) + (hv.z * hv.z)) local player_mag = math.sqrt((v.x * v.x) + (v.z * v.z)) if dir_dot > 0 and player_mag <= hitter_mag * 0.625 then - knockback = knockback + hitter_mag * 0.0625 + knockback = knockback + hitter_mag * 0.375 end elseif luaentity and luaentity._knockback then local kb = knockback + luaentity._knockback / 4 From b0e33793ec5b1e7a48cfc6713d6f10235f1e24d6 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Wed, 13 Dec 2023 20:04:15 +0000 Subject: [PATCH 04/39] Fix a potential bug that could bypass attack reach limit when a stronger attack breaches the invul --- mods/PLAYER/mcl_playerplus/init.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index ed72a43b4..83ea1a1aa 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -730,6 +730,15 @@ mcl_damage.register_modifier(function(obj, damage, reason) end, -200) minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage) + -- attack reach limit + if hitter and hitter:is_player() then + local player_pos = player:get_pos() + local hitter_pos = hitter:get_pos() + if vector.distance(player_pos, hitter_pos) > 3 then + damage = 0 + return damage + end + end -- damage invulnerability if hitter then local name = player:get_player_name() @@ -748,15 +757,6 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, mcl_playerplus_internal[name].invul_timestamp = time_now end end - -- attack reach limit - if hitter and hitter:is_player() then - local player_pos = player:get_pos() - local hitter_pos = hitter:get_pos() - if vector.distance(player_pos, hitter_pos) > 3 then - damage = 0 - return damage - end - end end) minetest.register_on_respawnplayer(function(player) From 2b71462c1e3e983bb4f1a27c2a0afd2a4994ea7e Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Wed, 13 Dec 2023 20:36:54 +0000 Subject: [PATCH 05/39] Prevent knockback if player is beyond attack reach limit --- mods/ITEMS/mcl_enchanting/enchantments.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 44db05fe3..23145c176 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -276,7 +276,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool if hitter then luaentity = hitter:get_luaentity() end - if hitter and hitter:is_player() then + if hitter and hitter:is_player() and distance <= 3 then local wielditem = hitter:get_wielded_item() knockback = knockback + 5 * mcl_enchanting.get_enchantment(wielditem, "knockback") -- add player velocity to knockback @@ -288,6 +288,8 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool if dir_dot > 0 and player_mag <= hitter_mag * 0.625 then knockback = knockback + hitter_mag * 0.375 end + elseif hitter and hitter:is_player() and distance > 3 then + knockback = 0 elseif luaentity and luaentity._knockback then local kb = knockback + luaentity._knockback / 4 local punch_dir = dir From 85b1f5247a691f56201a452db31e0705d6d84e4a Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Thu, 14 Dec 2023 07:46:16 +0000 Subject: [PATCH 06/39] Add vertical lift & minimum pvp knockback --- mods/ITEMS/mcl_enchanting/enchantments.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 23145c176..741621f22 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -279,8 +279,20 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool if hitter and hitter:is_player() and distance <= 3 then local wielditem = hitter:get_wielded_item() knockback = knockback + 5 * mcl_enchanting.get_enchantment(wielditem, "knockback") - -- add player velocity to knockback + -- add vertical lift to knockback local v = player:get_velocity() + if v and v.y <= 0.1 and v.y >= -0.1 and dir.y <= 0.44 then + player:add_velocity({ + x = 0, + y = 4.5, + z = 0 + }) + -- add minimum knockback + if knockback <= 1.5 then + knockback = knockback + 6 + end + end + -- add player velocity to knockback local hv = hitter:get_velocity() local dir_dot = (hv.x * dir.x) + (hv.z * dir.z) local hitter_mag = math.sqrt((hv.x * hv.x) + (hv.z * hv.z)) From b2507c36407237f225d4bab47db34ab04da01c0c Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Thu, 14 Dec 2023 08:12:13 +0000 Subject: [PATCH 07/39] Make fire aspect enchant respect attack reach limit --- mods/ITEMS/mcl_enchanting/enchantments.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 741621f22..399081d00 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -133,7 +133,11 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, if wielditem then local fire_aspect_level = mcl_enchanting.get_enchantment(wielditem, "fire_aspect") if fire_aspect_level > 0 then - mcl_burning.set_on_fire(player, fire_aspect_level * 4) + local player_pos = player:get_pos() + local hitter_pos = hitter:get_pos() + if vector.distance(hitter_pos, player_pos) <= 3 then + mcl_burning.set_on_fire(player, fire_aspect_level * 4) + end end end end From ed507d8509caae7dcda9f01bde756ba3c9e10cb6 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Thu, 14 Dec 2023 08:15:55 +0000 Subject: [PATCH 08/39] Remove unnecessary space in the attack reach limit on mobs code --- mods/ENTITIES/mcl_mobs/combat.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index 4396f3265..5135aff7b 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -522,7 +522,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir) if is_player then -- is mob out of reach? - if vector.distance(mob_pos, player_pos) > 3 then + if vector.distance(mob_pos, player_pos) > 3 then return end -- is mob protected? From 49af5d2013b1330649394d3f302b648df5d05073 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Thu, 14 Dec 2023 08:51:34 +0000 Subject: [PATCH 09/39] Rebalance minimum pvp knockback to account for added knockbacks when moving --- mods/ITEMS/mcl_enchanting/enchantments.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 399081d00..34d4c1930 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -293,7 +293,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool }) -- add minimum knockback if knockback <= 1.5 then - knockback = knockback + 6 + knockback = knockback + 4.5 end end -- add player velocity to knockback From bf9e487fa9fab03579bafc2b60442773d946f3e3 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Thu, 14 Dec 2023 09:27:28 +0000 Subject: [PATCH 10/39] Adjust minimum pvp knockback to be closer to MC --- mods/ITEMS/mcl_enchanting/enchantments.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 34d4c1930..12172ea3e 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -293,7 +293,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool }) -- add minimum knockback if knockback <= 1.5 then - knockback = knockback + 4.5 + knockback = knockback + 4.875 end end -- add player velocity to knockback From 6b439fd1dedba5ff4c62e880846dd407dcf1bf47 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Thu, 14 Dec 2023 11:57:55 +0000 Subject: [PATCH 11/39] Add maximum pvp knockback limit & approximate enchant knockback distance to be similar to MC --- mods/ITEMS/mcl_enchanting/enchantments.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 12172ea3e..a9fd40714 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -282,7 +282,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool end if hitter and hitter:is_player() and distance <= 3 then local wielditem = hitter:get_wielded_item() - knockback = knockback + 5 * mcl_enchanting.get_enchantment(wielditem, "knockback") + knockback = knockback + 3 * mcl_enchanting.get_enchantment(wielditem, "knockback") -- add vertical lift to knockback local v = player:get_velocity() if v and v.y <= 0.1 and v.y >= -0.1 and dir.y <= 0.44 then @@ -304,6 +304,10 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool if dir_dot > 0 and player_mag <= hitter_mag * 0.625 then knockback = knockback + hitter_mag * 0.375 end + -- add maximum knockback limit + if knockback > 12.875 then + knockback = 12.875 + end elseif hitter and hitter:is_player() and distance > 3 then knockback = 0 elseif luaentity and luaentity._knockback then From 60367cdbe043e5afeb1ee092e2a55bec1d497272 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Fri, 15 Dec 2023 15:42:49 +0000 Subject: [PATCH 12/39] Revert unreliable bugfix There are times when the continuous damage when punching players does not happen so will not fix at the moment as using other weapons does still work. --- mods/PLAYER/mcl_playerplus/init.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 83ea1a1aa..99230bf9a 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -664,7 +664,6 @@ minetest.register_on_joinplayer(function(player) swimDistance = 0, jump_cooldown = -1, -- Cooldown timer for jumping, we need this to prevent the jump exhaustion to increase rapidly last_damage = 0, - invul_timestamp = 0, } mcl_playerplus.elytra[player] = {active = false, rocketing = 0, speed = 0} @@ -742,11 +741,9 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, -- damage invulnerability if hitter then local name = player:get_player_name() - local time_now = minetest.get_us_time() - local invul_timestamp = mcl_playerplus_internal[name].invul_timestamp - local time_diff = time_now - invul_timestamp - -- check for invulnerability time in microseconds (0.5 second) - if time_diff <= 500000 and time_diff >= 0 then + -- check for invulnerability time for 0.5 second + local invul = player:get_meta():get_int("mcl_damage:invulnerable") + if invul > 0 then damage = damage - mcl_playerplus_internal[name].last_damage if damage < 0 then damage = 0 @@ -754,7 +751,10 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, return damage else mcl_playerplus_internal[name].last_damage = damage - mcl_playerplus_internal[name].invul_timestamp = time_now + player:get_meta():set_int("mcl_damage:invulnerable", 1) + minetest.after(0.5, function() + player:get_meta():set_int("mcl_damage:invulnerable", 0) + end) end end end) From ca556c052ff46d3c4856c26ba57fcbf90bd1adff Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Fri, 15 Dec 2023 15:52:26 +0000 Subject: [PATCH 13/39] Prevent pvp knockbacks when invulnerable --- mods/ITEMS/mcl_enchanting/enchantments.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index a9fd40714..5f3971f60 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -285,7 +285,8 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool knockback = knockback + 3 * mcl_enchanting.get_enchantment(wielditem, "knockback") -- add vertical lift to knockback local v = player:get_velocity() - if v and v.y <= 0.1 and v.y >= -0.1 and dir.y <= 0.44 then + local invul = player:get_meta():get_int("mcl_damage:invulnerable") + if v and v.y <= 0.1 and v.y >= -0.1 and dir.y <= 0.44 and invul == 0 then player:add_velocity({ x = 0, y = 4.5, @@ -308,6 +309,10 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool if knockback > 12.875 then knockback = 12.875 end + -- remove knockback if invulnerable + if invul > 0 then + knockback = 0 + end elseif hitter and hitter:is_player() and distance > 3 then knockback = 0 elseif luaentity and luaentity._knockback then From 8e2c5249f54d677a14eae674d8fd7682b1973ac6 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Fri, 15 Dec 2023 15:59:08 +0000 Subject: [PATCH 14/39] Fix comment on player invul code --- mods/PLAYER/mcl_playerplus/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 99230bf9a..27eec4845 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -741,7 +741,7 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, -- damage invulnerability if hitter then local name = player:get_player_name() - -- check for invulnerability time for 0.5 second + -- check for invulnerability time (0.5 second) local invul = player:get_meta():get_int("mcl_damage:invulnerable") if invul > 0 then damage = damage - mcl_playerplus_internal[name].last_damage From d7b10d18d8872ff21fb4a5f1505afa799c6d5d83 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Fri, 15 Dec 2023 16:27:09 +0000 Subject: [PATCH 15/39] Fix not being able to give minimum knockback to players when both near and lower than them --- mods/ITEMS/mcl_enchanting/enchantments.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 5f3971f60..b157f3211 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -286,12 +286,14 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool -- add vertical lift to knockback local v = player:get_velocity() local invul = player:get_meta():get_int("mcl_damage:invulnerable") - if v and v.y <= 0.1 and v.y >= -0.1 and dir.y <= 0.44 and invul == 0 then - player:add_velocity({ - x = 0, - y = 4.5, - z = 0 - }) + if v and v.y <= 0.1 and v.y >= -0.1 and invul == 0 then + if dir.y <= 0.44 then + player:add_velocity({ + x = 0, + y = 4.5, + z = 0 + }) + end -- add minimum knockback if knockback <= 1.5 then knockback = knockback + 4.875 From cd83305f07572d68b2ea6ea8b5fc25356e59d499 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Fri, 15 Dec 2023 18:17:15 +0000 Subject: [PATCH 16/39] Make the vertical lift on pvp knockback similar to MC --- mods/ITEMS/mcl_enchanting/enchantments.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index b157f3211..b4092fe93 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -288,11 +288,11 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool local invul = player:get_meta():get_int("mcl_damage:invulnerable") if v and v.y <= 0.1 and v.y >= -0.1 and invul == 0 then if dir.y <= 0.44 then - player:add_velocity({ - x = 0, - y = 4.5, - z = 0 - }) + if mcl_enchanting.get_enchantment(wielditem, "knockback") == 0 then + player:add_velocity({x = 0, y = 6.4, z = 0}) + else + player:add_velocity({x = 0, y = 7, z = 0}) + end end -- add minimum knockback if knockback <= 1.5 then From c9692c622481c45eac3213caeea8aa73ccf7cbd3 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Fri, 15 Dec 2023 19:49:04 +0000 Subject: [PATCH 17/39] Fix player invulnerability not getting disabled permanently bug --- mods/PLAYER/mcl_playerplus/init.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 27eec4845..9b819142e 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -664,6 +664,7 @@ minetest.register_on_joinplayer(function(player) swimDistance = 0, jump_cooldown = -1, -- Cooldown timer for jumping, we need this to prevent the jump exhaustion to increase rapidly last_damage = 0, + invul_timestamp = 0, } mcl_playerplus.elytra[player] = {active = false, rocketing = 0, speed = 0} @@ -741,9 +742,15 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, -- damage invulnerability if hitter then local name = player:get_player_name() - -- check for invulnerability time (0.5 second) - local invul = player:get_meta():get_int("mcl_damage:invulnerable") - if invul > 0 then + local time_now = minetest.get_us_time() + local invul_timestamp = mcl_playerplus_internal[name].invul_timestamp + local time_diff = time_now - invul_timestamp + -- check for invulnerability time in microseconds (0.5 second) + if time_diff <= 500000 and time_diff >= 0 then + player:get_meta():set_int("mcl_damage:invulnerable", 1) + minetest.after(0.5, function() + player:get_meta():set_int("mcl_damage:invulnerable", 0) + end) damage = damage - mcl_playerplus_internal[name].last_damage if damage < 0 then damage = 0 @@ -751,10 +758,11 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, return damage else mcl_playerplus_internal[name].last_damage = damage - player:get_meta():set_int("mcl_damage:invulnerable", 1) - minetest.after(0.5, function() + mcl_playerplus_internal[name].invul_timestamp = time_now + local invul = player:get_meta():get_int("mcl_damage:invulnerable") + if invul > 0 then player:get_meta():set_int("mcl_damage:invulnerable", 0) - end) + end end end end) From 9b9747b3d8e82f6df14b58350890a42963e84909 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Fri, 15 Dec 2023 21:02:07 +0000 Subject: [PATCH 18/39] Prevent excessive vertical knockbacks if hit by a player from below --- mods/ITEMS/mcl_enchanting/enchantments.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index b4092fe93..4160da19f 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -286,7 +286,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool -- add vertical lift to knockback local v = player:get_velocity() local invul = player:get_meta():get_int("mcl_damage:invulnerable") - if v and v.y <= 0.1 and v.y >= -0.1 and invul == 0 then + if v and v.y <= 0.01 and v.y >= -0.01 and invul == 0 then if dir.y <= 0.44 then if mcl_enchanting.get_enchantment(wielditem, "knockback") == 0 then player:add_velocity({x = 0, y = 6.4, z = 0}) @@ -311,6 +311,9 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool if knockback > 12.875 then knockback = 12.875 end + if knockback > 6.4375 and dir.y >= 0.3 then + knockback = 6.4375 + end -- remove knockback if invulnerable if invul > 0 then knockback = 0 From f799596db9d33f5aba90d7819120834efeeb9815 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Fri, 15 Dec 2023 22:56:02 +0000 Subject: [PATCH 19/39] Make vertical pvp knockbacks respect attack reach limit & complete excess vertical kb prevention --- mods/ITEMS/mcl_enchanting/enchantments.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 4160da19f..f792014d7 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -287,7 +287,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool local v = player:get_velocity() local invul = player:get_meta():get_int("mcl_damage:invulnerable") if v and v.y <= 0.01 and v.y >= -0.01 and invul == 0 then - if dir.y <= 0.44 then + if dir.y <= 0.44 and distance <= 3 then if mcl_enchanting.get_enchantment(wielditem, "knockback") == 0 then player:add_velocity({x = 0, y = 6.4, z = 0}) else @@ -313,6 +313,8 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool end if knockback > 6.4375 and dir.y >= 0.3 then knockback = 6.4375 + elseif knockback <= 6.4375 and dir.y >= 0.3 then + knockback = 1 end -- remove knockback if invulnerable if invul > 0 then From 33e8337bbb57919f6419a0187ffd19a5cab05b15 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sat, 16 Dec 2023 07:58:26 +0000 Subject: [PATCH 20/39] Finish remaining excessive vertical pvp knockback prevention adjustments when hit from below --- mods/ITEMS/mcl_enchanting/enchantments.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index f792014d7..3c03cc846 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -286,13 +286,16 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool -- add vertical lift to knockback local v = player:get_velocity() 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 dir.y <= 0.44 and distance <= 3 then - if mcl_enchanting.get_enchantment(wielditem, "knockback") == 0 then + if dir.y <= 0.3 then + if enchant == 0 then player:add_velocity({x = 0, y = 6.4, z = 0}) else player:add_velocity({x = 0, y = 7, z = 0}) end + elseif dir.y <= 0.44 and dir.y > 0.3 and enchant > 0 then + knockback = knockback + 3 end -- add minimum knockback if knockback <= 1.5 then @@ -311,10 +314,8 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool if knockback > 12.875 then knockback = 12.875 end - if knockback > 6.4375 and dir.y >= 0.3 then - knockback = 6.4375 - elseif knockback <= 6.4375 and dir.y >= 0.3 then - knockback = 1 + if knockback > 6.275 and dir.y >= 0.3 and v.y == 0 and enchant == 0 then + knockback = 6.275 end -- remove knockback if invulnerable if invul > 0 then From cfab59d68a2bfafb814b980d947b3b1b5e1848c6 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sat, 16 Dec 2023 09:20:29 +0000 Subject: [PATCH 21/39] Rebalanced moving pvp knockbacks --- mods/ITEMS/mcl_enchanting/enchantments.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 3c03cc846..fdcb66388 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -282,7 +282,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool end if hitter and hitter:is_player() and distance <= 3 then local wielditem = hitter:get_wielded_item() - knockback = knockback + 3 * mcl_enchanting.get_enchantment(wielditem, "knockback") + knockback = knockback + 3.22 * mcl_enchanting.get_enchantment(wielditem, "knockback") -- add vertical lift to knockback local v = player:get_velocity() local invul = player:get_meta():get_int("mcl_damage:invulnerable") @@ -308,12 +308,9 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool local hitter_mag = math.sqrt((hv.x * hv.x) + (hv.z * hv.z)) local player_mag = math.sqrt((v.x * v.x) + (v.z * v.z)) if dir_dot > 0 and player_mag <= hitter_mag * 0.625 then - knockback = knockback + hitter_mag * 0.375 - end - -- add maximum knockback limit - if knockback > 12.875 then - knockback = 12.875 + knockback = knockback + hitter_mag * 0.6875 end + -- add vertical knockback limit on angled hit if knockback > 6.275 and dir.y >= 0.3 and v.y == 0 and enchant == 0 then knockback = 6.275 end From 8fbd72c1422061a0b99bf3916e3af7f0bca449bc Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sat, 16 Dec 2023 09:46:18 +0000 Subject: [PATCH 22/39] Optimize code by calling get_enchantment function only once --- mods/ITEMS/mcl_enchanting/enchantments.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index fdcb66388..6194945a7 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -282,11 +282,12 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool end if hitter and hitter:is_player() and distance <= 3 then 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 local v = player:get_velocity() 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 dir.y <= 0.3 then if enchant == 0 then From 32e91b45ae5d6f84844b0db927dfe650da274af1 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sat, 16 Dec 2023 11:48:16 +0000 Subject: [PATCH 23/39] Add vertical pvp knockbacks from downward hits & reduce pvp kb on half block angled upward hits --- mods/ITEMS/mcl_enchanting/enchantments.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 6194945a7..836a13a65 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -290,10 +290,16 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool local invul = player:get_meta():get_int("mcl_damage:invulnerable") if v and v.y <= 0.01 and v.y >= -0.01 and invul == 0 then if dir.y <= 0.3 then + local regular_v = 6.4 + local enchant_v = 7 + if dir.y <= 0.27 then + regular_v = regular_v * math.abs(dir.y - 1) + enchant_v = enchant_v * math.abs(dir.y - 1) + end if enchant == 0 then - player:add_velocity({x = 0, y = 6.4, z = 0}) + player:add_velocity({x = 0, y = regular_v, z = 0}) else - player:add_velocity({x = 0, y = 7, z = 0}) + player:add_velocity({x = 0, y = enchant_v, z = 0}) end elseif dir.y <= 0.44 and dir.y > 0.3 and enchant > 0 then knockback = knockback + 3 From e8ee9c44635657862dcf54e59f829ddec1a0ed09 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sat, 16 Dec 2023 12:58:58 +0000 Subject: [PATCH 24/39] Remove obsolete work-around code --- mods/ITEMS/mcl_enchanting/enchantments.lua | 26 +++++++--------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 836a13a65..28cb1083c 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -289,20 +289,14 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool local v = player:get_velocity() local invul = player:get_meta():get_int("mcl_damage:invulnerable") if v and v.y <= 0.01 and v.y >= -0.01 and invul == 0 then - if dir.y <= 0.3 then - local regular_v = 6.4 - local enchant_v = 7 - if dir.y <= 0.27 then - regular_v = regular_v * math.abs(dir.y - 1) - enchant_v = enchant_v * math.abs(dir.y - 1) - end - if enchant == 0 then - player:add_velocity({x = 0, y = regular_v, z = 0}) - else - player:add_velocity({x = 0, y = enchant_v, z = 0}) - end - elseif dir.y <= 0.44 and dir.y > 0.3 and enchant > 0 then - knockback = knockback + 3 + local regular_v = 6.4 + local enchant_v = 7 + regular_v = regular_v * math.abs(dir.y - 1) + enchant_v = enchant_v * math.abs(dir.y - 1) + if enchant == 0 then + player:add_velocity({x = 0, y = regular_v, z = 0}) + else + player:add_velocity({x = 0, y = enchant_v, z = 0}) end -- add minimum knockback if knockback <= 1.5 then @@ -317,10 +311,6 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool if dir_dot > 0 and player_mag <= hitter_mag * 0.625 then knockback = knockback + hitter_mag * 0.6875 end - -- add vertical knockback limit on angled hit - if knockback > 6.275 and dir.y >= 0.3 and v.y == 0 and enchant == 0 then - knockback = 6.275 - end -- remove knockback if invulnerable if invul > 0 then knockback = 0 From 0a8874ecad38bf8e9738a2cba67a2f83d0e782cf Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sun, 17 Dec 2023 16:39:04 +0000 Subject: [PATCH 25/39] Make vertical pvp knockbacks less floaty --- mods/ITEMS/mcl_enchanting/enchantments.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 28cb1083c..1d065db3b 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -291,13 +291,19 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool if v and v.y <= 0.01 and v.y >= -0.01 and invul == 0 then local regular_v = 6.4 local enchant_v = 7 + local added_v = 0 regular_v = regular_v * math.abs(dir.y - 1) enchant_v = enchant_v * math.abs(dir.y - 1) if enchant == 0 then player:add_velocity({x = 0, y = regular_v, z = 0}) + added_v = regular_v else player:add_velocity({x = 0, y = enchant_v, z = 0}) + added_v = enchant_v end + minetest.after(0.25, function() + player:add_velocity({x = 0, y = -added_v * 0.375 , z = 0}) + end) -- add minimum knockback if knockback <= 1.5 then knockback = knockback + 4.875 From 8612350fa786053d42eb51260f72b4cc4059835a Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sun, 17 Dec 2023 17:48:39 +0000 Subject: [PATCH 26/39] Make vertical pvp knockback floatiness reduction include moving hits --- mods/ITEMS/mcl_enchanting/enchantments.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 1d065db3b..05a1e7531 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -287,11 +287,11 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool knockback = knockback + 3.22 * enchant -- add vertical lift to knockback local v = player:get_velocity() + local added_v = 0 local invul = player:get_meta():get_int("mcl_damage:invulnerable") if v and v.y <= 0.01 and v.y >= -0.01 and invul == 0 then local regular_v = 6.4 local enchant_v = 7 - local added_v = 0 regular_v = regular_v * math.abs(dir.y - 1) enchant_v = enchant_v * math.abs(dir.y - 1) if enchant == 0 then @@ -301,9 +301,6 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool player:add_velocity({x = 0, y = enchant_v, z = 0}) added_v = enchant_v end - minetest.after(0.25, function() - player:add_velocity({x = 0, y = -added_v * 0.375 , z = 0}) - end) -- add minimum knockback if knockback <= 1.5 then knockback = knockback + 4.875 @@ -317,6 +314,10 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool if dir_dot > 0 and player_mag <= hitter_mag * 0.625 then knockback = knockback + hitter_mag * 0.6875 end + -- reduce floatiness + minetest.after(0.25, function() + player:add_velocity({x = 0, y = (v.y + added_v) * -0.375 , z = 0}) + end) -- remove knockback if invulnerable if invul > 0 then knockback = 0 From 6d7ae8ba2df7e4d2639f0e22cef3fb69e3423468 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sun, 17 Dec 2023 19:59:18 +0000 Subject: [PATCH 27/39] Add minimum unenchanted knockback to bow --- mods/ITEMS/mcl_bows/bow.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 174208c3c..188035b99 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -49,6 +49,8 @@ function mcl_bows.shoot_arrow(arrow_item, pos, dir, yaw, shooter, power, damage, end if enchantments.punch then knockback = enchantments.punch * 21 + else + knockback = 4.875 end if enchantments.flame then mcl_burning.set_on_fire(obj, math.huge) From c39e55e2d4e4ce878cc04947aecdcf7590fe7f0e Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sun, 17 Dec 2023 20:01:35 +0000 Subject: [PATCH 28/39] Add minimum knockback to crossbow --- mods/ITEMS/mcl_bows/crossbow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_bows/crossbow.lua b/mods/ITEMS/mcl_bows/crossbow.lua index df7b5f560..fcc60c460 100644 --- a/mods/ITEMS/mcl_bows/crossbow.lua +++ b/mods/ITEMS/mcl_bows/crossbow.lua @@ -48,7 +48,7 @@ function mcl_bows_s.shoot_arrow_crossbow(arrow_item, pos, dir, yaw, shooter, pow if damage == nil then damage = 3 end - local knockback + local knockback = 4.875 if crossbow_stack then local enchantments = mcl_enchanting.get_enchantments(crossbow_stack) if enchantments.piercing then From 200f7451ebfaff94653bca4f9d89495f4e04c6a7 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sun, 17 Dec 2023 21:15:55 +0000 Subject: [PATCH 29/39] Remove unnecessary invul code & add damage animation code --- mods/PLAYER/mcl_playerplus/init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 9b819142e..e3d323854 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -759,10 +759,10 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, else mcl_playerplus_internal[name].last_damage = damage mcl_playerplus_internal[name].invul_timestamp = time_now - local invul = player:get_meta():get_int("mcl_damage:invulnerable") - if invul > 0 then - player:get_meta():set_int("mcl_damage:invulnerable", 0) - end + player:get_meta():set_int("mcl_damage:damage_animation", 1) + minetest.after(0.5, function() + player:get_meta():set_int("mcl_damage:damage_animation", 0) + end) end end end) From 12109e7f44c49f5f4c8815717377a2a5410f12fc Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sun, 17 Dec 2023 21:18:57 +0000 Subject: [PATCH 30/39] Add player damage animation --- mods/PLAYER/mcl_player/init.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mods/PLAYER/mcl_player/init.lua b/mods/PLAYER/mcl_player/init.lua index 288b697e1..8ebcedccf 100644 --- a/mods/PLAYER/mcl_player/init.lua +++ b/mods/PLAYER/mcl_player/init.lua @@ -228,6 +228,8 @@ minetest.register_globalstep(function(dtime) -- Apply animations based on what the player is doing if player:get_hp() == 0 then player_set_animation(player, "die") + elseif player:get_meta():get_int("mcl_damage:damage_animation") > 0 then + player_set_animation(player, "walk", animation_speed_mod) elseif mcl_playerplus.elytra[player] and mcl_playerplus.elytra[player].active then player_set_animation(player, "stand") elseif walking and velocity.x > 0.35 From 14cec16c63445e8f021645b761c3ad3fd5972644 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Mon, 18 Dec 2023 21:31:38 +0000 Subject: [PATCH 31/39] Increase enchanted bow knockback --- mods/ITEMS/mcl_bows/bow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 188035b99..e4e34610d 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -48,7 +48,7 @@ function mcl_bows.shoot_arrow(arrow_item, pos, dir, yaw, shooter, power, damage, damage = damage + (enchantments.power + 1) / 4 end if enchantments.punch then - knockback = enchantments.punch * 21 + knockback = enchantments.punch * 24 else knockback = 4.875 end From fe90424ee4797e54238d1ba1cf913a4389fc6b59 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Mon, 18 Dec 2023 21:42:26 +0000 Subject: [PATCH 32/39] Add pvp knockback reduction when moving towards player while attacking --- mods/ITEMS/mcl_enchanting/enchantments.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 05a1e7531..db2aa9da6 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -316,8 +316,14 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool end -- reduce floatiness minetest.after(0.25, function() - player:add_velocity({x = 0, y = (v.y + added_v) * -0.375 , z = 0}) + player:add_velocity({x = 0, y = (v.y + added_v) * -0.375, z = 0}) end) + -- reduce knockback when moving towards hitter while attacking + local self_dir_dot = (v.x * dir.x) + (v.z * dir.z) + local control = player:get_player_control() + if self_dir_dot < -4.3 and control.up and control.LMB then + knockback = knockback * 0.6 + end -- remove knockback if invulnerable if invul > 0 then knockback = 0 From 44c656502f4858a5e779e590307a01e3444543fb Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Mon, 18 Dec 2023 22:04:12 +0000 Subject: [PATCH 33/39] Add a prevention in case players get stuck with the damage animation --- mods/PLAYER/mcl_player/init.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mods/PLAYER/mcl_player/init.lua b/mods/PLAYER/mcl_player/init.lua index 8ebcedccf..9681fa86f 100644 --- a/mods/PLAYER/mcl_player/init.lua +++ b/mods/PLAYER/mcl_player/init.lua @@ -230,6 +230,9 @@ minetest.register_globalstep(function(dtime) player_set_animation(player, "die") elseif player:get_meta():get_int("mcl_damage:damage_animation") > 0 then player_set_animation(player, "walk", animation_speed_mod) + minetest.after(0.5, function() + player:get_meta():set_int("mcl_damage:damage_animation", 0) + end) elseif mcl_playerplus.elytra[player] and mcl_playerplus.elytra[player].active then player_set_animation(player, "stand") elseif walking and velocity.x > 0.35 From d7ed37ef25e14b0451a627809e34599dd96dc436 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Tue, 19 Dec 2023 15:31:29 +0000 Subject: [PATCH 34/39] Remove redundant knockback limiter --- mods/ITEMS/mcl_enchanting/enchantments.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index db2aa9da6..c26df61d9 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -311,7 +311,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool local dir_dot = (hv.x * dir.x) + (hv.z * dir.z) local hitter_mag = math.sqrt((hv.x * hv.x) + (hv.z * hv.z)) local player_mag = math.sqrt((v.x * v.x) + (v.z * v.z)) - if dir_dot > 0 and player_mag <= hitter_mag * 0.625 then + if dir_dot > 0 then knockback = knockback + hitter_mag * 0.6875 end -- reduce floatiness From ff882707def990b5e30eede831a7f4aa43626a1d Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Tue, 19 Dec 2023 16:15:41 +0000 Subject: [PATCH 35/39] Rework moving majority of the added velocity knockbacks into sprinting --- mods/ITEMS/mcl_enchanting/enchantments.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index c26df61d9..7744f2c7e 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -307,12 +307,15 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool end end -- add player velocity to knockback + local h_name = hitter:get_player_name() local hv = hitter:get_velocity() local dir_dot = (hv.x * dir.x) + (hv.z * dir.z) local hitter_mag = math.sqrt((hv.x * hv.x) + (hv.z * hv.z)) local player_mag = math.sqrt((v.x * v.x) + (v.z * v.z)) - if dir_dot > 0 then + if dir_dot > 0 and mcl_sprint.is_sprinting(h_name) then knockback = knockback + hitter_mag * 0.6875 + elseif dir_dot > 0 then + knockback = knockback + hitter_mag * 0.34375 end -- reduce floatiness minetest.after(0.25, function() From 76bff2b540b55b644aa2f07b79ad5db17c1c5dca Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Tue, 19 Dec 2023 16:49:48 +0000 Subject: [PATCH 36/39] Add minimum pvp knockbacks to other meele weapons --- mods/ITEMS/mcl_enchanting/enchantments.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 7744f2c7e..60e8a6c99 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -304,6 +304,8 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool -- add minimum knockback if knockback <= 1.5 then knockback = knockback + 4.875 + elseif knockback <= 6.19 then + knockback = knockback + 0.609375 end end -- add player velocity to knockback From e19de859903e3b75a4378d560162f52b53619c71 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Tue, 19 Dec 2023 17:19:09 +0000 Subject: [PATCH 37/39] Adjust the difference between sprinting & walking knockbacks for a more seemless transition --- mods/ITEMS/mcl_enchanting/enchantments.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 60e8a6c99..29fdab6f6 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -317,7 +317,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool if dir_dot > 0 and mcl_sprint.is_sprinting(h_name) then knockback = knockback + hitter_mag * 0.6875 elseif dir_dot > 0 then - knockback = knockback + hitter_mag * 0.34375 + knockback = knockback + hitter_mag * 0.515625 end -- reduce floatiness minetest.after(0.25, function() From 96fa6c251ef59acaed76b6e65e4a7af795cb62b6 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Wed, 20 Dec 2023 15:50:37 +0000 Subject: [PATCH 38/39] Counteract self forward velocity when hit by players in pvp --- mods/ITEMS/mcl_enchanting/enchantments.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 29fdab6f6..bd9b4047d 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -308,6 +308,11 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool knockback = knockback + 0.609375 end end + -- counteract forward velocity when hit + local self_dir_dot = (v.x * dir.x) + (v.z * dir.z) + if self_dir_dot < 0 then + player:add_velocity({x = v.x * -1, y = 0, z = v.z * -1}) + end -- add player velocity to knockback local h_name = hitter:get_player_name() local hv = hitter:get_velocity() From 10dcdb7d6b546171d5e4eb62881aed9b1d5ffd2c Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Thu, 21 Dec 2023 15:52:26 +0000 Subject: [PATCH 39/39] Remove unnecessary player vector magnitude calculation --- mods/ITEMS/mcl_enchanting/enchantments.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index bd9b4047d..591dfb679 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -318,7 +318,6 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool local hv = hitter:get_velocity() local dir_dot = (hv.x * dir.x) + (hv.z * dir.z) local hitter_mag = math.sqrt((hv.x * hv.x) + (hv.z * hv.z)) - local player_mag = math.sqrt((v.x * v.x) + (v.z * v.z)) if dir_dot > 0 and mcl_sprint.is_sprinting(h_name) then knockback = knockback + hitter_mag * 0.6875 elseif dir_dot > 0 then