aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/movement.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-06-25 05:09:26 +0000
committerGitHub <noreply@github.com>2022-06-25 05:09:26 +0000
commit7d3e57763e32ac9cf94180b1c714704cfbc3034d (patch)
tree2dcfe72bf09a42f6614f9dc988dc0254162ea0bf /azalea-client/src/movement.rs
parent69c47eda4c496b13dadd80976bffd2fab7ea5894 (diff)
parentca7067e173129f3044ebc8c77634f06da29a086e (diff)
downloadazalea-drasl-7d3e57763e32ac9cf94180b1c714704cfbc3034d.tar.xz
Merge pull request #10 from mat-1/azalea-entity
azalea-entity
Diffstat (limited to 'azalea-client/src/movement.rs')
-rw-r--r--azalea-client/src/movement.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs
new file mode 100644
index 00000000..f74d48df
--- /dev/null
+++ b/azalea-client/src/movement.rs
@@ -0,0 +1,45 @@
+use crate::Client;
+use azalea_core::EntityPos;
+use azalea_protocol::packets::game::serverbound_move_player_packet_pos_rot::ServerboundMovePlayerPacketPosRot;
+
+impl Client {
+ /// Set the client's position to the given coordinates.
+ pub async fn move_to(&mut self, new_pos: EntityPos) -> Result<(), String> {
+ println!("obtaining lock on state");
+ let mut state_lock = self.state.lock().unwrap();
+ println!("obtained lock on state");
+
+ let world = state_lock.world.as_ref().unwrap();
+
+ let player = &state_lock.player;
+ let player_id = if let Some(player) = player.entity(world) {
+ player.id
+ } else {
+ return Err("Player entity not found".to_string());
+ };
+
+ let world = state_lock.world.as_mut().unwrap();
+ world.move_entity(player_id, new_pos)?;
+ drop(state_lock);
+
+ println!("obtaining lock on conn");
+ self.conn
+ .lock()
+ .await
+ .write(
+ ServerboundMovePlayerPacketPosRot {
+ x: new_pos.x,
+ y: new_pos.y,
+ z: new_pos.z,
+ x_rot: 0.0,
+ y_rot: 0.0,
+ on_ground: false,
+ }
+ .get(),
+ )
+ .await;
+ println!("obtained lock on conn");
+
+ Ok(())
+ }
+}