diff options
Diffstat (limited to 'bot/src')
| -rwxr-xr-x[-rw-r--r--] | bot/src/main.rs | 50 |
1 files changed, 46 insertions, 4 deletions
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(); } _ => {} } |
