forked from VoxeLibre/VoxeLibre
Add knockback prevention/reduction when guarding
This commit is contained in:
parent
3b045f624b
commit
2b7c2e706a
|
@ -277,8 +277,15 @@ local old_calculate_knockback = minetest.calculate_knockback
|
|||
function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool_capabilities, dir, distance, damage)
|
||||
local knockback = old_calculate_knockback(player, hitter, time_from_last_punch, tool_capabilities, dir, distance, damage)
|
||||
local luaentity
|
||||
local is_blocked = false
|
||||
if hitter then
|
||||
luaentity = hitter:get_luaentity()
|
||||
-- check if attack is blocked
|
||||
local shield_dot = vector.dot(player:get_look_dir(), vector.subtract(hitter:get_pos(), player:get_pos()))
|
||||
if mcl_shields.is_blocking(player) and shield_dot >= 0 then
|
||||
is_blocked = true
|
||||
knockback = knockback * 0.5
|
||||
end
|
||||
end
|
||||
if hitter and hitter:is_player() and distance <= 3 then
|
||||
local wielditem = hitter:get_wielded_item()
|
||||
|
@ -289,7 +296,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool
|
|||
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
|
||||
if v and v.y <= 0.01 and v.y >= -0.01 and invul == 0 and not is_blocked then
|
||||
local regular_v = 6.4
|
||||
local enchant_v = 7
|
||||
regular_v = regular_v * math.abs(dir.y - 1)
|
||||
|
@ -324,9 +331,11 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool
|
|||
knockback = knockback + hitter_mag * 0.515625
|
||||
end
|
||||
-- reduce floatiness
|
||||
minetest.after(0.25, function()
|
||||
player:add_velocity({x = 0, y = (v.y + added_v) * -0.375, z = 0})
|
||||
end)
|
||||
if added_v ~= 0 then
|
||||
minetest.after(0.25, function()
|
||||
player:add_velocity({x = 0, y = (v.y + added_v) * -0.375, z = 0})
|
||||
end)
|
||||
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()
|
||||
|
@ -337,6 +346,10 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool
|
|||
if invul > 0 then
|
||||
knockback = 0
|
||||
end
|
||||
-- remove knockback if attack is blocked
|
||||
if is_blocked then
|
||||
knockback = 0
|
||||
end
|
||||
elseif hitter and hitter:is_player() and distance > 3 then
|
||||
knockback = 0
|
||||
elseif luaentity and luaentity._knockback then
|
||||
|
@ -345,7 +358,9 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool
|
|||
punch_dir.y = 0
|
||||
punch_dir = vector.normalize(punch_dir) * kb
|
||||
punch_dir.y = 4
|
||||
player:add_velocity(punch_dir)
|
||||
if not is_blocked then
|
||||
player:add_velocity(punch_dir)
|
||||
end
|
||||
knockback = 0
|
||||
end
|
||||
return knockback
|
||||
|
|
Loading…
Reference in New Issue