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/pvp.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/pvp.rs')
| -rw-r--r-- | azalea/examples/pvp.rs | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/azalea/examples/pvp.rs b/azalea/examples/pvp.rs index 5febdd45..9405cb6f 100644 --- a/azalea/examples/pvp.rs +++ b/azalea/examples/pvp.rs @@ -1,22 +1,46 @@ -use azalea::{Account, Accounts, Event, pathfinder}; +use std::sync::Arc; + +use azalea::{pathfinder, Account, Accounts, Client, Event}; +use parking_lot::Mutex; #[tokio::main] async fn main() { let accounts = Accounts::new(); + for i in 0..10 { accounts.add(Account::offline(format!("bot{}", i))); } - let bots = accounts.join("localhost".try_into().unwrap()).await.unwrap(); + azalea::start_swarm(azalea::SwarmOptions { + accounts, + address: "localhost", + + swarm_state: Arc::new(Mutex::new(State::default())), + state: State::default(), + + swarm_plugins: vec![Arc::new(pathfinder::Plugin::default())], + plugins: vec![], + + handle: Box::new(handle), + swarm_handle: Box::new(handle), + }) + .await + .unwrap(); +} + +struct State {} +struct SwarmState {} - match bots.next().await { - Event::Tick { +async fn handle(bots: Client, event: Arc<Event>, state: Arc<Mutex<State>>) { + match *event { + Event::Tick => { // choose an arbitrary player within render distance to target - if let Some(target) = bots.world.find_one_entity(|e| e.id == "minecraft:player") { + if let Some(target) = bots + .dimension() + .find_one_entity(|e| e.id == "minecraft:player") + { for bot in bots { - bot.tick_goto_goal( - pathfinder::Goals::Reach(target.bounding_box) - ); + bot.tick_goto_goal(pathfinder::Goals::Reach(target.bounding_box)); // if target.bounding_box.distance(bot.eyes) < bot.reach_distance() { if bot.entity.can_reach(target.bounding_box) { bot.swing(); @@ -27,7 +51,7 @@ async fn main() { } } } - }, + } _ => {} } } |
