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] 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)