diff options
| author | mat <git@matdoes.dev> | 2023-08-25 02:34:31 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-08-25 02:34:31 -0500 |
| commit | d5465cd28e43d48b3e913fdb1161eb907e4d80d0 (patch) | |
| tree | b0962ac1bd09b434c67296c038ef3b26245ce6d7 /azalea/examples/steal.rs | |
| parent | 9c31f8033f006d5f505ce97e359638d6c1136859 (diff) | |
| download | azalea-drasl-d5465cd28e43d48b3e913fdb1161eb907e4d80d0.tar.xz | |
add basic pathfinding test
Diffstat (limited to 'azalea/examples/steal.rs')
| -rw-r--r-- | azalea/examples/steal.rs | 79 |
1 files changed, 38 insertions, 41 deletions
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(()) |
