aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-10-23 16:57:28 -0500
committermat <github@matdoes.dev>2022-10-23 16:57:28 -0500
commitc9b1b19ff235975a80191d512392460c0eabfad4 (patch)
treef2271c73b01fec675b523fb79da5b1ae83300091 /azalea/examples
parent2eade86cf7a12a6ec64496aedbfc3d3a3bd44e1a (diff)
downloadazalea-drasl-c9b1b19ff235975a80191d512392460c0eabfad4.tar.xz
Update examples with new cleaner handle/state
Diffstat (limited to 'azalea/examples')
-rw-r--r--azalea/examples/mine_a_chunk.rs16
-rw-r--r--azalea/examples/potatobot/main.rs4
-rw-r--r--azalea/examples/pvp.rs14
3 files changed, 11 insertions, 23 deletions
diff --git a/azalea/examples/mine_a_chunk.rs b/azalea/examples/mine_a_chunk.rs
index 5f1dabe1..3bb712fa 100644
--- a/azalea/examples/mine_a_chunk.rs
+++ b/azalea/examples/mine_a_chunk.rs
@@ -14,7 +14,7 @@ async fn main() {
accounts,
address: "localhost",
- swarm_state: Arc::new(Mutex::new(State::default())),
+ swarm_state: State::default(),
state: State::default(),
swarm_plugins: vec![Arc::new(pathfinder::Plugin::default())],
@@ -33,20 +33,12 @@ struct State {}
#[derive(Default, Clone)]
struct SwarmState {}
-async fn handle(bot: Client, event: Arc<Event>, state: Arc<Mutex<State>>) -> anyhow::Result<()> {
- match event {
- _ => {}
- }
-
+async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
Ok(())
}
-async fn swarm_handle(
- swarm: Swarm,
- event: Arc<Event>,
- state: Arc<Mutex<SwarmState>>,
-) -> anyhow::Result<()> {
- match *event {
+async fn swarm_handle(swarm: Swarm, event: Event, state: SwarmState) -> anyhow::Result<()> {
+ match event {
Event::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/main.rs b/azalea/examples/potatobot/main.rs
index 5398c68a..1aa28ecc 100644
--- a/azalea/examples/potatobot/main.rs
+++ b/azalea/examples/potatobot/main.rs
@@ -2,10 +2,8 @@ mod autoeat;
use azalea::prelude::*;
use azalea::{pathfinder, Account, BlockPos, Client, Event, ItemKind, MoveDirection, Plugin, Vec3};
-use parking_lot::Mutex;
-use std::sync::Arc;
-#[derive(Default)]
+#[derive(Default, Clone)]
struct State {}
#[tokio::main]
diff --git a/azalea/examples/pvp.rs b/azalea/examples/pvp.rs
index 8c133576..ec2a08f0 100644
--- a/azalea/examples/pvp.rs
+++ b/azalea/examples/pvp.rs
@@ -1,23 +1,21 @@
-use azalea::{pathfinder, Account, Accounts, Client, Event};
-use parking_lot::Mutex;
-use std::sync::Arc;
+use azalea::{pathfinder, Account, Client, Event};
#[tokio::main]
async fn main() {
- let accounts = Accounts::new();
+ let accounts = Vec::new();
for i in 0..10 {
- accounts.add(Account::offline(&format!("bot{}", i)));
+ accounts.push(Account::offline(&format!("bot{}", i)));
}
azalea::start_swarm(azalea::SwarmOptions {
accounts,
address: "localhost",
- swarm_state: Arc::new(Mutex::new(State::default())),
+ swarm_state: State::default(),
state: State::default(),
- swarm_plugins: vec![Arc::new(pathfinder::Plugin::default())],
+ swarm_plugins: vec![Box::new(pathfinder::Plugin::default())],
plugins: vec![],
handle: Box::new(handle),
@@ -48,7 +46,7 @@ async fn swarm_handle(swarm: Swarm, event: Event, state: State) {
if bot.entity.can_reach(target.bounding_box) {
bot.swing();
}
- if !h.using_held_item() && bot.state.lock().hunger <= 17 {
+ if !bot.using_held_item() && bot.state.lock().hunger <= 17 {
bot.hold(azalea::ItemGroup::Food);
tokio::task::spawn(bot.use_held_item());
}