diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-10-07 19:57:42 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-07 19:57:42 -0500 |
| commit | ba4cfaafaec97a3c5b9405fe542035ebe9039edd (patch) | |
| tree | 5fc7340a49f96d84f86ed6adf400ad461c47d1b6 /azalea/examples/mine_a_chunk.rs | |
| parent | e0bcab53b8a3721a008e47062c6b5972fa64b8ad (diff) | |
| download | azalea-drasl-ba4cfaafaec97a3c5b9405fe542035ebe9039edd.tar.xz | |
Bot API (#27)
Basically make the `azalea` crate have stuff
Diffstat (limited to 'azalea/examples/mine_a_chunk.rs')
| -rw-r--r-- | azalea/examples/mine_a_chunk.rs | 70 |
1 files changed, 56 insertions, 14 deletions
diff --git a/azalea/examples/mine_a_chunk.rs b/azalea/examples/mine_a_chunk.rs index 6549f2b2..bc576513 100644 --- a/azalea/examples/mine_a_chunk.rs +++ b/azalea/examples/mine_a_chunk.rs @@ -1,6 +1,6 @@ -use azalea::{Account, Accounts, Event, pathfinder}; - -// You can use the `azalea::Bots` struct to control many bots as one unit. +use azalea::{pathfinder, Account, Accounts, Client, Event}; +use parking_lot::Mutex; +use std::sync::Arc; #[tokio::main] async fn main() { @@ -10,18 +10,60 @@ async fn main() { accounts.add(Account::offline(format!("bot{}", i))); } - let bots = accounts.join("localhost".try_into().unwrap()).await.unwrap(); + azalea::start_group(azalea::GroupOptions { + accounts, + address: "localhost", + + group_state: Arc::new(Mutex::new(State::default())), + state: State::default(), - bots.goto(azalea::BlockPos::new(0, 70, 0)).await; - // or bots.goto_goal(pathfinder::Goals::Goto(azalea::BlockPos(0, 70, 0))).await; + group_plugins: vec![Arc::new(pathfinder::Plugin::default())], + plugins: vec![], + + handle: Box::new(handle), + group_handle: Box::new(handle), + }) + .await + .unwrap(); +} - // destroy the blocks in this area and then leave +#[derive(Default)] +struct State {} + +#[derive(Default)] +struct GroupState {} + +async fn handle(bot: Client, event: Arc<Event>, state: Arc<Mutex<State>>) -> anyhow::Result<()> { + match event { + _ => {} + } + + Ok(()) +} + +async fn group_handle( + bots: Swarm, + event: Arc<Event>, + state: Arc<Mutex<GroupState>>, +) -> anyhow::Result<()> { + match *event { + Event::Login => { + bots.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; + } + _ => {} + } - bots.fill( - azalea::Selection::Range( - azalea::BlockPos::new(0, 0, 0), - azalea::BlockPos::new(16, 255, 16) - ), - azalea::block::Air - ).await; + Ok(()) } |
