From 661e19698734a90a5d2feb01a0727e92f1f3c980 Mon Sep 17 00:00:00 2001 From: Snowiiii Date: Sat, 3 Aug 2024 12:55:39 +0200 Subject: [PATCH] Add Clientbound Synchronize Player Position --- pumpkin-protocol/src/client/play/mod.rs | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pumpkin-protocol/src/client/play/mod.rs b/pumpkin-protocol/src/client/play/mod.rs index b3d04d7a7..adf6bb2e8 100644 --- a/pumpkin-protocol/src/client/play/mod.rs +++ b/pumpkin-protocol/src/client/play/mod.rs @@ -187,3 +187,49 @@ impl ClientPacket for CGameEvent { bytebuf.put_f32(self.value); } } + +pub struct CSyncPlayerPostion { + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: VarInt, +} + +impl CSyncPlayerPostion { + pub fn new( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: VarInt, + ) -> Self { + Self { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + } + } +} + +impl ClientPacket for CSyncPlayerPostion { + const PACKET_ID: VarInt = 0x40; + + fn write(&self, bytebuf: &mut ByteBuffer) { + bytebuf.put_f64(self.x); + bytebuf.put_f64(self.y); + bytebuf.put_f64(self.z); + bytebuf.put_f32(self.yaw.to_degrees()); + bytebuf.put_f32(self.pitch.to_degrees()); + bytebuf.put_i8(self.flags); + bytebuf.put_var_int(self.teleport_id); + } +}