pub struct PlacementSource<'a> {
player: Option<&'a Player>,
hand: InteractionHand,
item: PlacementItemSource<'a>,
orientation: PlacementOrientation,
is_secondary_use_active: bool,
}Expand description
Player and item data retained across one block placement operation.
Player-backed access deliberately re-resolves the selected hand under short inventory locks. The stack may therefore change between accesses; retaining one inventory guard across behavior dispatch could deadlock callbacks which open a menu. Direct access retains the exact borrowed stack for the whole operation.
Fields§
§player: Option<&'a Player>§hand: InteractionHand§item: PlacementItemSource<'a>§orientation: PlacementOrientation§is_secondary_use_active: boolImplementations§
Source§impl<'a> PlacementSource<'a>
impl<'a> PlacementSource<'a>
Sourcepub fn player_hand(player: &'a Player, inv: &InventoryAccess) -> Self
pub fn player_hand(player: &'a Player, inv: &InventoryAccess) -> Self
Creates a placement source backed by a player’s live hand.
Sourcepub const fn direct(
player: Option<&'a Player>,
hand: InteractionHand,
stack: &'a mut ItemStack,
orientation: PlacementOrientation,
is_secondary_use_active: bool,
) -> Self
pub const fn direct( player: Option<&'a Player>, hand: InteractionHand, stack: &'a mut ItemStack, orientation: PlacementOrientation, is_secondary_use_active: bool, ) -> Self
Creates a source backed by a directly borrowed stack.
Sourcepub const fn player(&self) -> Option<&Player>
pub const fn player(&self) -> Option<&Player>
Returns the player associated with this source, if any.
Sourcepub const fn hand(&self) -> InteractionHand
pub const fn hand(&self) -> InteractionHand
Returns the interaction hand associated with this source.
Sourcepub fn with_item<R>(&self, f: impl FnOnce(&ItemStack) -> R) -> R
pub fn with_item<R>(&self, f: impl FnOnce(&ItemStack) -> R) -> R
Runs f with read access to this source’s current stack.
Sourcepub fn with_item_mut<R>(&mut self, f: impl FnOnce(&mut ItemStack) -> R) -> R
pub fn with_item_mut<R>(&mut self, f: impl FnOnce(&mut ItemStack) -> R) -> R
Runs f with mutable access to this source’s current stack.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for PlacementSource<'a>
impl<'a> !UnwindSafe for PlacementSource<'a>
impl<'a> Freeze for PlacementSource<'a>
impl<'a> Send for PlacementSource<'a>
impl<'a> Sync for PlacementSource<'a>
impl<'a> Unpin for PlacementSource<'a>
impl<'a> UnsafeUnpin for PlacementSource<'a>
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
§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<>>