1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

add player position packet

This commit is contained in:
mat 2022-04-27 15:09:33 +00:00
parent 4f9f2468f0
commit 60d1fa50c3
3 changed files with 75 additions and 0 deletions

View file

@ -123,6 +123,10 @@ pub async fn join_server(address: &ServerAddress) -> Result<(), String> {
GamePacket::ClientboundRecipePacket(p) => {
println!("Got recipe packet {:?}", p);
}
GamePacket::ClientboundPlayerPositionPacket(p) => {
// TODO: reply with teleport confirm
println!("Got player position packet {:?}", p);
}
},
Err(e) => {
panic!("Error: {:?}", e);

View file

@ -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)
}
}

View file

@ -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,