aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples/pvp.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-11-27 17:51:50 -0600
committermat <github@matdoes.dev>2022-11-27 17:51:50 -0600
commit36a11220106c052864235eebf144d4f15531dcb3 (patch)
treef0898f3974ec0b56fe5953c8b79fd22cedc67ffe /azalea/examples/pvp.rs
parent1a2178959d94232e96346a64785e8d8a639ab2b1 (diff)
downloadazalea-drasl-36a11220106c052864235eebf144d4f15531dcb3.tar.xz
fix some docs/examples
Diffstat (limited to 'azalea/examples/pvp.rs')
-rwxr-xr-xazalea/examples/pvp.rs45
1 files changed, 31 insertions, 14 deletions
diff --git a/azalea/examples/pvp.rs b/azalea/examples/pvp.rs
index 157ad9e2..711806de 100755
--- a/azalea/examples/pvp.rs
+++ b/azalea/examples/pvp.rs
@@ -1,25 +1,30 @@
-use azalea::{pathfinder, Account, Client, Event};
+use azalea::{pathfinder, Account, Client, Event, SwarmEvent};
+use azalea::{prelude::*, Swarm};
#[tokio::main]
async fn main() {
- let accounts = Vec::new();
+ let mut accounts = Vec::new();
+ let mut states = Vec::new();
for i in 0..10 {
accounts.push(Account::offline(&format!("bot{}", i)));
+ states.push(State::default());
}
azalea::start_swarm(azalea::SwarmOptions {
accounts,
address: "localhost",
- swarm_state: State::default(),
- state: State::default(),
+ swarm_state: SwarmState::default(),
+ states,
- swarm_plugins: plugins![pathfinder::Plugin],
+ swarm_plugins: swarm_plugins![pathfinder::Plugin],
plugins: plugins![],
- handle: Box::new(handle),
- swarm_handle: Box::new(swarm_handle),
+ handle,
+ swarm_handle,
+
+ join_delay: None,
})
.await
.unwrap();
@@ -31,19 +36,29 @@ struct State {}
#[derive(Default, Clone)]
struct SwarmState {}
-async fn handle(bot: Client, event: Event, state: State) {}
-async fn swarm_handle<S>(swarm: Swarm<S>, event: Event, state: State) {
+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<()> {
match event {
- Event::Tick => {
+ SwarmEvent::Tick => {
// choose an arbitrary player within render distance to target
- if let Some(target) = swarm.world.find_one_entity(|e| e.id == "minecraft:player") {
- for bot in swarm {
+ if let Some(target) = swarm
+ .worlds
+ .read()
+ .find_one_entity(|e| e.id == "minecraft:player")
+ {
+ for (bot, bot_state) in swarm {
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) {
+ if bot.entity().can_reach(target.bounding_box) {
bot.swing();
}
- if !bot.using_held_item() && bot.state.lock().hunger <= 17 {
+ if !bot.using_held_item() && bot.hunger() <= 17 {
bot.hold(azalea::ItemGroup::Food);
tokio::task::spawn(bot.use_held_item());
}
@@ -52,4 +67,6 @@ async fn swarm_handle<S>(swarm: Swarm<S>, event: Event, state: State) {
}
_ => {}
}
+
+ Ok(())
}