aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-27 15:09:33 +0000
committermat <github@matdoes.dev>2022-04-27 15:09:33 +0000
commit60d1fa50c32c202dd04895caa51172948a4760b6 (patch)
tree2af30c7de1d37bc3150a637e8b3150d40d95feea /azalea-protocol/src/packets/game/clientbound_player_position_packet.rs
parent4f9f2468f0fc80b19baac6904c05c9cc9a9cb61a (diff)
downloadazalea-drasl-60d1fa50c32c202dd04895caa51172948a4760b6.tar.xz
add player position packet
Diffstat (limited to 'azalea-protocol/src/packets/game/clientbound_player_position_packet.rs')
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_position_packet.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs
new file mode 100644
index 00000000..5bb40d84
--- /dev/null
+++ b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs
@@ -0,0 +1,69 @@
+// i don't know the actual name of this packet, i couldn't find it in the source code
+
+use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
+use async_trait::async_trait;
+use packet_macros::GamePacket;
+use tokio::io::AsyncRead;
+
+#[derive(Clone, Debug, 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.
+ #[varint]
+ pub id: i32,
+ 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,
+}
+
+#[async_trait]
+impl McBufReadable for RelativeArguments {
+ async fn read_into<R>(buf: &mut R) -> Result<Self, String>
+ where
+ R: AsyncRead + std::marker::Unpin + std::marker::Send,
+ {
+ let byte = buf.read_byte().await?;
+ 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 Vec<u8>) -> Result<(), std::io::Error> {
+ let mut byte = 0;
+ if self.x {
+ byte = byte | 0b1;
+ }
+ if self.y {
+ byte = byte | 0b10;
+ }
+ if self.z {
+ byte = byte | 0b100;
+ }
+ if self.y_rot {
+ byte = byte | 0b1000;
+ }
+ if self.x_rot {
+ byte = byte | 0b10000;
+ }
+ u8::write_into(&byte, buf)
+ }
+}