aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples/testbot
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-03-27 13:49:18 -0600
committermat <git@matdoes.dev>2026-03-28 01:49:34 +0600
commit2d3e4194b885ec499826812da52c965f5a7235cf (patch)
tree9cffc73bb9c5ffa29591392f060816b2c9f321a6 /azalea/examples/testbot
parenteeaf1435e81d9cbd8daa0efa22029c1f259a64b5 (diff)
downloadazalea-drasl-2d3e4194b885ec499826812da52c965f5a7235cf.tar.xz
instant path updates for simple paths, and add follow command to testbot
Diffstat (limited to 'azalea/examples/testbot')
-rw-r--r--azalea/examples/testbot/commands/movement.rs18
-rw-r--r--azalea/examples/testbot/main.rs36
2 files changed, 38 insertions, 16 deletions
diff --git a/azalea/examples/testbot/commands/movement.rs b/azalea/examples/testbot/commands/movement.rs
index 3f015f2c..500e17b0 100644
--- a/azalea/examples/testbot/commands/movement.rs
+++ b/azalea/examples/testbot/commands/movement.rs
@@ -9,7 +9,6 @@ use azalea::{
use parking_lot::Mutex;
use super::{CommandSource, Ctx};
-use crate::BotTask;
pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
commands.register(
@@ -72,6 +71,19 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
))),
);
+ commands.register(literal("follow").executes(|ctx: &Ctx| {
+ let source = ctx.source.lock();
+ println!("got follow");
+ // look for the sender
+ let Some(entity) = source.entity() else {
+ source.reply("I can't see you!");
+ return 0;
+ };
+ source.reply("ok");
+ *source.state.following_entity.lock() = Some(entity);
+ 1
+ }));
+
commands.register(literal("down").executes(|ctx: &Ctx| {
let source = ctx.source.clone();
tokio::spawn(async move {
@@ -207,14 +219,14 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
let source = ctx.source.lock();
source.bot.stop_pathfinding();
source.reply("ok");
- *source.state.task.lock() = BotTask::None;
+ *source.state.following_entity.lock() = None;
1
}));
commands.register(literal("forcestop").executes(|ctx: &Ctx| {
let source = ctx.source.lock();
source.bot.force_stop_pathfinding();
source.reply("ok");
- *source.state.task.lock() = BotTask::None;
+ *source.state.following_entity.lock() = None;
1
}));
}
diff --git a/azalea/examples/testbot/main.rs b/azalea/examples/testbot/main.rs
index 57bdcc72..173f2b8c 100644
--- a/azalea/examples/testbot/main.rs
+++ b/azalea/examples/testbot/main.rs
@@ -29,11 +29,14 @@ pub mod mspt;
use std::{env, process, sync::Arc, thread, time::Duration};
use azalea::{
- ClientInformation,
+ ClientInformation, EntityRef,
brigadier::command_dispatcher::CommandDispatcher,
ecs::prelude::*,
pathfinder::{
- debug::PathfinderDebugParticles, execute::simulation::SimulationPathfinderExecutionPlugin,
+ PathfinderOpts,
+ debug::PathfinderDebugParticles,
+ execute::simulation::SimulationPathfinderExecutionPlugin,
+ goals::{Goal, RadiusGoal},
},
prelude::*,
swarm::prelude::*,
@@ -105,23 +108,17 @@ fn deadlock_detection_thread() {
}
}
-#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
-pub enum BotTask {
- #[default]
- None,
-}
-
#[derive(Clone, Component, Default)]
pub struct State {
pub killaura: bool,
- pub task: Arc<Mutex<BotTask>>,
+ pub following_entity: Arc<Mutex<Option<EntityRef>>>,
}
impl State {
fn new() -> Self {
Self {
killaura: false,
- task: Arc::new(Mutex::new(BotTask::None)),
+ following_entity: Default::default(),
}
}
}
@@ -188,9 +185,22 @@ async fn handle(bot: Client, event: azalea::Event, state: State) -> eyre::Result
azalea::Event::Tick => {
killaura::tick(bot.clone(), state.clone())?;
- let task = *state.task.lock();
- match task {
- BotTask::None => {}
+ if bot.ticks_connected().is_multiple_of(5) {
+ if let Some(following) = &*state.following_entity.lock() {
+ let goal = RadiusGoal::new(following.position(), 3.);
+ if bot.is_calculating_path() {
+ // keep waiting
+ } else if !goal.success(bot.position().into()) || bot.is_executing_path() {
+ bot.start_goto_with_opts(
+ goal,
+ PathfinderOpts::new()
+ .retry_on_no_path(false)
+ .max_timeout(Duration::from_secs(1)),
+ );
+ } else {
+ following.look_at();
+ }
+ }
}
}
azalea::Event::Login => {