diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-10-07 19:57:42 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-07 19:57:42 -0500 |
| commit | ba4cfaafaec97a3c5b9405fe542035ebe9039edd (patch) | |
| tree | 5fc7340a49f96d84f86ed6adf400ad461c47d1b6 /azalea-client/src/movement.rs | |
| parent | e0bcab53b8a3721a008e47062c6b5972fa64b8ad (diff) | |
| download | azalea-drasl-ba4cfaafaec97a3c5b9405fe542035ebe9039edd.tar.xz | |
Bot API (#27)
Basically make the `azalea` crate have stuff
Diffstat (limited to 'azalea-client/src/movement.rs')
| -rw-r--r-- | azalea-client/src/movement.rs | 54 |
1 files changed, 22 insertions, 32 deletions
diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs index ab324370..fb4a5968 100644 --- a/azalea-client/src/movement.rs +++ b/azalea-client/src/movement.rs @@ -31,9 +31,9 @@ impl Client { /// This gets called every tick. pub async fn send_position(&mut self) -> Result<(), MovePlayerError> { let packet = { - let player_lock = self.player.lock().unwrap(); - let mut physics_state = self.physics_state.lock().unwrap(); - let mut dimension_lock = self.dimension.lock().unwrap(); + let player_lock = self.player.lock(); + let mut physics_state = self.physics_state.lock(); + let mut dimension_lock = self.dimension.lock(); let mut player_entity = player_lock .entity_mut(&mut dimension_lock) @@ -129,8 +129,8 @@ impl Client { // Set our current position to the provided Vec3, potentially clipping through blocks. pub async fn set_pos(&mut self, new_pos: Vec3) -> Result<(), MovePlayerError> { - let player_lock = self.player.lock().unwrap(); - let mut dimension_lock = self.dimension.lock().unwrap(); + let player_lock = self.player.lock(); + let mut dimension_lock = self.dimension.lock(); dimension_lock.set_entity_pos(player_lock.entity_id, new_pos)?; @@ -138,8 +138,8 @@ impl Client { } pub async fn move_entity(&mut self, movement: &Vec3) -> Result<(), MovePlayerError> { - let mut dimension_lock = self.dimension.lock().unwrap(); - let player = self.player.lock().unwrap(); + let mut dimension_lock = self.dimension.lock(); + let player = self.player.lock(); let mut entity = player .entity_mut(&mut dimension_lock) @@ -157,25 +157,17 @@ impl Client { pub fn ai_step(&mut self) { self.tick_controls(None); - let player_lock = self.player.lock().unwrap(); - let mut dimension_lock = self.dimension.lock().unwrap(); - + let player_lock = self.player.lock(); + let mut dimension_lock = self.dimension.lock(); let mut player_entity = player_lock .entity_mut(&mut dimension_lock) .expect("Player must exist"); // server ai step { - let mut physics_state = self.physics_state.lock().unwrap(); + let physics_state = self.physics_state.lock(); player_entity.xxa = physics_state.left_impulse; player_entity.zza = physics_state.forward_impulse; - - // handle jumping_once - if physics_state.jumping_once { - player_entity.jumping = true; - } else if player_entity.jumping { - physics_state.jumping_once = false; - } } player_entity.ai_step(); @@ -183,7 +175,7 @@ impl Client { /// Update the impulse from self.move_direction. The multipler is used for sneaking. pub(crate) fn tick_controls(&mut self, multiplier: Option<f32>) { - let mut physics_state = self.physics_state.lock().unwrap(); + let mut physics_state = self.physics_state.lock(); let mut forward_impulse: f32 = 0.; let mut left_impulse: f32 = 0.; @@ -219,31 +211,29 @@ impl Client { /// Start walking in the given direction. pub fn walk(&mut self, direction: MoveDirection) { - let mut physics_state = self.physics_state.lock().unwrap(); + let mut physics_state = self.physics_state.lock(); physics_state.move_direction = direction; } - /// Jump once next tick. This acts as if you pressed space for one tick in - /// vanilla. If you want to jump continuously, use `set_jumping`. - pub fn jump(&mut self) { - let mut physics_state = self.physics_state.lock().unwrap(); - physics_state.jumping_once = true; - } - /// Toggle whether we're jumping. This acts as if you held space in /// vanilla. If you want to jump once, use the `jump` function. /// /// If you're making a realistic client, calling this function every tick is /// recommended. pub fn set_jumping(&mut self, jumping: bool) { - let player_lock = self.player.lock().unwrap(); - let mut dimension_lock = self.dimension.lock().unwrap(); - let mut player_entity = player_lock - .entity_mut(&mut dimension_lock) - .expect("Player must exist"); + let mut dimension = self.dimension.lock(); + let mut player_entity = self.entity_mut(&mut dimension); player_entity.jumping = jumping; } + + /// Returns whether the player will try to jump next tick. + pub fn jumping(&self) -> bool { + let dimension = self.dimension.lock(); + let player_entity = self.entity(&dimension); + + player_entity.jumping + } } #[derive(Clone, Copy, Debug, Default)] |
