aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-08-25 02:34:31 -0500
committermat <git@matdoes.dev>2023-08-25 02:34:31 -0500
commitd5465cd28e43d48b3e913fdb1161eb907e4d80d0 (patch)
treeb0962ac1bd09b434c67296c038ef3b26245ce6d7 /azalea/examples
parent9c31f8033f006d5f505ce97e359638d6c1136859 (diff)
downloadazalea-drasl-d5465cd28e43d48b3e913fdb1161eb907e4d80d0.tar.xz
add basic pathfinding test
Diffstat (limited to 'azalea/examples')
-rwxr-xr-xazalea/examples/echo.rs17
-rw-r--r--azalea/examples/steal.rs79
-rw-r--r--azalea/examples/testbot.rs7
3 files changed, 48 insertions, 55 deletions
diff --git a/azalea/examples/echo.rs b/azalea/examples/echo.rs
index dbf56a31..01390982 100755
--- a/azalea/examples/echo.rs
+++ b/azalea/examples/echo.rs
@@ -18,16 +18,13 @@ async fn main() {
pub struct State {}
async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
- match event {
- Event::Chat(m) => {
- if let (Some(sender), content) = m.split_sender_and_content() {
- if sender == bot.profile.name {
- return Ok(()); // ignore our own messages
- }
- bot.chat(&content);
- };
- }
- _ => {}
+ if let Event::Chat(m) = event {
+ if let (Some(sender), content) = m.split_sender_and_content() {
+ if sender == bot.profile.name {
+ return Ok(()); // ignore our own messages
+ }
+ bot.chat(&content);
+ };
}
Ok(())
diff --git a/azalea/examples/steal.rs b/azalea/examples/steal.rs
index 7a7ee4bb..9bbda945 100644
--- a/azalea/examples/steal.rs
+++ b/azalea/examples/steal.rs
@@ -24,52 +24,49 @@ struct State {
}
async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<()> {
- match event {
- Event::Chat(m) => {
- if m.username() == Some(bot.profile.name.clone()) {
- return Ok(());
- };
- if m.content() != "go" {
- return Ok(());
- }
- {
- state.checked_chests.lock().clear();
- }
+ if let Event::Chat(m) = event {
+ if m.username() == Some(bot.profile.name.clone()) {
+ return Ok(());
+ };
+ if m.content() != "go" {
+ return Ok(());
+ }
+ {
+ state.checked_chests.lock().clear();
+ }
- let chest_block = bot
- .world()
- .read()
- .find_block(bot.position(), &azalea::Block::Chest.into());
- // TODO: update this when find_blocks is implemented
- let Some(chest_block) = chest_block else {
- bot.chat("No chest found");
- return Ok(());
- };
- // bot.goto(BlockPosGoal::from(chest_block));
- let Some(chest) = bot.open_container(chest_block).await else {
- println!("Couldn't open chest");
- return Ok(());
- };
+ let chest_block = bot
+ .world()
+ .read()
+ .find_block(bot.position(), &azalea::Block::Chest.into());
+ // TODO: update this when find_blocks is implemented
+ let Some(chest_block) = chest_block else {
+ bot.chat("No chest found");
+ return Ok(());
+ };
+ // bot.goto(BlockPosGoal::from(chest_block));
+ let Some(chest) = bot.open_container(chest_block).await else {
+ println!("Couldn't open chest");
+ return Ok(());
+ };
- println!("Getting contents");
- for (index, slot) in chest
- .contents()
- .expect("we just opened the chest")
- .iter()
- .enumerate()
- {
- println!("Checking slot {index}: {slot:?}");
- if let ItemSlot::Present(item) = slot {
- if item.kind == azalea::Item::Diamond {
- println!("clicking slot ^");
- chest.click(QuickMoveClick::Left { slot: index as u16 });
- }
+ println!("Getting contents");
+ for (index, slot) in chest
+ .contents()
+ .expect("we just opened the chest")
+ .iter()
+ .enumerate()
+ {
+ println!("Checking slot {index}: {slot:?}");
+ if let ItemSlot::Present(item) = slot {
+ if item.kind == azalea::Item::Diamond {
+ println!("clicking slot ^");
+ chest.click(QuickMoveClick::Left { slot: index as u16 });
}
}
-
- println!("Done");
}
- _ => {}
+
+ println!("Done");
}
Ok(())
diff --git a/azalea/examples/testbot.rs b/azalea/examples/testbot.rs
index 3d566410..14800e9c 100644
--- a/azalea/examples/testbot.rs
+++ b/azalea/examples/testbot.rs
@@ -284,12 +284,11 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result<
_ => {}
}
}
- Event::Packet(packet) => match *packet {
- ClientboundGamePacket::Login(_) => {
+ Event::Packet(packet) => {
+ if let ClientboundGamePacket::Login(_) = *packet {
println!("login packet");
}
- _ => {}
- },
+ }
_ => {}
}