From 2eade86cf7a12a6ec64496aedbfc3d3a3bd44e1a Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 23 Oct 2022 16:51:49 -0500 Subject: make `handle` cleaner Arc -> Event, Arc> -> State Items in State now need to have interior mutability (i.e. Arc>), but it's a worthwhile tradeoff since it allows the user to customize it for each field --- azalea/examples/mine_a_chunk.rs | 43 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'azalea/examples/mine_a_chunk.rs') diff --git a/azalea/examples/mine_a_chunk.rs b/azalea/examples/mine_a_chunk.rs index bc576513..5f1dabe1 100644 --- a/azalea/examples/mine_a_chunk.rs +++ b/azalea/examples/mine_a_chunk.rs @@ -1,4 +1,4 @@ -use azalea::{pathfinder, Account, Accounts, Client, Event}; +use azalea::{pathfinder, Account, Accounts, Client, Event, Swarm}; use parking_lot::Mutex; use std::sync::Arc; @@ -7,31 +7,31 @@ async fn main() { let accounts = Accounts::new(); for i in 0..10 { - accounts.add(Account::offline(format!("bot{}", i))); + accounts.add(Account::offline(&format!("bot{}", i))); } - azalea::start_group(azalea::GroupOptions { + azalea::start_swarm(azalea::SwarmOptions { accounts, address: "localhost", - group_state: Arc::new(Mutex::new(State::default())), + swarm_state: Arc::new(Mutex::new(State::default())), state: State::default(), - group_plugins: vec![Arc::new(pathfinder::Plugin::default())], + swarm_plugins: vec![Arc::new(pathfinder::Plugin::default())], plugins: vec![], handle: Box::new(handle), - group_handle: Box::new(handle), + swarm_handle: Box::new(swarm_handle), }) .await .unwrap(); } -#[derive(Default)] +#[derive(Default, Clone)] struct State {} -#[derive(Default)] -struct GroupState {} +#[derive(Default, Clone)] +struct SwarmState {} async fn handle(bot: Client, event: Arc, state: Arc>) -> anyhow::Result<()> { match event { @@ -41,26 +41,27 @@ async fn handle(bot: Client, event: Arc, state: Arc>) -> any Ok(()) } -async fn group_handle( - bots: Swarm, +async fn swarm_handle( + swarm: Swarm, event: Arc, - state: Arc>, + state: Arc>, ) -> anyhow::Result<()> { match *event { Event::Login => { - bots.goto(azalea::BlockPos::new(0, 70, 0)).await; + swarm.goto(azalea::BlockPos::new(0, 70, 0)).await; // or bots.goto_goal(pathfinder::Goals::Goto(azalea::BlockPos(0, 70, 0))).await; // destroy the blocks in this area and then leave - bots.fill( - azalea::Selection::Range( - azalea::BlockPos::new(0, 0, 0), - azalea::BlockPos::new(16, 255, 16), - ), - azalea::block::Air, - ) - .await; + swarm + .fill( + azalea::Selection::Range( + azalea::BlockPos::new(0, 0, 0), + azalea::BlockPos::new(16, 255, 16), + ), + azalea::block::Air, + ) + .await; } _ => {} } -- cgit v1.2.3