blob: 7ab4ddc23a3d2607abc4b4f210f9961da3644854 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
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> {
let mut dimension_lock = self.dimension.lock().unwrap();
let dimension = dimension_lock.as_mut().unwrap();
let mut player_lock = self.player.lock().unwrap();
let player_id = if let Some(player_lock) = player_lock.entity(dimension) {
player_lock.id
} else {
return Err("Player entity not found".to_string());
};
dimension.move_entity(player_id, new_pos)?;
drop(dimension_lock);
drop(player_lock);
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(())
}
}
|