aboutsummaryrefslogtreecommitdiff
path: root/azalea-inventory
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-inventory')
-rw-r--r--azalea-inventory/src/lib.rs19
1 files changed, 19 insertions, 0 deletions
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<const N: usize> Default for SlotList<N> {
SlotList([(); N].map(|_| ItemStack::Empty))
}
}
+impl<const N: usize> SlotList<N> {
+ 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