1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 23:44:38 +00:00
azalea/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs
2022-06-24 23:54:31 -05:00

63 lines
1.5 KiB
Rust

use azalea_buf::McBuf;
use azalea_buf::{McBufReadable, McBufWritable, Readable};
use packet_macros::GamePacket;
use std::io::{Read, Write};
#[derive(Clone, Debug, McBuf, GamePacket)]
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_into(buf: &mut impl Read) -> Result<Self, String> {
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)
}
}