aboutsummaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-10-07 19:57:42 -0500
committerGitHub <noreply@github.com>2022-10-07 19:57:42 -0500
commitba4cfaafaec97a3c5b9405fe542035ebe9039edd (patch)
tree5fc7340a49f96d84f86ed6adf400ad461c47d1b6 /bot
parente0bcab53b8a3721a008e47062c6b5972fa64b8ad (diff)
downloadazalea-drasl-ba4cfaafaec97a3c5b9405fe542035ebe9039edd.tar.xz
Bot API (#27)
Basically make the `azalea` crate have stuff
Diffstat (limited to 'bot')
-rwxr-xr-xbot/Cargo.toml6
-rw-r--r--bot/src/main.rs44
2 files changed, 22 insertions, 28 deletions
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<Event>, _state: Arc<Mutex<State>>) -> anyhow::Result<()> {
+ if let Event::Tick = *event {
+ bot.jump();
}
Ok(())