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/src/bot.rs | |
| parent | e0bcab53b8a3721a008e47062c6b5972fa64b8ad (diff) | |
| download | azalea-drasl-ba4cfaafaec97a3c5b9405fe542035ebe9039edd.tar.xz | |
Bot API (#27)
Basically make the `azalea` crate have stuff
Diffstat (limited to 'azalea/src/bot.rs')
| -rw-r--r-- | azalea/src/bot.rs | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs index 6746e09e..a77e2a1c 100644 --- a/azalea/src/bot.rs +++ b/azalea/src/bot.rs @@ -1,14 +1,46 @@ -pub struct BotState { +use crate::{Client, Event}; +use async_trait::async_trait; +use parking_lot::Mutex; +use std::sync::Arc; + +#[derive(Default)] +pub struct Plugin { + pub state: Arc<Mutex<State>>, +} + +#[derive(Default)] +pub struct State { jumping_once: bool, } pub trait BotTrait { - fn jump(&mut self); + fn jump(&self); } impl BotTrait for azalea_client::Client { - fn jump(&mut self) { - let mut physics_state = self.physics_state.lock().unwrap(); - physics_state.jumping_once = true; + /// Try to jump next tick. + fn jump(&self) { + 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"); + + player_entity.jumping = true; + } +} + +#[async_trait] +impl crate::Plugin for Plugin { + async fn handle(self: Arc<Self>, mut bot: Client, event: Arc<Event>) { + if let Event::Tick = *event { + let mut state = self.state.lock(); + if bot.jumping() { + state.jumping_once = false; + } else if state.jumping_once { + bot.set_jumping(true); + } + } } } |
