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:
UseOnContext.getClickedPos()isSelf::hit_pos.BlockPlaceContext.getClickedPos()isSelf::place_pos.BlockPlaceContext.replacingClickedOnBlock()isSelf::replaces_clicked_block.
When translating vanilla block placement code, do not map
BlockPlaceContext.getClickedPos() to Self::hit_pos.
Fields§
§hit_pos: BlockPosRaw block position from the hit result.
Vanilla equivalent: UseOnContext.getClickedPos().
clicked_face: DirectionThe face of the block that was clicked.
click_location: DVec3The exact location where the click occurred.
inside: boolWhether the click was inside the block.
place_pos: BlockPosPosition 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: boolWhether 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: PlacementModeImplementations§
Source§impl<'a> BlockPlaceContext<'a>
impl<'a> BlockPlaceContext<'a>
Sourcepub fn new(
world: &'a Arc<World>,
source: PlacementSource<'a>,
hit_result: &BlockHitResult,
) -> Self
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.
fn with_mode( world: &'a Arc<World>, source: PlacementSource<'a>, hit_result: &BlockHitResult, mode: PlacementMode, ) -> Self
Sourcepub fn directional(
world: &'a Arc<World>,
pos: BlockPos,
direction: Direction,
stack: &'a mut ItemStack,
clicked_face: Direction,
) -> Self
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.
fn resolve_placement_geometry(&mut self)
Sourcepub fn can_place(&self) -> bool
pub fn can_place(&self) -> bool
Returns whether the effective placement position can be replaced.
Sourcepub fn at(self, pos: BlockPos, direction: Direction) -> Self
pub fn at(self, pos: BlockPos, direction: Direction) -> Self
Creates the shifted context used by vanilla BlockPlaceContext.at.
Sourcepub const fn clicked_face(&self) -> Direction
pub const fn clicked_face(&self) -> Direction
Returns the face from the effective hit result.
Sourcepub const fn click_location(&self) -> DVec3
pub const fn click_location(&self) -> DVec3
Returns the exact effective hit location.
Sourcepub const fn is_inside(&self) -> bool
pub const fn is_inside(&self) -> bool
Returns whether the effective hit location is inside the hit block.
Sourcepub fn replaces_clicked_block(&self) -> bool
pub fn replaces_clicked_block(&self) -> bool
Returns whether placement replaces the originally hit block.
Sourcepub const fn player(&self) -> Option<&Player>
pub const fn player(&self) -> Option<&Player>
Returns the player associated with this placement, if any.
Sourcepub const fn hand(&self) -> InteractionHand
pub const fn hand(&self) -> InteractionHand
Returns the interaction hand associated with this placement.
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 the current placement 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 the current placement stack.
Sourcepub const fn source(&self) -> &PlacementSource<'a>
pub const fn source(&self) -> &PlacementSource<'a>
Returns the placement source used by block placement callbacks.
Sourcepub fn horizontal_direction(&self) -> Direction
pub fn horizontal_direction(&self) -> Direction
Returns the horizontal placement direction.
Sourcepub const fn is_secondary_use_active(&self) -> bool
pub const fn is_secondary_use_active(&self) -> bool
Returns whether secondary use is active for this placement.
Sourcepub fn get_nearest_looking_direction(&self) -> Direction
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.
Sourcepub const fn get_nearest_looking_vertical_direction(&self) -> Direction
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().
Sourcepub fn get_nearest_looking_directions(&self) -> [Direction; 6]
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.
Sourcepub fn is_water_source(&self) -> bool
pub fn is_water_source(&self) -> bool
Returns true if the block at the placement position is a water source.
Sourcepub fn is_full_water(&self) -> bool
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> 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
§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> ⓘ
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> ⓘ
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 moreArc<SyncMutex<>>