From d5465cd28e43d48b3e913fdb1161eb907e4d80d0 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 25 Aug 2023 02:34:31 -0500 Subject: add basic pathfinding test --- azalea/examples/echo.rs | 17 ++++------ azalea/examples/steal.rs | 79 ++++++++++++++++++++++------------------------ azalea/examples/testbot.rs | 7 ++-- 3 files changed, 48 insertions(+), 55 deletions(-) (limited to 'azalea/examples') 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"); } - _ => {} - }, + } _ => {} } -- cgit v1.2.3