aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples/steal.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-05-03 20:57:27 -0500
committerGitHub <noreply@github.com>2023-05-03 20:57:27 -0500
commit634cb8d72c6608512aedba19e5cd669104bc35ea (patch)
treef8e76ce9eb43403d29cc0cbcf9a4f51522419dc2 /azalea/examples/steal.rs
parent1fb4418f2c9cbd004c64c2f23d2d0352ee12c0e5 (diff)
downloadazalea-drasl-634cb8d72c6608512aedba19e5cd669104bc35ea.tar.xz
Inventory (#48)
* start adding azalea-inventory * design more of how inventories are defined * start working on az-inv-macros * inventory macro works * start adding inventory codegen * update some deps * add inventory codegen * manually write inventory menus * put the inventories in Client * start on containersetcontent * inventory menu should hopefully work * checks in containersetcontent * format a comment * move some variant matches * inventory.rs * inventory stuff * more inventory stuff * inventory/container tracking works * start adding interact function * sequence number * start adding HitResultComponent * implement traverse_blocks * start adding clip * add clip function * update_hit_result_component * start trying to fix * fix * make some stuff simpler * clippy * lever * chest * container handle * fix ambiguity * fix some doc tests * move some container stuff from az-client to azalea * clicking container * start implementing simulate_click * keep working on simulate click * implement more of simulate_click this is really boring * inventory fixes * start implementing shift clicking * fix panic in azalea-chat i hope * shift clicking implemented * more inventory stuff * fix items not showing in containers sometimes * fix test * fix all warnings * remove a println --------- Co-authored-by: mat <git@matdoes.dev>
Diffstat (limited to 'azalea/examples/steal.rs')
-rw-r--r--azalea/examples/steal.rs76
1 files changed, 76 insertions, 0 deletions
diff --git a/azalea/examples/steal.rs b/azalea/examples/steal.rs
new file mode 100644
index 00000000..3302079a
--- /dev/null
+++ b/azalea/examples/steal.rs
@@ -0,0 +1,76 @@
+//! Steal all the diamonds from all the nearby chests.
+
+use azalea::{prelude::*, BlockPos};
+use azalea_inventory::operations::QuickMoveClick;
+use azalea_inventory::ItemSlot;
+use parking_lot::Mutex;
+use std::sync::Arc;
+
+#[tokio::main]
+async fn main() {
+ let account = Account::offline("bot");
+ // or let bot = Account::microsoft("email").await;
+
+ ClientBuilder::new()
+ .set_handler(handle)
+ .start(account, "localhost")
+ .await
+ .unwrap();
+}
+
+#[derive(Default, Clone, Component)]
+struct State {
+ pub checked_chests: Arc<Mutex<Vec<BlockPos>>>,
+}
+
+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();
+ }
+
+ 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!("Done");
+ }
+ _ => {}
+ }
+
+ Ok(())
+}