mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
Update craft_dig_straight_down.rs
This commit is contained in:
parent
c46eb556e2
commit
f9e42fa3d8
1 changed files with 26 additions and 6 deletions
|
@ -1,15 +1,35 @@
|
|||
use azalea::{Bot, Event};
|
||||
|
||||
let bot = Bot::offline("bot");
|
||||
// or let bot = azalea::Bot::microsoft("access token").await;
|
||||
struct Context {
|
||||
pub started: bool
|
||||
}
|
||||
|
||||
bot.join("localhost".try_into().unwrap()).await.unwrap();
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let bot = Bot::offline("bot");
|
||||
// or let bot = azalea::Bot::microsoft("access token").await;
|
||||
|
||||
loop {
|
||||
match bot.next().await {
|
||||
bot.join("localhost".try_into().unwrap()).await.unwrap();
|
||||
|
||||
let ctx = Arc::new(Mutex::new(Context { started: false }));
|
||||
|
||||
loop {
|
||||
tokio::spawn(handle_event(bot.next().await, bot, ctx.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async fn handle_event(event: &Event, bot: &Bot, ctx: Arc<Context>) {
|
||||
match event {
|
||||
Event::Message(m) {
|
||||
if m.username == bot.player.username { return };
|
||||
if m.message = "go" {
|
||||
// make sure we only start once
|
||||
let ctx_lock = ctx.lock().unwrap();
|
||||
if ctx_lock.started { return };
|
||||
ctx_lock.started = true;
|
||||
drop(ctx_lock);
|
||||
|
||||
bot.goto_goal(
|
||||
pathfinder::Goals::NearXZ(5, azalea::BlockXZ(0, 0))
|
||||
).await;
|
||||
|
@ -34,4 +54,4 @@ loop {
|
|||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue