aboutsummaryrefslogtreecommitdiff
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
parent1a2178959d94232e96346a64785e8d8a639ab2b1 (diff)
downloadazalea-drasl-36a11220106c052864235eebf144d4f15531dcb3.tar.xz
fix some docs/examples
-rwxr-xr-xazalea/examples/craft_dig_straight_down.rs6
-rwxr-xr-xazalea/examples/echo.rs4
-rw-r--r--azalea/examples/mine_a_chunk.rs6
-rwxr-xr-xazalea/examples/pvp.rs45
-rw-r--r--azalea/src/lib.rs4
5 files changed, 40 insertions, 25 deletions
diff --git a/azalea/examples/craft_dig_straight_down.rs b/azalea/examples/craft_dig_straight_down.rs
index 3e6d9e31..864b9809 100755
--- a/azalea/examples/craft_dig_straight_down.rs
+++ b/azalea/examples/craft_dig_straight_down.rs
@@ -27,7 +27,7 @@ async fn main() {
async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
match event {
Event::Chat(m) => {
- if m.username() == Some(bot.game_profile.name) {
+ if m.username() == Some(bot.profile.name) {
return Ok(());
};
if m.content() == "go" {
@@ -42,7 +42,7 @@ async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
bot.goto(pathfinder::Goals::NearXZ(5, azalea::BlockXZ(0, 0)))
.await;
let chest = bot
- .open_container(&bot.world.find_one_block(|b| b.id == "minecraft:chest"))
+ .open_container(&bot.world().find_one_block(|b| b.id == "minecraft:chest"))
.await
.unwrap();
bot.take_amount(&chest, 5, |i| i.id == "#minecraft:planks")
@@ -65,7 +65,7 @@ async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
bot.hold(&pickaxe);
loop {
- if let Err(e) = bot.dig(bot.entity.feet_pos().down(1)).await {
+ if let Err(e) = bot.dig(bot.entity().feet_pos().down(1)).await {
println!("{:?}", e);
break;
}
diff --git a/azalea/examples/echo.rs b/azalea/examples/echo.rs
index 5f6cf072..2093ff4e 100755
--- a/azalea/examples/echo.rs
+++ b/azalea/examples/echo.rs
@@ -21,11 +21,11 @@ async fn main() {
#[derive(Default, Clone)]
pub struct State {}
-async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
+async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
match event {
Event::Chat(m) => {
if let (Some(sender), content) = m.split_sender_and_content() {
- if sender == bot.game_profile.name {
+ if sender == bot.profile.name {
return Ok(()); // ignore our own messages
}
bot.chat(&content).await?;
diff --git a/azalea/examples/mine_a_chunk.rs b/azalea/examples/mine_a_chunk.rs
index f9b208a2..b48fb99c 100644
--- a/azalea/examples/mine_a_chunk.rs
+++ b/azalea/examples/mine_a_chunk.rs
@@ -1,7 +1,5 @@
use azalea::{prelude::*, SwarmEvent};
use azalea::{Account, Client, Event, Swarm};
-use parking_lot::Mutex;
-use std::sync::Arc;
#[tokio::main]
async fn main() {
@@ -10,14 +8,14 @@ async fn main() {
for i in 0..10 {
accounts.push(Account::offline(&format!("bot{}", i)));
- states.push(Arc::new(Mutex::new(State::default())));
+ states.push(State::default());
}
azalea::start_swarm(azalea::SwarmOptions {
accounts,
address: "localhost",
- swarm_state: State::default(),
+ swarm_state: SwarmState::default(),
states,
swarm_plugins: plugins![],
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(())
}
diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs
index 7c9c660b..05d92f33 100644
--- a/azalea/src/lib.rs
+++ b/azalea/src/lib.rs
@@ -15,7 +15,7 @@
//! Latest bleeding-edge version:
//! `azalea = { git="https://github.com/mat-1/Cargo.toml" }`\
//! Latest "stable" release:
-//! `azalea = "0.3"`
+//! `azalea = "0.6"`
//!
//! ## Optimization
//!
@@ -28,7 +28,7 @@
//! ```toml
//! [profile.dev]
//! opt-level = 1
-//! [profile.dev.package."*""]
+//! [profile.dev.package."*"]
//! opt-level = 3
//! ```
//! to your Cargo.toml. You may have to install the LLD linker.