aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xazalea-client/src/connect.rs4
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_position_packet.rs69
-rwxr-xr-xazalea-protocol/src/packets/game/mod.rs2
3 files changed, 75 insertions, 0 deletions
diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs
index d8b47321..78370d7e 100755
--- a/azalea-client/src/connect.rs
+++ b/azalea-client/src/connect.rs
@@ -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);
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,