1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
use azalea_buf::{BufReadError, McBuf};
use azalea_buf::{McBufReadable, McBufWritable, Readable};
use packet_macros::ClientboundGamePacket;
use std::io::{Read, Write};
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
pub struct ClientboundPlayerPositionPacket {
pub x: f64,
pub y: f64,
pub z: f64,
pub y_rot: f32,
pub x_rot: f32,
pub relative_arguments: RelativeArguments,
/// Client should confirm this packet with Teleport Confirm containing the
/// same Teleport ID.
#[var]
pub id: u32,
pub dismount_vehicle: bool,
}
#[derive(Debug, Clone)]
pub struct RelativeArguments {
pub x: bool,
pub y: bool,
pub z: bool,
pub y_rot: bool,
pub x_rot: bool,
}
impl McBufReadable for RelativeArguments {
fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> {
let byte = buf.read_byte()?;
Ok(RelativeArguments {
x: byte & 0b1 != 0,
y: byte & 0b10 != 0,
z: byte & 0b100 != 0,
y_rot: byte & 0b1000 != 0,
x_rot: byte & 0b10000 != 0,
})
}
}
impl McBufWritable for RelativeArguments {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
let mut byte = 0;
if self.x {
byte |= 0b1;
}
if self.y {
byte |= 0b10;
}
if self.z {
byte |= 0b100;
}
if self.y_rot {
byte |= 0b1000;
}
if self.x_rot {
byte |= 0b10000;
}
u8::write_into(&byte, buf)
}
}
|