diff options
| author | mat <github@matdoes.dev> | 2022-04-27 15:09:33 +0000 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-04-27 15:09:33 +0000 |
| commit | 60d1fa50c32c202dd04895caa51172948a4760b6 (patch) | |
| tree | 2af30c7de1d37bc3150a637e8b3150d40d95feea /azalea-protocol/src/packets/game | |
| parent | 4f9f2468f0fc80b19baac6904c05c9cc9a9cb61a (diff) | |
| download | azalea-drasl-60d1fa50c32c202dd04895caa51172948a4760b6.tar.xz | |
add player position packet
Diffstat (limited to 'azalea-protocol/src/packets/game')
| -rw-r--r-- | azalea-protocol/src/packets/game/clientbound_player_position_packet.rs | 69 | ||||
| -rwxr-xr-x | azalea-protocol/src/packets/game/mod.rs | 2 |
2 files changed, 71 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) + } +} diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index d197015a..436e0cc2 100755 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -5,6 +5,7 @@ pub mod clientbound_disconnect_packet; pub mod clientbound_entity_event_packet; pub mod clientbound_login_packet; pub mod clientbound_player_abilities_packet; +pub mod clientbound_player_position_packet; pub mod clientbound_recipe_packet; pub mod clientbound_set_carried_item_packet; pub mod clientbound_update_recipes_packet; @@ -24,6 +25,7 @@ declare_state_packets!( 0x18: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket, 0x26: clientbound_login_packet::ClientboundLoginPacket, 0x32: clientbound_player_abilities_packet::ClientboundPlayerAbilitiesPacket, + 0x38: clientbound_player_position_packet::ClientboundPlayerPositionPacket, 0x39: clientbound_recipe_packet::ClientboundRecipePacket, 0x48: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket, 0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket, |
