Skip to content

Commit

Permalink
Implement ServerPacket for CPlayerPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Feb 23, 2025
1 parent f45991a commit 7c1d5ef
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion pumpkin-protocol/src/client/play/player_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use pumpkin_data::packet::clientbound::PLAY_PLAYER_POSITION;
use pumpkin_macros::packet;
use pumpkin_util::math::vector3::Vector3;

use crate::{ClientPacket, PositionFlag, VarInt, bytebuf::ByteBufMut};
use crate::{
ClientPacket, PositionFlag, ServerPacket, VarInt, bytebuf::ByteBuf, bytebuf::ByteBufMut,
};

#[packet(PLAY_PLAYER_POSITION)]
pub struct CPlayerPosition<'a> {
Expand Down Expand Up @@ -35,6 +37,28 @@ impl<'a> CPlayerPosition<'a> {
}
}

impl ServerPacket for CPlayerPosition<'_> {
fn read(bytebuf: &mut impl bytes::Buf) -> Result<Self, crate::bytebuf::ReadingError> {
fn get_vec(
bytebuf: &mut impl bytes::Buf,
) -> Result<Vector3<f64>, crate::bytebuf::ReadingError> {
Ok(Vector3::new(
bytebuf.try_get_f64()?,
bytebuf.try_get_f64()?,
bytebuf.try_get_f64()?,
))
}
Ok(Self {
teleport_id: bytebuf.try_get_var_int()?,
position: get_vec(bytebuf)?,
delta: get_vec(bytebuf)?,
yaw: bytebuf.try_get_f32()?,
pitch: bytebuf.try_get_f32()?,
releatives: &[], // TODO
})
}
}

impl ClientPacket for CPlayerPosition<'_> {
fn write(&self, bytebuf: &mut impl BufMut) {
bytebuf.put_var_int(&self.teleport_id);
Expand Down

0 comments on commit 7c1d5ef

Please # to comment.