Skip to main content

BlockPlaceContext

Struct BlockPlaceContext 

Source
pub struct BlockPlaceContext<'a> {
    hit_pos: BlockPos,
    clicked_face: Direction,
    click_location: DVec3,
    inside: bool,
    place_pos: BlockPos,
    replaces_clicked_block: bool,
    pub world: &'a Arc<World>,
    source: PlacementSource<'a>,
    mode: PlacementMode,
}
Expand description

Context for placing a block.

Vanilla porting map:

When translating vanilla block placement code, do not map BlockPlaceContext.getClickedPos() to Self::hit_pos.

Fields§

§hit_pos: BlockPos

Raw block position from the hit result.

Vanilla equivalent: UseOnContext.getClickedPos().

§clicked_face: Direction

The face of the block that was clicked.

§click_location: DVec3

The exact location where the click occurred.

§inside: bool

Whether the click was inside the block.

§place_pos: BlockPos

Position where the block will be placed.

Vanilla equivalent: BlockPlaceContext.getClickedPos(). Vanilla returns the raw hit position only when replacing the clicked block; otherwise it returns the adjacent block position in the clicked-face direction.

§replaces_clicked_block: bool

Whether placement replaces the hit block itself.

Vanilla equivalent: BlockPlaceContext.replacingClickedOnBlock().

§world: &'a Arc<World>

The world where the block is being placed.

§source: PlacementSource<'a>§mode: PlacementMode

Implementations§

Source§

impl<'a> BlockPlaceContext<'a>

Source

pub fn new( world: &'a Arc<World>, source: PlacementSource<'a>, hit_result: &BlockHitResult, ) -> Self

Creates a placement context from a source and effective hit result.

Source

fn with_mode( world: &'a Arc<World>, source: PlacementSource<'a>, hit_result: &BlockHitResult, mode: PlacementMode, ) -> Self

Source

pub fn directional( world: &'a Arc<World>, pos: BlockPos, direction: Direction, stack: &'a mut ItemStack, clicked_face: Direction, ) -> Self

Creates vanilla’s playerless DirectionalPlaceContext equivalent.

Source

fn resolve_placement_geometry(&mut self)

Source

pub fn can_place(&self) -> bool

Returns whether the effective placement position can be replaced.

Source

pub fn at(self, pos: BlockPos, direction: Direction) -> Self

Creates the shifted context used by vanilla BlockPlaceContext.at.

Source

pub const fn hit_pos(&self) -> BlockPos

Returns the raw block position from the hit result.

Source

pub const fn clicked_face(&self) -> Direction

Returns the face from the effective hit result.

Source

pub const fn click_location(&self) -> DVec3

Returns the exact effective hit location.

Source

pub const fn is_inside(&self) -> bool

Returns whether the effective hit location is inside the hit block.

Source

pub const fn place_pos(&self) -> BlockPos

Returns the effective block placement position.

Source

pub fn replaces_clicked_block(&self) -> bool

Returns whether placement replaces the originally hit block.

Source

pub const fn player(&self) -> Option<&Player>

Returns the player associated with this placement, if any.

Source

pub const fn hand(&self) -> InteractionHand

Returns the interaction hand associated with this placement.

Source

pub fn with_item<R>(&self, f: impl FnOnce(&ItemStack) -> R) -> R

Runs f with read access to the current placement stack.

Source

pub fn with_item_mut<R>(&mut self, f: impl FnOnce(&mut ItemStack) -> R) -> R

Runs f with mutable access to the current placement stack.

Source

pub const fn source(&self) -> &PlacementSource<'a>

Returns the placement source used by block placement callbacks.

Source

pub fn horizontal_direction(&self) -> Direction

Returns the horizontal placement direction.

Source

pub const fn rotation(&self) -> f32

Returns the placement rotation.

Source

pub const fn is_secondary_use_active(&self) -> bool

Returns whether secondary use is active for this placement.

Source

pub fn get_nearest_looking_direction(&self) -> Direction

Returns the direction the player is looking at most directly.

This considers both yaw and pitch to determine the nearest direction among all 6 directions (UP, DOWN, NORTH, SOUTH, EAST, WEST).

Based on Java’s Direction.orderedByNearest(Entity)[0]. Unlike Self::get_nearest_looking_directions, this does not reorder around the clicked face when placing beside a non-replaceable block.

Source

pub const fn get_nearest_looking_vertical_direction(&self) -> Direction

Returns the vertical direction the player is looking toward.

Based on Java’s BlockPlaceContext.getNearestLookingVerticalDirection().

Source

pub fn get_nearest_looking_directions(&self) -> [Direction; 6]

Returns all 6 directions ordered by how closely the player is looking at them.

Based on Java’s BlockPlaceContext.getNearestLookingDirections(). When not replacing the clicked block, the opposite of the clicked face is moved to the front of the array.

Source

pub fn is_water_source(&self) -> bool

Returns true if the block at the placement position is a water source.

Source

pub fn is_full_water(&self) -> bool

Returns true if the block at the placement position contains full water.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for BlockPlaceContext<'a>

§

impl<'a> !UnwindSafe for BlockPlaceContext<'a>

§

impl<'a> Freeze for BlockPlaceContext<'a>

§

impl<'a> Send for BlockPlaceContext<'a>

§

impl<'a> Sync for BlockPlaceContext<'a>

§

impl<'a> Unpin for BlockPlaceContext<'a>

§

impl<'a> UnsafeUnpin for BlockPlaceContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> IntoShared for T

Source§

fn into_shared(self) -> Arc<Mutex<RawMutex, Self>>

Wraps this value in an Arc<SyncMutex<>>
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more