aboutsummaryrefslogtreecommitdiff
path: root/examples/craft_dig_straight_down.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-10-02 14:58:42 -0500
committerGitHub <noreply@github.com>2022-10-02 14:58:42 -0500
commit06068377bd17f95bdafe86ff14bab1d0d852aa53 (patch)
treeed3f15107d69dc0cc8f6794745832b82a1649c80 /examples/craft_dig_straight_down.rs
parent37f9f1c6feda676be30bef31291eaed2a5fc82ce (diff)
downloadazalea-drasl-06068377bd17f95bdafe86ff14bab1d0d852aa53.tar.xz
New example (#24)
the example isn't finished but it's finished enough
Diffstat (limited to 'examples/craft_dig_straight_down.rs')
-rw-r--r--examples/craft_dig_straight_down.rs57
1 files changed, 0 insertions, 57 deletions
diff --git a/examples/craft_dig_straight_down.rs b/examples/craft_dig_straight_down.rs
deleted file mode 100644
index 47c4fe28..00000000
--- a/examples/craft_dig_straight_down.rs
+++ /dev/null
@@ -1,57 +0,0 @@
-use azalea::{Bot, Event};
-
-struct Context {
- pub started: bool
-}
-
-#[tokio::main]
-async fn main() {
- let bot = Bot::offline("bot");
- // or let bot = azalea::Bot::microsoft("access token").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;
- let chest = bot.open_container(&bot.world.find_one_block(|b| b.id == "minecraft:chest")).await.unwrap();
- bot.take_amount(&chest, 5, |i| i.id == "#minecraft:planks").await;
- // when rust adds async drop this won't be necessary
- chest.close().await;
-
- let crafting_table = bot.open_crafting_table(&bot.world.find_one_block(|b| b.id == "minecraft:crafting_table")).await.unwrap();
- bot.craft(&crafting_table, &bot.recipe_for("minecraft:sticks")).await?;
- let pickaxe = bot.craft(&crafting_table, &bot.recipe_for("minecraft:wooden_pickaxe")).await?;
- crafting_table.close().await;
-
- bot.hold(&pickaxe);
- loop {
- if let Err(e) = bot.dig(bot.entity.feet_pos().down(1)).await {
- println!("{:?}", e);
- break;
- }
- }
- }
- },
- _ => {}
- }
-} \ No newline at end of file