aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples
diff options
context:
space:
mode:
Diffstat (limited to 'azalea/examples')
-rwxr-xr-xazalea/examples/craft_dig_straight_down.rs16
-rwxr-xr-xazalea/examples/echo.rs16
-rw-r--r--azalea/examples/matbot.rs4
-rw-r--r--azalea/examples/mine_a_chunk.rs38
-rwxr-xr-xazalea/examples/pvp.rs41
5 files changed, 42 insertions, 73 deletions
diff --git a/azalea/examples/craft_dig_straight_down.rs b/azalea/examples/craft_dig_straight_down.rs
index 76979406..0632776e 100755
--- a/azalea/examples/craft_dig_straight_down.rs
+++ b/azalea/examples/craft_dig_straight_down.rs
@@ -3,7 +3,7 @@ use azalea::prelude::*;
use parking_lot::Mutex;
use std::sync::Arc;
-#[derive(Default, Clone)]
+#[derive(Default, Clone, Component)]
struct State {
pub started: Arc<Mutex<bool>>,
}
@@ -13,15 +13,11 @@ async fn main() {
let account = Account::offline("bot");
// or let bot = Account::microsoft("email").await;
- azalea::start(azalea::Options {
- account,
- address: "localhost",
- state: State::default(),
- plugins: plugins![],
- handle,
- })
- .await
- .unwrap();
+ azalea::ClientBuilder::new()
+ .set_handler(handle)
+ .start(account, "localhost")
+ .await
+ .unwrap();
}
async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
diff --git a/azalea/examples/echo.rs b/azalea/examples/echo.rs
index f9bafebd..292e12cd 100755
--- a/azalea/examples/echo.rs
+++ b/azalea/examples/echo.rs
@@ -7,15 +7,11 @@ async fn main() {
let account = Account::offline("bot");
// or let account = Account::microsoft("email").await;
- azalea::start(azalea::Options {
- account,
- address: "localhost",
- state: State::default(),
- plugins: plugins![],
- handle,
- })
- .await
- .unwrap();
+ ClientBuilder::new()
+ .set_handler(handle)
+ .start(account, "localhost")
+ .await
+ .unwrap();
}
#[derive(Default, Clone, Component)]
@@ -28,7 +24,7 @@ async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()>
if sender == bot.profile.name {
return Ok(()); // ignore our own messages
}
- bot.chat(&content).await?;
+ bot.chat(&content);
};
}
_ => {}
diff --git a/azalea/examples/matbot.rs b/azalea/examples/matbot.rs
index 17736eab..1ddd9197 100644
--- a/azalea/examples/matbot.rs
+++ b/azalea/examples/matbot.rs
@@ -14,7 +14,7 @@ use std::time::Duration;
#[derive(Default, Clone, Component)]
struct State {}
-#[derive(Default, Clone, Component)]
+#[derive(Default, Clone, Resource)]
struct SwarmState {}
#[tokio::main]
@@ -54,7 +54,7 @@ async fn main() -> anyhow::Result<()> {
}
loop {
- let e = azalea::SwarmBuilder::new()
+ let e = SwarmBuilder::new()
.add_accounts(accounts.clone())
.set_handler(handle)
.set_swarm_handler(swarm_handle)
diff --git a/azalea/examples/mine_a_chunk.rs b/azalea/examples/mine_a_chunk.rs
index 72d27ff3..bc4e4fdd 100644
--- a/azalea/examples/mine_a_chunk.rs
+++ b/azalea/examples/mine_a_chunk.rs
@@ -1,5 +1,4 @@
-use azalea::{prelude::*, SwarmEvent};
-use azalea::{Account, Client, Event, Swarm};
+use azalea::prelude::*;
#[tokio::main]
async fn main() {
@@ -7,44 +6,29 @@ async fn main() {
let mut states = Vec::new();
for i in 0..10 {
- accounts.push(Account::offline(&format!("bot{o}")));
+ accounts.push(Account::offline(&format!("bot{i}")));
states.push(State::default());
}
- azalea::start_swarm(azalea::SwarmOptions {
- accounts,
- address: "localhost",
-
- swarm_state: SwarmState::default(),
- states,
-
- swarm_plugins: plugins![],
- plugins: plugins![],
-
- handle,
- swarm_handle,
-
- join_delay: None,
- })
- .await
- .unwrap();
+ let e = azalea::SwarmBuilder::new()
+ .add_accounts(accounts.clone())
+ .set_handler(handle)
+ .set_swarm_handler(swarm_handle)
+ .start("localhost")
+ .await;
}
-#[derive(Default, Clone)]
+#[derive(Default, Clone, Component)]
struct State {}
-#[derive(Default, Clone)]
+#[derive(Default, Clone, Resource)]
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::Login => {
swarm.goto(azalea::BlockPos::new(0, 70, 0)).await;
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());