From ba4cfaafaec97a3c5b9405fe542035ebe9039edd Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Fri, 7 Oct 2022 19:57:42 -0500 Subject: Bot API (#27) Basically make the `azalea` crate have stuff --- bot/src/main.rs | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'bot/src') diff --git a/bot/src/main.rs b/bot/src/main.rs index 9b2eea1f..0a291fd8 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -1,35 +1,31 @@ -use azalea_client::{Account, Client, Event, MoveDirection}; -use std::convert::TryInto; +use azalea::prelude::*; +use azalea::{Account, Client, Event}; +use parking_lot::Mutex; +use std::sync::Arc; + +#[derive(Default)] +struct State {} #[tokio::main] async fn main() { env_logger::init(); - let bot = Account::offline("bot"); - - let (bot, mut rx) = bot.join(&"localhost".try_into().unwrap()).await.unwrap(); + let account = Account::offline("bot"); - while let Some(event) = rx.recv().await { - tokio::spawn(handle_event(event, bot.clone())); - } + azalea::start(azalea::Options { + account, + address: "localhost", + state: Arc::new(Mutex::new(State::default())), + plugins: vec![], + handle, + }) + .await + .unwrap(); } -async fn handle_event(event: Event, mut bot: Client) -> anyhow::Result<()> { - match event { - Event::Login => { - // tokio::time::sleep(std::time::Duration::from_secs(1)).await; - // bot.walk(MoveDirection::Forward); - - // loop { - // tokio::time::sleep(std::time::Duration::from_secs(2)).await; - // } - // bot.walk(MoveDirection::None); - } - Event::GameTick => { - bot.set_jumping(true); - } - Event::Packet(_packet) => {} - _ => {} +async fn handle(bot: Client, event: Arc, _state: Arc>) -> anyhow::Result<()> { + if let Event::Tick = *event { + bot.jump(); } Ok(()) -- cgit v1.2.3