aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples
diff options
context:
space:
mode:
Diffstat (limited to 'azalea/examples')
-rw-r--r--[-rwxr-xr-x]azalea/examples/mine_a_chunk.rs29
-rwxr-xr-xazalea/examples/potatobot/autoeat.rs2
-rwxr-xr-xazalea/examples/potatobot/main.rs2
-rwxr-xr-xazalea/examples/pvp.rs4
4 files changed, 23 insertions, 14 deletions
diff --git a/azalea/examples/mine_a_chunk.rs b/azalea/examples/mine_a_chunk.rs
index 2e30b2c5..f9b208a2 100755..100644
--- a/azalea/examples/mine_a_chunk.rs
+++ b/azalea/examples/mine_a_chunk.rs
@@ -1,13 +1,16 @@
-use azalea::{Account, Accounts, Client, Event, Swarm};
+use azalea::{prelude::*, SwarmEvent};
+use azalea::{Account, Client, Event, Swarm};
use parking_lot::Mutex;
use std::sync::Arc;
#[tokio::main]
async fn main() {
- let accounts = Accounts::new();
+ let mut accounts = Vec::new();
+ let mut states = Vec::new();
for i in 0..10 {
- accounts.add(Account::offline(&format!("bot{}", i)));
+ accounts.push(Account::offline(&format!("bot{}", i)));
+ states.push(Arc::new(Mutex::new(State::default())));
}
azalea::start_swarm(azalea::SwarmOptions {
@@ -15,13 +18,15 @@ async fn main() {
address: "localhost",
swarm_state: State::default(),
- state: State::default(),
+ states,
- swarm_plugins: plugins![azalea_pathfinder::Plugin::default()],
+ swarm_plugins: plugins![],
plugins: plugins![],
- handle: Box::new(handle),
- swarm_handle: Box::new(swarm_handle),
+ handle,
+ swarm_handle,
+
+ join_delay: None,
})
.await
.unwrap();
@@ -37,9 +42,13 @@ async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
Ok(())
}
-async fn swarm_handle(swarm: Swarm, event: Event, state: SwarmState) -> anyhow::Result<()> {
- match event {
- Event::Login => {
+async fn swarm_handle(
+ swarm: Swarm<State>,
+ event: SwarmEvent,
+ state: SwarmState,
+) -> anyhow::Result<()> {
+ match &event {
+ SwarmEvent::Login => {
swarm.goto(azalea::BlockPos::new(0, 70, 0)).await;
// or bots.goto_goal(pathfinder::Goals::Goto(azalea::BlockPos(0, 70, 0))).await;
diff --git a/azalea/examples/potatobot/autoeat.rs b/azalea/examples/potatobot/autoeat.rs
index 0f0ccc6d..89934fa2 100755
--- a/azalea/examples/potatobot/autoeat.rs
+++ b/azalea/examples/potatobot/autoeat.rs
@@ -14,7 +14,7 @@ pub struct Plugin {
pub struct State {}
#[async_trait]
-impl azalea::Plugin for Plugin {
+impl azalea::PluginState for Plugin {
async fn handle(self: Box<Self>, event: Event, bot: Client) {
match event {
Event::UpdateHunger => {
diff --git a/azalea/examples/potatobot/main.rs b/azalea/examples/potatobot/main.rs
index e585c41d..8d40c48e 100755
--- a/azalea/examples/potatobot/main.rs
+++ b/azalea/examples/potatobot/main.rs
@@ -15,7 +15,7 @@ async fn main() {
account,
address: "localhost",
state: State::default(),
- plugins: plugins![autoeat::Plugin::default(), pathfinder::Plugin::default(),],
+ plugins: plugins![autoeat::Plugin, pathfinder::Plugin],
handle,
})
.await
diff --git a/azalea/examples/pvp.rs b/azalea/examples/pvp.rs
index 87d83c6d..157ad9e2 100755
--- a/azalea/examples/pvp.rs
+++ b/azalea/examples/pvp.rs
@@ -15,7 +15,7 @@ async fn main() {
swarm_state: State::default(),
state: State::default(),
- swarm_plugins: plugins![pathfinder::Plugin::default()],
+ swarm_plugins: plugins![pathfinder::Plugin],
plugins: plugins![],
handle: Box::new(handle),
@@ -32,7 +32,7 @@ struct State {}
struct SwarmState {}
async fn handle(bot: Client, event: Event, state: State) {}
-async fn swarm_handle(swarm: Swarm, event: Event, state: State) {
+async fn swarm_handle<S>(swarm: Swarm<S>, event: Event, state: State) {
match event {
Event::Tick => {
// choose an arbitrary player within render distance to target