Bugfix: spectate hand wasn't overwritten if there was already another hand put by another mod

This commit is contained in:
marco_a 2024-04-24 22:59:23 +02:00
parent 287687df6f
commit 401e18760a

View File

@ -4,7 +4,7 @@ local function override_hotbar() end
local function set_spectator() end
local players_in_spectate_mode = {} -- KEY: player name, VALUE: {(string) minigame, (int) arenaID, (string) type, (string) spectating}
local spectate_temp_storage = {} -- KEY: player_name, VALUE: {(table) camera_offset, (string) inventory_fs}
local spectate_temp_storage = {} -- KEY: player_name, VALUE: {(table) camera_offset, (string) inventory_fs, (ItemStack) hand}
local players_spectated = {} -- KEY: player name, VALUE: {(string) spectator(s) = true}
local entities_spectated = {} -- KEY: [mod][arena_name][entity name], VALUE: {(string) spectator(s) = true}
local areas_spectated = {} -- KEY: [mod][arena_name][area_name], VALUE: {(string) spectator(s) = true}
@ -95,16 +95,17 @@ function arena_lib.enter_spectate_mode(p_name, arena, xc_name)
end
end
-- applico mano finta
player:get_inventory():set_size("hand", 1)
player:get_inventory():add_item("hand", "arena_lib:spectate_hand")
-- che siano entrati anche come giocatori o meno, non importa, in quanto operations_before_entering_arena
-- viene eseguita prima dell'entrata nella spettatore, e quindi questi parametri
-- sono già stati eventualmente salvati nell'archiviazione di arena_lib
spectate_temp_storage[p_name] = {}
spectate_temp_storage[p_name].camera_offset = {player:get_eye_offset()}
spectate_temp_storage[p_name].inventory_fs = player:get_inventory_formspec()
spectate_temp_storage[p_name].hand = player:get_inventory():get_stack("hand", 1)
-- applico mano finta
player:get_inventory():set_size("hand", 1)
player:get_inventory():set_stack("hand", 1, "arena_lib:spectate_hand")
-- applicazione parametri vari
local current_properties = table.copy(player:get_properties())
@ -172,6 +173,7 @@ function arena_lib.leave_spectate_mode(p_name)
-- verranno eventualmente poi sovrascritti da quelli nell'archiviazione di arena_lib
player:set_eye_offset(spectate_temp_storage[p_name].camera_offset[1], spectate_temp_storage[p_name].camera_offset[2])
player:set_inventory_formspec(spectate_temp_storage[p_name].inventory_fs)
player:get_inventory():set_stack("hand", 1, spectate_temp_storage[p_name].hand)
spectate_temp_storage[p_name] = nil
player:set_detach()