pub struct InventoryAccess {
inventory: Shared<PlayerInventory>,
hand: InteractionHand,
}Expand description
Access to the player’s inventory.
This handle does not hold the inventory lock by itself. Use the closure methods to keep lock scopes short and avoid carrying an inventory guard through block behavior, world mutation, or menu opening.
Fields§
§inventory: Shared<PlayerInventory>§hand: InteractionHandImplementations§
Source§impl InventoryAccess
impl InventoryAccess
Sourcepub const fn new(
inventory: Shared<PlayerInventory>,
hand: InteractionHand,
) -> Self
pub const fn new( inventory: Shared<PlayerInventory>, hand: InteractionHand, ) -> Self
Creates a new InventoryAccess instance.
Sourcepub fn with_item<R>(&self, f: impl FnOnce(&mut ItemStack) -> R) -> R
pub fn with_item<R>(&self, f: impl FnOnce(&mut ItemStack) -> R) -> R
Runs f with mutable access to the item in the player’s hand.
Sourcepub fn with_inventory<R>(&self, f: impl FnOnce(&mut PlayerInventory) -> R) -> R
pub fn with_inventory<R>(&self, f: impl FnOnce(&mut PlayerInventory) -> R) -> R
Runs f with mutable access to the player’s inventory.
Sourcepub fn with_guard<R>(&self, f: impl FnOnce(&mut ContainerLockGuard) -> R) -> R
pub fn with_guard<R>(&self, f: impl FnOnce(&mut ContainerLockGuard) -> R) -> R
Runs f with a container guard containing the player’s inventory.
Prefer Self::with_item or Self::with_inventory unless an operation
must interoperate with APIs that require ContainerLockGuard.
Trait Implementations§
Source§impl Clone for InventoryAccess
impl Clone for InventoryAccess
Source§fn clone(&self) -> InventoryAccess
fn clone(&self) -> InventoryAccess
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for InventoryAccess
impl !UnwindSafe for InventoryAccess
impl Freeze for InventoryAccess
impl Send for InventoryAccess
impl Sync for InventoryAccess
impl Unpin for InventoryAccess
impl UnsafeUnpin for InventoryAccess
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreWraps this value in an
Arc<SyncMutex<>>