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/Cargo.toml | 6 ++---- bot/src/main.rs | 44 ++++++++++++++++++++------------------------ 2 files changed, 22 insertions(+), 28 deletions(-) (limited to 'bot') diff --git a/bot/Cargo.toml b/bot/Cargo.toml index b51e6705..53f8637b 100755 --- a/bot/Cargo.toml +++ b/bot/Cargo.toml @@ -7,10 +7,8 @@ version = "0.1.0" [dependencies] anyhow = "1.0.65" -azalea-client = {path = "../azalea-client"} -azalea-core = {path = "../azalea-core"} -azalea-physics = {path = "../azalea-physics"} -azalea-protocol = {path = "../azalea-protocol"} +azalea = { path = "../azalea" } env_logger = "0.9.1" tokio = "1.19.2" uuid = "1.1.2" +parking_lot = "^0.12.1" 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