aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/craft_dig_straight_down.rs57
-rw-r--r--examples/echo.rs38
-rw-r--r--examples/mine_a_chunk.rs27
-rw-r--r--examples/pvp.rs33
4 files changed, 0 insertions, 155 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
diff --git a/examples/echo.rs b/examples/echo.rs
deleted file mode 100644
index c9e46a09..00000000
--- a/examples/echo.rs
+++ /dev/null
@@ -1,38 +0,0 @@
-use azalea::{Account, Event};
-
-let account = Account::offline("bot");
-// or let account = azalea::Account::microsoft("access token").await;
-
-let bot = account.join("localhost".try_into().unwrap()).await.unwrap();
-
-loop {
- match bot.next().await {
- Event::Message(m) {
- if m.username == bot.username { return };
- bot.chat(m.message).await;
- },
- Event::Kicked(m) {
- println!(m);
- bot.reconnect().await.unwrap();
- },
- Event::Hunger(h) {
- if !h.using_held_item() && h.hunger <= 17 {
- match bot.hold(azalea::ItemGroup::Food).await {
- Ok(_) => {},
- Err(e) => {
- println!("{}", e);
- break;
- }
- }
- match bot.use_held_item().await {
- Ok(_) => {},
- Err(e) => {
- println!("{}", e);
- break;
- }
- }
- }
- }
- _ => {}
- }
-}
diff --git a/examples/mine_a_chunk.rs b/examples/mine_a_chunk.rs
deleted file mode 100644
index bb85a637..00000000
--- a/examples/mine_a_chunk.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-use azalea::{Account, Accounts, Event, pathfinder};
-
-// You can use the `azalea::Bots` struct to control many bots as one unit.
-
-#[tokio::main]
-async fn main() {
- let accounts = Accounts::new();
-
- for i in 0..10 {
- accounts.add(Account::offline(format!("bot{}", i)));
- }
-
- let bots = accounts.join("localhost".try_into().unwrap()).await.unwrap();
-
- bots.goto(azalea::BlockCoord(0, 70, 0)).await;
- // or bots.goto_goal(pathfinder::Goals::Goto(azalea::BlockCoord(0, 70, 0))).await;
-
- // destroy the blocks in this area and then leave
-
- bots.fill(
- azalea::Selection::Range(
- azalea::BlockCoord(0, 0, 0),
- azalea::BlockCoord(16, 255, 16)
- ),
- azalea::block::Air
- ).await;
-}
diff --git a/examples/pvp.rs b/examples/pvp.rs
deleted file mode 100644
index 5febdd45..00000000
--- a/examples/pvp.rs
+++ /dev/null
@@ -1,33 +0,0 @@
-use azalea::{Account, Accounts, Event, pathfinder};
-
-#[tokio::main]
-async fn main() {
- let accounts = Accounts::new();
- for i in 0..10 {
- accounts.add(Account::offline(format!("bot{}", i)));
- }
-
- let bots = accounts.join("localhost".try_into().unwrap()).await.unwrap();
-
- match bots.next().await {
- Event::Tick {
- // choose an arbitrary player within render distance to target
- if let Some(target) = bots.world.find_one_entity(|e| e.id == "minecraft:player") {
- for bot in bots {
- bot.tick_goto_goal(
- pathfinder::Goals::Reach(target.bounding_box)
- );
- // if target.bounding_box.distance(bot.eyes) < bot.reach_distance() {
- if bot.entity.can_reach(target.bounding_box) {
- bot.swing();
- }
- if !h.using_held_item() && bot.state.lock().hunger <= 17 {
- bot.hold(azalea::ItemGroup::Food);
- tokio::task::spawn(bot.use_held_item());
- }
- }
- }
- },
- _ => {}
- }
-}