aboutsummaryrefslogtreecommitdiff
path: root/azalea-inventory/src/lib.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-03 17:10:34 -1300
committermat <git@matdoes.dev>2025-06-03 17:10:34 -1300
commitbbfca34133fdb97a732a60a0a11ca4ba3276a63a (patch)
tree28598b793c36c04a7cab512b3d488aa5eaacb3cc /azalea-inventory/src/lib.rs
parentf5f50b85e5d427aab6a0ef00570b4076b61babe8 (diff)
downloadazalea-drasl-bbfca34133fdb97a732a60a0a11ca4ba3276a63a.tar.xz
copy player part of container_menu to inventory_menu on close
Diffstat (limited to 'azalea-inventory/src/lib.rs')
-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