aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-28 22:50:39 +0000
committermat <github@matdoes.dev>2022-04-28 22:50:39 +0000
commit2575da38edac2e4e546e0b49bfd308003c62263f (patch)
tree4117d92d16c3d98a427e4530e1d3f366c661ee52
parentc2a9acc7561927d4c76c8de29915935af95048fd (diff)
downloadazalea-drasl-2575da38edac2e4e546e0b49bfd308003c62263f.tar.xz
write more example code
-rwxr-xr-xREADME.md51
1 files changed, 46 insertions, 5 deletions
diff --git a/README.md b/README.md
index 6502b0ae..09eee993 100755
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ I named this Azalea because it sounds like a cool word and this is a cool librar
## Example code
-Note that this doesn't work yet, it's just how I want the API to look.
+Note that these doesn't work yet, it's just how I want the API to look.
```rs
use azalea::{Bot, Event};
@@ -39,6 +39,46 @@ loop {
}
```
+```rs
+use azalea::{Bot, Event};
+
+let bot = Bot::offline("bot");
+// or let bot = azalea::Bot::microsoft("access token").await;
+
+bot.join("localhost".try_into().unwrap()).await.unwrap();
+
+loop {
+ match bot.recv().await {
+ Event::Message(m) {
+ if m.username == bot.username { return };
+ if m.message = "go" {
+ bot.goto_goal(
+ pathfinder::Goals::NearXZ(5, azalea::BlockXZ(0, 0))
+ ).await;
+ let chest = bot.open_chest(&bot.world.find_one_block(|b| b.id == "minecraft:chest")).await.unwrap();
+ bot.take_amount(&chest, 3, |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.feet_coords().down(1)).await {
+ println!("{:?}", e);
+ break;
+ }
+ }
+ }
+ },
+ _ => {}
+ }
+}
+```
+
You can use the `azalea::Bots` struct to control many bots as one unit.
```rs
@@ -54,14 +94,15 @@ async fn main() {
bots.join("localhost".try_into().unwrap()).await.unwrap();
- bots.goto(pathfinder::GotoGoal(azalea::BlockCoord(0, 70, 0))).await;
+ 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(
- pathfinder::FillGoal(
- azalea::BlockCoord(-5, 60, -5),
- azalea::BlockCoord(5, 70, 5)
+ azalea::Selection::Range(
+ azalea::BlockCoord(0, 0, 0),
+ azalea::BlockCoord(16, 255, 16)
),
azalea::block::Air
).await;