1
0
Fork 0

Add missing shield features + tweaks & fixes

Features:

- Add being able to be damaged by piercing crossbow enchant
- Add being disabled for 5 seconds when attacked with axe

Tweaks:

- Disable guarding when eating

Fixes:

- Fix not being able to guard when pointing to a node/block
- Fix shield guarding movement slowdown sometimes getting stuck on login
- Attempt at fixing shield activating when in menu/formspec bug
This commit is contained in:
Eliy21 2024-01-26 16:02:11 +00:00
parent c31226041f
commit 3b045f624b
1 changed files with 48 additions and 3 deletions

View File

@ -151,6 +151,10 @@ mcl_damage.register_modifier(function(obj, damage, reason)
return return
end end
if damager and damager:get_luaentity() and damager:get_luaentity()._piercing and damager:get_luaentity()._piercing > 0 then
return
end
local durability = 336 local durability = 336
local unbreaking = mcl_enchanting.get_enchantment(shieldstack, mcl_shields.enchantments[2]) local unbreaking = mcl_enchanting.get_enchantment(shieldstack, mcl_shields.enchantments[2])
if unbreaking > 0 then if unbreaking > 0 then
@ -167,6 +171,23 @@ mcl_damage.register_modifier(function(obj, damage, reason)
end end
end end
minetest.sound_play({name = "mcl_block"}, {pos = obj:get_pos(), max_hear_distance = 16}) minetest.sound_play({name = "mcl_block"}, {pos = obj:get_pos(), max_hear_distance = 16})
if mcl_shields.is_blocking(obj) and damager and damager:get_wielded_item() and damager:get_wielded_item():get_name() and
(damager:get_wielded_item():get_name() == "mcl_tools:axe_wood" or
damager:get_wielded_item():get_name() == "mcl_tools:axe_stone" or
damager:get_wielded_item():get_name() == "mcl_tools:axe_iron" or
damager:get_wielded_item():get_name() == "mcl_tools:axe_gold" or
damager:get_wielded_item():get_name() == "mcl_tools:axe_diamond" or
damager:get_wielded_item():get_name() == "mcl_tools:axe_netherite") then
mcl_shields.players[obj].cooldown = 5
elseif mcl_shields.is_blocking(obj) and damager and damager:get_luaentity() and damager:get_luaentity().name and
(damager:get_luaentity().name == "mobs_mc:vindicator" or
damager:get_luaentity().name == "mobs_mc:piglin_brute") then
mcl_shields.players[obj].cooldown = 5
end
return 0 return 0
end) end)
@ -265,11 +286,19 @@ local function handle_blocking(player)
local pos = player:get_pos() local pos = player:get_pos()
if shield_in_hand then if shield_in_hand then
if mcl_shields.players[player].cooldown ~= 0 then
player_shield.blocking = 0
return
end
if not_blocking then if not_blocking then
minetest.after(0.25, function() minetest.after(0.25, function()
if (not_blocking or not shield_in_offhand) and shield_in_hand and rmb then rmb = player:get_player_control().RMB
if (not_blocking or not shield_in_offhand) and shield_in_hand and rmb and not mcl_hunger.is_eating(player) and mcl_shields.players[player].cooldown == 0 then
player_shield.blocking = 2 player_shield.blocking = 2
set_shield(player, true, 2) set_shield(player, true, 2)
else
player_shield.blocking = 0
set_shield(player, false, 2)
end end
end) end)
elseif not shield_in_offhand then elseif not shield_in_offhand then
@ -277,7 +306,7 @@ local function handle_blocking(player)
end end
elseif shield_in_offhand then elseif shield_in_offhand then
local pointed_thing = mcl_util.get_pointed_thing(player, true) local pointed_thing = mcl_util.get_pointed_thing(player, true)
local offhand_can_block = (wielded_item(player) == "" or not pointed_thing) local offhand_can_block = (wielded_item(player) ~= "mcl_shields:shield")
and (minetest.get_item_group(wielded_item(player), "bow") ~= 1 and minetest.get_item_group(wielded_item(player), "crossbow") ~= 1) and (minetest.get_item_group(wielded_item(player), "bow") ~= 1 and minetest.get_item_group(wielded_item(player), "crossbow") ~= 1)
if pointed_thing and pointed_thing.type == "node" then if pointed_thing and pointed_thing.type == "node" then
@ -289,11 +318,19 @@ local function handle_blocking(player)
if not offhand_can_block then if not offhand_can_block then
return return
end end
if mcl_shields.players[player].cooldown ~= 0 then
player_shield.blocking = 0
return
end
if not_blocking then if not_blocking then
minetest.after(0.25, function() minetest.after(0.25, function()
if (not_blocking or not shield_in_hand) and shield_in_offhand and rmb and offhand_can_block then rmb = player:get_player_control().RMB
if (not_blocking or not shield_in_hand) and shield_in_offhand and rmb and offhand_can_block and not mcl_hunger.is_eating(player) and mcl_shields.players[player].cooldown == 0 then
player_shield.blocking = 1 player_shield.blocking = 1
set_shield(player, true, 1) set_shield(player, true, 1)
else
player_shield.blocking = 0
set_shield(player, false, 1)
end end
end) end)
elseif not shield_in_hand then elseif not shield_in_hand then
@ -391,6 +428,12 @@ end
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do for _, player in pairs(minetest.get_connected_players()) do
if mcl_shields.players[player].cooldown > 0 then
mcl_shields.players[player].cooldown = mcl_shields.players[player].cooldown - dtime
elseif mcl_shields.players[player].cooldown < 0 then
mcl_shields.players[player].cooldown = 0
end
handle_blocking(player) handle_blocking(player)
local blocking, shieldstack = mcl_shields.is_blocking(player) local blocking, shieldstack = mcl_shields.is_blocking(player)
@ -518,6 +561,8 @@ minetest.register_on_joinplayer(function(player)
mcl_shields.players[player] = { mcl_shields.players[player] = {
shields = {}, shields = {},
blocking = 0, blocking = 0,
cooldown = 0,
} }
remove_shield_hud(player) remove_shield_hud(player)
playerphysics.remove_physics_factor(player, "speed", "shield_speed")
end) end)