Merge pull request 'Shield improvements and bugfixes (fixes #2756)' (#4582) from shieldy_shields into master

Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4582
Reviewed-by: kno10 <kno10@noreply.git.minetest.land>
Reviewed-by: the-real-herowl <the-real-herowl@noreply.git.minetest.land>
This commit is contained in:
the-real-herowl 2024-11-10 01:34:50 +01:00
commit e3b7847df1
5 changed files with 58 additions and 43 deletions

View file

@ -257,10 +257,10 @@ function ARROW_ENTITY.on_step(self, dtime)
mcl_burning.set_on_fire(obj, 5) mcl_burning.set_on_fire(obj, 5)
end end
if not self._in_player and not self._blocked then if not self._in_player and not self._blocked then
obj:punch(self.object, 1.0, { mcl_util.deal_damage(obj, self._damage, {type = "arrow", source = self._shooter, direct = self.object})
full_punch_interval=1.0, if self._extra_hit_func then
damage_groups={fleshy=self._damage}, self._extra_hit_func(obj)
}, self.object:get_velocity()) end
if obj:is_player() then if obj:is_player() then
if not mcl_shields.is_blocking(obj) then if not mcl_shields.is_blocking(obj) then
local placement local placement

View file

@ -168,7 +168,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula
itemstack:get_meta():set_string("active", "true") itemstack:get_meta():set_string("active", "true")
return itemstack return itemstack
end, end,
groups = {weapon=1,weapon_ranged=1,bow=1,enchantability=1}, groups = {weapon=1,weapon_ranged=1,bow=1,cannot_block=1,enchantability=1},
_mcl_uses = 385, _mcl_uses = 385,
}) })
@ -216,7 +216,7 @@ for level=0, 2 do
wield_scale = mcl_vars.tool_wield_scale, wield_scale = mcl_vars.tool_wield_scale,
stack_max = 1, stack_max = 1,
range = 0, -- Pointing range to 0 to prevent punching with bow :D range = 0, -- Pointing range to 0 to prevent punching with bow :D
groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1, enchantability=1}, groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1, cannot_block=1, enchantability=1},
-- Trick to disable digging as well -- Trick to disable digging as well
on_use = function() return end, on_use = function() return end,
on_drop = function(itemstack, dropper, pos) on_drop = function(itemstack, dropper, pos)

View file

@ -158,7 +158,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula
itemstack:get_meta():set_string("active", "true") itemstack:get_meta():set_string("active", "true")
return itemstack return itemstack
end, end,
groups = {weapon=1,weapon_ranged=1,crossbow=1,enchantability=1}, groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1},
_mcl_uses = 326, _mcl_uses = 326,
}) })
@ -193,7 +193,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula
itemstack:get_meta():set_string("active", "true") itemstack:get_meta():set_string("active", "true")
return itemstack return itemstack
end, end,
groups = {weapon=1,weapon_ranged=1,crossbow=1,enchantability=1,not_in_creative_inventory=1}, groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1,not_in_creative_inventory=1},
_mcl_uses = 326, _mcl_uses = 326,
}) })
@ -238,7 +238,7 @@ for level=0, 2 do
wield_scale = mcl_vars.tool_wield_scale, wield_scale = mcl_vars.tool_wield_scale,
stack_max = 1, stack_max = 1,
range = 0, -- Pointing range to 0 to prevent punching with bow :D range = 0, -- Pointing range to 0 to prevent punching with bow :D
groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1, enchantability=1}, groups = {not_in_creative_inventory=1, not_in_craft_guide=1, cannot_block=1, bow=1, enchantability=1},
-- Trick to disable digging as well -- Trick to disable digging as well
on_use = function() return end, on_use = function() return end,
on_drop = function(itemstack, dropper, pos) on_drop = function(itemstack, dropper, pos)

View file

@ -211,16 +211,37 @@ local function set_interact(player, interact)
return return
end end
local meta = player:get_meta() local meta = player:get_meta()
if meta:get_int("mcl_privs:interact_revoked") ~= 1 then
privs.interact = interact if interact and meta:get_int("mcl_shields:interact_revoked") ~= 0 then
minetest.set_player_privs(player_name, privs) meta:set_int("mcl_shields:interact_revoked", 0)
meta:set_int("mcl_privs:interact_revoked",0) privs.interact = true
elseif not interact then
meta:set_int("mcl_shields:interact_revoked", privs.interact and 1 or 0)
privs.interact = nil
end end
minetest.set_player_privs(player_name, privs)
end end
-- Prevent player from being able to circumvent interact privilage removal by
-- using shield.
minetest.register_on_priv_revoke(function(name, revoker, priv)
if priv == "interact" and revoker then
local player = minetest.get_player_by_name(name)
if not player then
return
end
local meta = player:get_meta()
meta:set_int("mcl_shields:interact_revoked", 0)
end
end)
local shield_hud = {} local shield_hud = {}
local function remove_shield_hud(player) local function remove_shield_hud(player)
set_interact(player, true)
playerphysics.remove_physics_factor(player, "speed", "shield_speed")
if not shield_hud[player] then return end --this function takes a long time. only run it when necessary if not shield_hud[player] then return end --this function takes a long time. only run it when necessary
player:hud_remove(shield_hud[player]) player:hud_remove(shield_hud[player])
shield_hud[player] = nil shield_hud[player] = nil
@ -231,9 +252,6 @@ local function remove_shield_hud(player)
if not hf.wielditem then if not hf.wielditem then
player:hud_set_flags({wielditem = true}) player:hud_set_flags({wielditem = true})
end end
playerphysics.remove_physics_factor(player, "speed", "shield_speed")
set_interact(player, true)
end end
local function add_shield_entity(player, i) local function add_shield_entity(player, i)
@ -251,6 +269,11 @@ local function remove_shield_entity(player, i)
end end
end end
local function is_rmb_conflicting_node(nodename)
local nodedef = minetest.registered_nodes[nodename] or {}
return nodedef.on_rightclick
end
local function handle_blocking(player) local function handle_blocking(player)
local player_shield = mcl_shields.players[player] local player_shield = mcl_shields.players[player]
local rmb = player:get_player_control().RMB local rmb = player:get_player_control().RMB
@ -259,14 +282,25 @@ local function handle_blocking(player)
return return
end end
local pointed_thing = mcl_util.get_pointed_thing(player, true)
local wielded_stack = player:get_wielded_item()
local shield_in_offhand = mcl_shields.wielding_shield(player, 1) local shield_in_offhand = mcl_shields.wielding_shield(player, 1)
local shield_in_hand = mcl_shields.wielding_shield(player) local shield_in_hand = mcl_shields.wielding_shield(player)
local not_blocking = player_shield.blocking == 0 local not_blocking = player_shield.blocking == 0
local pos = player:get_pos() if pointed_thing and pointed_thing.type == "node" then
local pointed_node = minetest.get_node(pointed_thing.under)
if minetest.get_item_group(pointed_node.name, "container") > 1
or is_rmb_conflicting_node(pointed_node.name)
or wielded_stack:get_definition().type == "node" then
return
end
end
if shield_in_hand then if shield_in_hand then
if not_blocking then if not_blocking then
minetest.after(0.25, function() minetest.after(0.05, function()
if (not_blocking or not shield_in_offhand) and shield_in_hand and rmb then if (not_blocking or not shield_in_offhand) and shield_in_hand and rmb then
player_shield.blocking = 2 player_shield.blocking = 2
set_shield(player, true, 2) set_shield(player, true, 2)
@ -276,22 +310,15 @@ local function handle_blocking(player)
player_shield.blocking = 2 player_shield.blocking = 2
end end
elseif shield_in_offhand then elseif shield_in_offhand then
local pointed_thing = mcl_util.get_pointed_thing(player, true) local offhand_can_block = minetest.get_item_group(wielded_item(player), "cannot_block") ~= 1
local offhand_can_block = (wielded_item(player) == "" or not pointed_thing)
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 minetest.get_item_group(minetest.get_node(pointed_thing.under).name, "container") > 1 then
return
end
end
if not offhand_can_block then if not offhand_can_block then
return return
end end
if not_blocking then if not_blocking then
minetest.after(0.25, function() minetest.after(0.05, function()
if (not_blocking or not shield_in_hand) and shield_in_offhand and rmb and offhand_can_block then if (not_blocking or not shield_in_hand) and shield_in_offhand
and rmb and offhand_can_block then
player_shield.blocking = 1 player_shield.blocking = 1
set_shield(player, true, 1) set_shield(player, true, 1)
end end
@ -344,7 +371,7 @@ local function add_shield_hud(shieldstack, player, blocking)
z_index = -200, z_index = -200,
}) })
playerphysics.add_physics_factor(player, "speed", "shield_speed", 0.5) playerphysics.add_physics_factor(player, "speed", "shield_speed", 0.5)
set_interact(player, nil) set_interact(player, false)
end end
local function update_shield_hud(player, blocking, shieldstack) local function update_shield_hud(player, blocking, shieldstack)

View file

@ -30,17 +30,5 @@ for _, action in pairs({"grant", "revoke"}) do
if priv == "fly" then if priv == "fly" then
meta:set_int("mcl_privs:fly_changed", 1) meta:set_int("mcl_privs:fly_changed", 1)
end end
--[[
so e.g. hackers who have been revoked of the interact privilege
will not automatically get the interact privilege through the mcl shields code back
]]
if priv == "interact" then
if action == "revoke" then
meta:set_int("mcl_privs:interact_revoked", 1)
else
meta:set_int("mcl_privs:interact_revoked", 0)
end
end
end) end)
end end