aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-10-02 14:52:48 -0500
committermat <github@matdoes.dev>2022-10-02 14:52:48 -0500
commit37f9f1c6feda676be30bef31291eaed2a5fc82ce (patch)
tree9e61a94766d0477eeb861165fa721f8b42bb9a85 /azalea-client/src
parentc9b4dccd7eaeed68ce96cf5167916417d0baa6a7 (diff)
downloadazalea-drasl-37f9f1c6feda676be30bef31291eaed2a5fc82ce.tar.xz
add jumping
Diffstat (limited to 'azalea-client/src')
-rw-r--r--azalea-client/src/client.rs6
-rw-r--r--azalea-client/src/movement.rs32
2 files changed, 37 insertions, 1 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index cca932c0..2b721206 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -85,6 +85,12 @@ pub struct PhysicsState {
pub move_direction: MoveDirection,
pub forward_impulse: f32,
pub left_impulse: f32,
+
+ /// Whether we will jump next tick. This is purely to help with bots,
+ /// realistic clients should change the `jumping` field in the player entity.
+ ///
+ /// TODO: have a convenient way to change the `jumping` field in the player entity.
+ pub jumping_once: bool,
}
/// Whether we should ignore errors when decoding packets.
diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs
index 193f2017..ab324370 100644
--- a/azalea-client/src/movement.rs
+++ b/azalea-client/src/movement.rs
@@ -166,9 +166,16 @@ impl Client {
// server ai step
{
- let physics_state = self.physics_state.lock().unwrap();
+ let mut physics_state = self.physics_state.lock().unwrap();
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();
@@ -210,10 +217,33 @@ impl Client {
}
}
+ /// Start walking in the given direction.
pub fn walk(&mut self, direction: MoveDirection) {
let mut physics_state = self.physics_state.lock().unwrap();
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");
+
+ player_entity.jumping = jumping;
+ }
}
#[derive(Clone, Copy, Debug, Default)]