diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-11-12 23:54:05 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-12 23:54:05 -0600 |
| commit | 6eee543a3367d38a6f0e9bffb457a2bd76a8f9cc (patch) | |
| tree | a5e493ccd7ec24293b8d866242c3836146517122 /bot | |
| parent | fa57d03627aa20b1df44caed7cb025b6db1d9b53 (diff) | |
| download | azalea-drasl-6eee543a3367d38a6f0e9bffb457a2bd76a8f9cc.tar.xz | |
Pathfinder (#25)
Pathfinding is very much not done, but it works enough and I want to get this merged.
TODO: fast replanning, goals that aren't a single node, falling moves (it should be able to play the dropper), parkour moves
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/Cargo.toml | 4 | ||||
| -rwxr-xr-x[-rw-r--r--] | bot/src/main.rs | 50 |
2 files changed, 48 insertions, 6 deletions
diff --git a/bot/Cargo.toml b/bot/Cargo.toml index 9212f796..6663d1f7 100644 --- a/bot/Cargo.toml +++ b/bot/Cargo.toml @@ -11,6 +11,6 @@ version = "0.2.0" anyhow = "1.0.65" azalea = {path = "../azalea"} env_logger = "0.9.1" -parking_lot = "^0.12.1" -tokio = "^1.21.2" +parking_lot = {version = "^0.12.1", features = ["deadlock_detection"]} +tokio = "1.19.2" uuid = "1.1.2" diff --git a/bot/src/main.rs b/bot/src/main.rs index 3ab90bfd..f1398062 100644..100755 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -1,4 +1,5 @@ -use azalea::prelude::*; +use azalea::pathfinder::BlockPosGoal; +use azalea::{prelude::*, BlockPos}; use azalea::{Account, Client, Event}; #[derive(Default, Clone)] @@ -8,6 +9,31 @@ struct State {} async fn main() -> anyhow::Result<()> { env_logger::init(); + { + // only for #[cfg] + use parking_lot::deadlock; + use std::thread; + use std::time::Duration; + + // Create a background thread which checks for deadlocks every 10s + thread::spawn(move || loop { + thread::sleep(Duration::from_secs(10)); + let deadlocks = deadlock::check_deadlock(); + if deadlocks.is_empty() { + continue; + } + + println!("{} deadlocks detected", deadlocks.len()); + for (i, threads) in deadlocks.iter().enumerate() { + println!("Deadlock #{}", i); + for t in threads { + println!("Thread Id {:#?}", t.thread_id()); + println!("{:#?}", t.backtrace()); + } + } + }); + } // only for #[cfg] + // let account = Account::microsoft("example@example.com").await?; let account = Account::offline("bot"); @@ -16,7 +42,7 @@ async fn main() -> anyhow::Result<()> { account: account.clone(), address: "localhost", state: State::default(), - plugins: vec![], + plugins: plugins![], handle, }) .await; @@ -27,13 +53,29 @@ async fn main() -> anyhow::Result<()> { async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> { match event { Event::Login => { - bot.chat("Hello world").await?; + // bot.chat("Hello world").await?; + } + Event::Chat(m) => { + println!("{}", m.message().to_ansi(None)); + if m.message().to_string() == "<py5> goto" { + let target_pos_vec3 = bot + .dimension + .read() + .entity_by_uuid(&uuid::uuid!("6536bfed869548fd83a1ecd24cf2a0fd")) + .unwrap() + .pos() + .clone(); + let target_pos: BlockPos = (&target_pos_vec3).into(); + // bot.look_at(&target_pos_vec3); + bot.goto(BlockPosGoal::from(target_pos)); + // bot.walk(WalkDirection::Forward); + } } Event::Initialize => { println!("initialized"); } Event::Tick => { - bot.jump(); + // bot.jump(); } _ => {} } |
