From cffc8e0145e0323fbdc82ece64aa2aa052fe6d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Mon, 26 Feb 2024 19:50:03 +0100 Subject: [PATCH 1/8] Fix loosing interact bug in mcl_shields --- mods/ITEMS/mcl_shields/init.lua | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index 6edee7e89..2d40db2f0 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -211,16 +211,36 @@ local function set_interact(player, interact) return end local meta = player:get_meta() - if meta:get_int("mcl_privs:interact_revoked") ~= 1 then - privs.interact = interact - minetest.set_player_privs(player_name, privs) - meta:set_int("mcl_privs:interact_revoked",0) + + if interact and meta:get_int("mcl_shields:interact_revoked") ~= 0 then + meta:set_int("mcl_shields: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 + + minetest.set_player_privs(player_name, privs) 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 function remove_shield_hud(player) + set_interact(player, true) + 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]) shield_hud[player] = nil @@ -233,7 +253,6 @@ local function remove_shield_hud(player) end playerphysics.remove_physics_factor(player, "speed", "shield_speed") - set_interact(player, true) end local function add_shield_entity(player, i) @@ -344,7 +363,7 @@ local function add_shield_hud(shieldstack, player, blocking) z_index = -200, }) playerphysics.add_physics_factor(player, "speed", "shield_speed", 0.5) - set_interact(player, nil) + set_interact(player, false) end local function update_shield_hud(player, blocking, shieldstack) From d0d1217dec16938806c6cfbff561ac34e22cfccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Mon, 26 Feb 2024 20:05:53 +0100 Subject: [PATCH 2/8] Remove unused code in mcl_privs --- mods/MISC/mcl_privs/init.lua | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/mods/MISC/mcl_privs/init.lua b/mods/MISC/mcl_privs/init.lua index ddca9f946..09239390a 100644 --- a/mods/MISC/mcl_privs/init.lua +++ b/mods/MISC/mcl_privs/init.lua @@ -30,17 +30,5 @@ for _, action in pairs({"grant", "revoke"}) do if priv == "fly" then meta:set_int("mcl_privs:fly_changed", 1) 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 \ No newline at end of file +end From 45ae17044726cf1541c3168c8690301beccfd6f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Mon, 26 Feb 2024 20:09:41 +0100 Subject: [PATCH 3/8] Deduplicate shield slowdown removal code --- mods/ITEMS/mcl_shields/init.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index 2d40db2f0..9a1458b85 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -240,6 +240,7 @@ local shield_hud = {} 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 player:hud_remove(shield_hud[player]) @@ -251,8 +252,6 @@ local function remove_shield_hud(player) if not hf.wielditem then player:hud_set_flags({wielditem = true}) end - - playerphysics.remove_physics_factor(player, "speed", "shield_speed") end local function add_shield_entity(player, i) From 04e29c5796910fd0dd3035c43fcec7b3af956716 Mon Sep 17 00:00:00 2001 From: Loveaabb Date: Wed, 22 May 2024 10:20:26 +0000 Subject: [PATCH 4/8] Several improvements to the Shield --- mods/ITEMS/mcl_shields/init.lua | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index 9a1458b85..0bc0a18ba 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -269,6 +269,15 @@ local function remove_shield_entity(player, i) end end +local function is_node_stack(itemstack) + return itemstack:get_definition().drawtype -- only node's definition table contains element "drawtype" +end + +local function is_rmb_conflicting_node(nodename) + nodedef = minetest.registered_nodes[nodename] + return nodedef.on_rightclick +end + local function handle_blocking(player) local player_shield = mcl_shields.players[player] local rmb = player:get_player_control().RMB @@ -284,7 +293,7 @@ local function handle_blocking(player) local pos = player:get_pos() if shield_in_hand 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 player_shield.blocking = 2 set_shield(player, true, 2) @@ -295,11 +304,16 @@ local function handle_blocking(player) end elseif shield_in_offhand then local pointed_thing = mcl_util.get_pointed_thing(player, true) - 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) + local wielded_stack = player:get_wielded_item() + local offhand_can_block = (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 + 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 is_node_stack(wielded_stack) + then return end end @@ -308,7 +322,7 @@ local function handle_blocking(player) return end 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 player_shield.blocking = 1 set_shield(player, true, 1) From f26c34e65f507230ac64baffa417abd4e8e142c1 Mon Sep 17 00:00:00 2001 From: Loveaabb Date: Tue, 21 May 2024 14:51:43 +0000 Subject: [PATCH 5/8] Bugfix: Shield fails to block arrows --- mods/ITEMS/mcl_bows/arrow.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 652819aa6..14d289c10 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -257,10 +257,10 @@ function ARROW_ENTITY.on_step(self, dtime) mcl_burning.set_on_fire(obj, 5) end if not self._in_player and not self._blocked then - obj:punch(self.object, 1.0, { - full_punch_interval=1.0, - damage_groups={fleshy=self._damage}, - }, self.object:get_velocity()) + mcl_util.deal_damage(obj, self._damage, {type = "arrow", source = self._shooter, direct = self.object}) + if self._extra_hit_func then + self._extra_hit_func(obj) + end if obj:is_player() then if not mcl_shields.is_blocking(obj) then local placement From d5bc0613d8aba3b0febcbcaf088bdab50d9f70a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski?= Date: Fri, 9 Aug 2024 16:12:15 +0700 Subject: [PATCH 6/8] Make node itemstack check in mcl_shields less hacky --- mods/ITEMS/mcl_shields/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index 0bc0a18ba..62904aa1d 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -270,7 +270,7 @@ local function remove_shield_entity(player, i) end local function is_node_stack(itemstack) - return itemstack:get_definition().drawtype -- only node's definition table contains element "drawtype" + return (itemstack:get_definition().type == "node") end local function is_rmb_conflicting_node(nodename) From 084741b733157af951bae9962ba65cffc9f6b19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski?= Date: Fri, 16 Aug 2024 10:54:21 +0700 Subject: [PATCH 7/8] Fix using shield on unknown nodes and cleanup --- mods/ITEMS/mcl_shields/init.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index 62904aa1d..b3323bd3f 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -269,12 +269,8 @@ local function remove_shield_entity(player, i) end end -local function is_node_stack(itemstack) - return (itemstack:get_definition().type == "node") -end - local function is_rmb_conflicting_node(nodename) - nodedef = minetest.registered_nodes[nodename] + nodedef = minetest.registered_nodes[nodename] or {} return nodedef.on_rightclick end @@ -312,7 +308,7 @@ local function handle_blocking(player) 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 is_node_stack(wielded_stack) + or wielded_stack:get_definition().type == "node" then return end From f86a641dfa82039d206293a76a16fa15dd39815e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski?= Date: Tue, 17 Sep 2024 12:22:05 +0700 Subject: [PATCH 8/8] Improve shield block code and unhardcode offhand group --- mods/ITEMS/mcl_bows/bow.lua | 4 ++-- mods/ITEMS/mcl_bows/crossbow.lua | 6 +++--- mods/ITEMS/mcl_shields/init.lua | 33 ++++++++++++++++---------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 9f381f501..34784ab07 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -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") return itemstack 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, }) @@ -216,7 +216,7 @@ for level=0, 2 do wield_scale = mcl_vars.tool_wield_scale, stack_max = 1, 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 on_use = function() return end, on_drop = function(itemstack, dropper, pos) diff --git a/mods/ITEMS/mcl_bows/crossbow.lua b/mods/ITEMS/mcl_bows/crossbow.lua index c1cb7f8be..b6dc31dd0 100644 --- a/mods/ITEMS/mcl_bows/crossbow.lua +++ b/mods/ITEMS/mcl_bows/crossbow.lua @@ -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") return itemstack 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, }) @@ -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") return itemstack 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, }) @@ -238,7 +238,7 @@ for level=0, 2 do wield_scale = mcl_vars.tool_wield_scale, stack_max = 1, 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 on_use = function() return end, on_drop = function(itemstack, dropper, pos) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index b3323bd3f..e1b790049 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -270,7 +270,7 @@ local function remove_shield_entity(player, i) end local function is_rmb_conflicting_node(nodename) - nodedef = minetest.registered_nodes[nodename] or {} + local nodedef = minetest.registered_nodes[nodename] or {} return nodedef.on_rightclick end @@ -282,11 +282,22 @@ local function handle_blocking(player) return 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_hand = mcl_shields.wielding_shield(player) 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 not_blocking then minetest.after(0.05, function() @@ -299,27 +310,15 @@ local function handle_blocking(player) player_shield.blocking = 2 end elseif shield_in_offhand then - local pointed_thing = mcl_util.get_pointed_thing(player, true) - local wielded_stack = player:get_wielded_item() - local offhand_can_block = (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 - 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 + local offhand_can_block = minetest.get_item_group(wielded_item(player), "cannot_block") ~= 1 if not offhand_can_block then return end if not_blocking then 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 set_shield(player, true, 1) end