From bbfca34133fdb97a732a60a0a11ca4ba3276a63a Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 3 Jun 2025 17:10:34 -1300 Subject: copy player part of container_menu to inventory_menu on close --- azalea-inventory/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'azalea-inventory/src') diff --git a/azalea-inventory/src/lib.rs b/azalea-inventory/src/lib.rs index 91d9f48d..0f74ba3a 100644 --- a/azalea-inventory/src/lib.rs +++ b/azalea-inventory/src/lib.rs @@ -32,6 +32,11 @@ impl Default for SlotList { SlotList([(); N].map(|_| ItemStack::Empty)) } } +impl SlotList { + pub fn new(items: [ItemStack; N]) -> Self { + SlotList(items) + } +} impl Menu { /// Get the [`Player`] from this [`Menu`]. @@ -46,6 +51,20 @@ impl Menu { unreachable!("Called `Menu::as_player` on a menu that wasn't `Player`.") } } + + /// Same as [`Menu::as_player`], but returns a mutable reference to the + /// [`Player`]. + /// + /// # Panics + /// + /// Will panic if the menu isn't `Menu::Player`. + pub fn as_player_mut(&mut self) -> &mut Player { + if let Menu::Player(player) = self { + player + } else { + unreachable!("Called `Menu::as_player_mut` on a menu that wasn't `Player`.") + } + } } // the player inventory part is always the last 36 slots (except in the Player -- cgit v1.2.3