pub struct BlockPos {
pub x: i32,
pub y: i32,
pub z: i32,
}
Expand description
The coordinates of a block in the world. For entities (if the coordinate
have decimals), use Vec3
instead.
Fields§
§x: i32
§y: i32
§z: i32
Implementations§
Source§impl BlockPos
impl BlockPos
pub const fn new(x: i32, y: i32, z: i32) -> BlockPos
Sourcepub fn length_squared(&self) -> i32
pub fn length_squared(&self) -> i32
Get the distance of this vector to the origin by doing x^2 + y^2 + z^2
.
Sourcepub fn distance_squared_to(&self, other: &BlockPos) -> i32
pub fn distance_squared_to(&self, other: &BlockPos) -> i32
Get the squared distance from this position to another position.
Equivalent to (self - other).length_squared()
.
pub fn horizontal_distance_squared(&self) -> i32
pub fn horizontal_distance_squared_to(&self, other: &BlockPos) -> i32
Sourcepub fn down(&self, y: i32) -> BlockPos
pub fn down(&self, y: i32) -> BlockPos
Return a new instance of this position with the y coordinate decreased by the given number.
Sourcepub fn up(&self, y: i32) -> BlockPos
pub fn up(&self, y: i32) -> BlockPos
Return a new instance of this position with the y coordinate increased by the given number.
Sourcepub fn north(&self, z: i32) -> BlockPos
pub fn north(&self, z: i32) -> BlockPos
Return a new instance of this position with the z coordinate subtracted by the given number.
Sourcepub fn east(&self, x: i32) -> BlockPos
pub fn east(&self, x: i32) -> BlockPos
Return a new instance of this position with the x coordinate increased by the given number.
Sourcepub fn south(&self, z: i32) -> BlockPos
pub fn south(&self, z: i32) -> BlockPos
Return a new instance of this position with the z coordinate increased by the given number.
Sourcepub fn west(&self, x: i32) -> BlockPos
pub fn west(&self, x: i32) -> BlockPos
Return a new instance of this position with the x coordinate subtracted by the given number.
pub fn dot(&self, other: BlockPos) -> i32
Source§impl BlockPos
impl BlockPos
Sourcepub fn center(&self) -> Vec3
pub fn center(&self) -> Vec3
Get the absolute center of a block position by adding 0.5 to each coordinate.
Sourcepub fn to_vec3_floored(&self) -> Vec3
pub fn to_vec3_floored(&self) -> Vec3
Convert the block position into a Vec3 without centering it.
Sourcepub fn length_manhattan(&self) -> u32
pub fn length_manhattan(&self) -> u32
Get the distance of this vector from the origin by doing x + y + z
.
Sourcepub fn min(&self, other: &BlockPos) -> BlockPos
pub fn min(&self, other: &BlockPos) -> BlockPos
Make a new BlockPos with the lower coordinates for each axis.
assert_eq!(
BlockPos::min(
&BlockPos::new(1, 20, 300),
&BlockPos::new(50, 40, 30),
),
BlockPos::new(1, 20, 30),
);
Sourcepub fn max(&self, other: &BlockPos) -> BlockPos
pub fn max(&self, other: &BlockPos) -> BlockPos
Make a new BlockPos with the higher coordinates for each axis.
assert_eq!(
BlockPos::max(
&BlockPos::new(1, 20, 300),
&BlockPos::new(50, 40, 30),
),
BlockPos::new(50, 40, 300),
);
pub fn offset_with_direction(self, direction: Direction) -> BlockPos
Trait Implementations§
Source§impl AddAssign for BlockPos
impl AddAssign for BlockPos
Source§fn add_assign(&mut self, rhs: BlockPos)
fn add_assign(&mut self, rhs: BlockPos)
+=
operation. Read moreSource§impl AzaleaRead for BlockPos
impl AzaleaRead for BlockPos
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<BlockPos, BufReadError>
Source§impl AzaleaWrite for BlockPos
impl AzaleaWrite for BlockPos
Source§impl<'de> Deserialize<'de> for BlockPos
impl<'de> Deserialize<'de> for BlockPos
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<BlockPos, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<BlockPos, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl DivAssign<i32> for BlockPos
impl DivAssign<i32> for BlockPos
Source§fn div_assign(&mut self, divisor: i32)
fn div_assign(&mut self, divisor: i32)
/=
operation. Read moreSource§impl From<&LastSentPosition> for BlockPos
impl From<&LastSentPosition> for BlockPos
Source§fn from(value: &LastSentPosition) -> BlockPos
fn from(value: &LastSentPosition) -> BlockPos
Source§impl From<LastSentPosition> for BlockPos
impl From<LastSentPosition> for BlockPos
Source§fn from(value: LastSentPosition) -> BlockPos
fn from(value: LastSentPosition) -> BlockPos
Source§impl FromStr for BlockPos
Parses a string in the format “X Y Z” into a BlockPos.
impl FromStr for BlockPos
Parses a string in the format “X Y Z” into a BlockPos.
The input string should contain three integer values separated by spaces,
representing the x, y, and z components of the vector respectively.
This can be used to parse user input or from BlockPos::to_string
.
Source§impl MulAssign<i32> for BlockPos
impl MulAssign<i32> for BlockPos
Source§fn mul_assign(&mut self, multiplier: i32)
fn mul_assign(&mut self, multiplier: i32)
*=
operation. Read moreSource§impl Serialize for BlockPos
impl Serialize for BlockPos
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for BlockPos
impl Eq for BlockPos
impl StructuralPartialEq for BlockPos
Auto Trait Implementations§
impl Freeze for BlockPos
impl RefUnwindSafe for BlockPos
impl Send for BlockPos
impl Sync for BlockPos
impl Unpin for BlockPos
impl UnwindSafe for BlockPos
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DynEq for T
impl<T> DynEq for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self
using default()
.