pub struct Position {
pub x: i32,
pub y: i16,
pub z: i32,
}Expand description
A Minecraft protocol block position packed into a 64-bit value.
The wire format stores x in the 26 most-significant bits, z in the
middle 26 bits, and y in the 12 least-significant bits. Each component is
a signed two’s-complement integer:
x: 26 bits | z: 26 bits | y: 12 bitsThe value is packed as:
((x & 0x3FFFFFF) << 38) | ((z & 0x3FFFFFF) << 12) | (y & 0xFFF)§Examples
use mcproto_types::{TypeCodec, basic::Position};
let position = Position {
x: 18_357_644,
y: 831,
z: -20_882_616,
};
let mut encoded = Vec::new();
position.encode(&mut encoded)?;
assert_eq!(
encoded,
[0x46, 0x07, 0x63, 0x2c, 0x15, 0xb4, 0x83, 0x3f]
);
let mut input = encoded.as_slice();
assert_eq!(Position::decode(&mut input)?, position);
assert!(input.is_empty());Fields§
§x: i32The x coordinate, from -33,554,432 through 33,554,431.
y: i16The y coordinate, from -2,048 through 2,047.
z: i32The z coordinate, from -33,554,432 through 33,554,431.
Trait Implementations§
impl Copy for Position
impl Eq for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnsafeUnpin for Position
impl UnwindSafe for Position
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,
Source§impl<T> ContextualCodec for Twhere
T: TypeCodec,
impl<T> ContextualCodec for Twhere
T: TypeCodec,
Source§fn encode_with_context(
&self,
writer: &mut impl Write,
_context: &Context,
) -> Result<(), CodecError>
fn encode_with_context( &self, writer: &mut impl Write, _context: &Context, ) -> Result<(), CodecError>
Encodes this value using context supplied by its enclosing structure.
Source§fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
Decodes this value using context supplied by its enclosing structure.