diff options
| author | Ubuntu <github@matdoes.dev> | 2023-02-06 19:15:41 +0000 |
|---|---|---|
| committer | Ubuntu <github@matdoes.dev> | 2023-02-06 19:15:41 +0000 |
| commit | d51b2a29b2911e4be480727e56553fa27cfbfce0 (patch) | |
| tree | 880eb62b3e90337cb29d51a30852bce07416bfd8 /azalea/examples/pvp.rs | |
| parent | cbcf1d5e54caefb50ec6340aaf1e8a94312a38c8 (diff) | |
| download | azalea-drasl-d51b2a29b2911e4be480727e56553fa27cfbfce0.tar.xz | |
fix some swarm examples/docs
Diffstat (limited to 'azalea/examples/pvp.rs')
| -rwxr-xr-x | azalea/examples/pvp.rs | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/azalea/examples/pvp.rs b/azalea/examples/pvp.rs index 28e54f35..be818024 100755 --- a/azalea/examples/pvp.rs +++ b/azalea/examples/pvp.rs @@ -1,5 +1,9 @@ -use azalea::{pathfinder, Account, Client, Event, SwarmEvent}; +use std::time::Duration; + +use azalea::entity::metadata::Player; +use azalea::{pathfinder, Account, Client, Event, GameProfileComponent, SwarmEvent}; use azalea::{prelude::*, Swarm}; +use azalea_ecs::query::With; #[tokio::main] async fn main() { @@ -11,23 +15,14 @@ async fn main() { states.push(State::default()); } - azalea::start_swarm(azalea::SwarmOptions { - accounts, - address: "localhost", - - swarm_state: SwarmState::default(), - states, - - swarm_plugins: swarm_plugins![pathfinder::Plugin], - plugins: plugins![], - - handle, - swarm_handle, - - join_delay: None, - }) - .await - .unwrap(); + SwarmBuilder::new() + .add_accounts(accounts.clone()) + .set_handler(handle) + .set_swarm_handler(swarm_handle) + .join_delay(Duration::from_millis(1000)) + .start("localhost") + .await + .unwrap(); } #[derive(Default, Clone)] @@ -39,15 +34,13 @@ struct SwarmState {} async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { Ok(()) } -async fn swarm_handle( - swarm: Swarm<State>, - event: SwarmEvent, - state: SwarmState, -) -> anyhow::Result<()> { +async fn swarm_handle(swarm: Swarm, event: SwarmEvent, state: SwarmState) -> anyhow::Result<()> { match event { SwarmEvent::Tick => { if let Some(target_entity) = - swarm.entity_by::<Player>(|name: &Name| name == "Herobrine") + swarm.entity_by::<With<Player>>(|profile: &&GameProfileComponent| { + profile.name == "Herobrine" + }) { let target_bounding_box = swarm.map_entity(target_entity, |bb: &BoundingBox| bb.clone()); |
