diff options
Diffstat (limited to 'azalea/src/bot.rs')
| -rw-r--r--[-rwxr-xr-x] | azalea/src/bot.rs | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs index 0becaa62..0674c692 100755..100644 --- a/azalea/src/bot.rs +++ b/azalea/src/bot.rs @@ -4,9 +4,14 @@ use azalea_core::Vec3; use parking_lot::Mutex; use std::{f64::consts::PI, sync::Arc}; -#[derive(Default, Clone)] -pub struct Plugin { - pub state: State, +#[derive(Clone, Default)] +pub struct Plugin; +impl crate::Plugin for Plugin { + type State = State; + + fn build(&self) -> State { + State::default() + } } #[derive(Default, Clone)] @@ -14,6 +19,18 @@ pub struct State { jumping_once: Arc<Mutex<bool>>, } +#[async_trait] +impl crate::PluginState for State { + async fn handle(self: Box<Self>, event: Event, mut bot: Client) { + if let Event::Tick = event { + if *self.jumping_once.lock() && bot.jumping() { + *self.jumping_once.lock() = false; + bot.set_jumping(false); + } + } + } +} + pub trait BotTrait { fn jump(&mut self); fn look_at(&mut self, pos: &Vec3); @@ -23,7 +40,7 @@ impl BotTrait for azalea_client::Client { /// Queue a jump for the next tick. fn jump(&mut self) { self.set_jumping(true); - let state = self.plugins.get::<Plugin>().unwrap().state.clone(); + let state = self.plugins.get::<State>().unwrap().clone(); *state.jumping_once.lock() = true; } @@ -34,18 +51,6 @@ impl BotTrait for azalea_client::Client { } } -#[async_trait] -impl crate::Plugin for Plugin { - async fn handle(self: Box<Self>, event: Event, mut bot: Client) { - if let Event::Tick = event { - if *self.state.jumping_once.lock() && bot.jumping() { - *self.state.jumping_once.lock() = false; - bot.set_jumping(false); - } - } - } -} - fn direction_looking_at(current: &Vec3, target: &Vec3) -> (f32, f32) { // borrowed from mineflayer's Bot.lookAt because i didn't want to do math let delta = target - current; |
