aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-01-05 17:47:46 +0500
committermat <git@matdoes.dev>2026-01-05 17:47:46 +0500
commit8c9b3c98cb6afd7484cc44c35965e6d2436e6d37 (patch)
tree68f5a0f6d84bbd3a255ac654ee38da987fcd90ea /azalea/examples
parentdb9a9e53ca18911fb2045b7d6af4ed6df388eaaa (diff)
downloadazalea-drasl-8c9b3c98cb6afd7484cc44c35965e6d2436e6d37.tar.xz
pathfinder swimming
Diffstat (limited to 'azalea/examples')
-rw-r--r--azalea/examples/testbot/commands.rs2
-rw-r--r--azalea/examples/testbot/commands/debug.rs47
-rw-r--r--azalea/examples/testbot/commands/movement.rs4
3 files changed, 46 insertions, 7 deletions
diff --git a/azalea/examples/testbot/commands.rs b/azalea/examples/testbot/commands.rs
index beb87510..930f41ca 100644
--- a/azalea/examples/testbot/commands.rs
+++ b/azalea/examples/testbot/commands.rs
@@ -30,7 +30,7 @@ impl CommandSource {
}
}
- pub fn entity(&mut self) -> Option<azalea::EntityRef> {
+ pub fn entity(&self) -> Option<azalea::EntityRef> {
let username = self.chat.sender()?;
self.bot
.any_entity_by::<&GameProfileComponent, With<Player>>(
diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs
index 36c699a4..1f9d5e5d 100644
--- a/azalea/examples/testbot/commands/debug.rs
+++ b/azalea/examples/testbot/commands/debug.rs
@@ -7,7 +7,10 @@ use azalea::{
brigadier::prelude::*,
chunks::ReceiveChunkEvent,
packet::game,
- pathfinder::{ExecutingPath, Pathfinder},
+ pathfinder::{
+ ExecutingPath, Pathfinder, custom_state::CustomPathfinderStateRef, mining::MiningCache,
+ moves::PathfinderCtx, rel_block_pos::RelBlockPos, world::CachedWorld,
+ },
};
use azalea_core::hit_result::HitResult;
use azalea_entity::{EntityKindComponent, metadata};
@@ -33,7 +36,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
}));
commands.register(literal("whereami").executes(|ctx: &Ctx| {
- let mut source = ctx.source.lock();
+ let source = ctx.source.lock();
let Some(entity) = source.entity() else {
source.reply("You aren't in render distance!");
return 0;
@@ -47,7 +50,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
}));
commands.register(literal("entityid").executes(|ctx: &Ctx| {
- let mut source = ctx.source.lock();
+ let source = ctx.source.lock();
let Some(entity) = source.entity() else {
source.reply("You aren't in render distance!");
return 0;
@@ -160,7 +163,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
let source = ctx.source.lock();
let pathfinder = source.bot.get_component::<Pathfinder>();
let Some(pathfinder) = pathfinder else {
- source.reply("I don't have the Pathfinder ocmponent");
+ source.reply("I don't have the Pathfinder component");
return 1;
};
source.reply(format!(
@@ -185,6 +188,42 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
));
1
}));
+ commands.register(literal("pathfindermoves").executes(|ctx: &Ctx| {
+ let source = ctx.source.lock();
+
+ let Some(entity) = source.entity() else {
+ source.reply("You aren't in render distance!");
+ return 0;
+ };
+ let position = entity.position();
+ let position = BlockPos::from(position);
+
+ let mut edges = Vec::new();
+ let cached_world = CachedWorld::new(source.bot.world(), position);
+ let mining_cache = MiningCache::new(None);
+ let custom_state = CustomPathfinderStateRef::default();
+
+ azalea::pathfinder::moves::default_move(
+ &mut PathfinderCtx {
+ edges: &mut edges,
+ world: &cached_world,
+ mining_cache: &mining_cache,
+ custom_state: &custom_state,
+ },
+ RelBlockPos::from_origin(position, position),
+ );
+
+ if edges.is_empty() {
+ source.reply("No possible moves.");
+ } else {
+ source.reply("Moves:");
+ for (i, edge) in edges.iter().enumerate() {
+ source.reply(format!("{}) {edge:?}", i + 1));
+ }
+ }
+
+ 1
+ }));
commands.register(literal("startuseitem").executes(|ctx: &Ctx| {
let source = ctx.source.lock();
diff --git a/azalea/examples/testbot/commands/movement.rs b/azalea/examples/testbot/commands/movement.rs
index c1af4143..209a1c80 100644
--- a/azalea/examples/testbot/commands/movement.rs
+++ b/azalea/examples/testbot/commands/movement.rs
@@ -15,7 +15,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
commands.register(
literal("goto")
.executes(|ctx: &Ctx| {
- let mut source = ctx.source.lock();
+ let source = ctx.source.lock();
println!("got goto");
// look for the sender
let Some(entity) = source.entity() else {
@@ -88,7 +88,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
literal("look")
.executes(|ctx: &Ctx| {
// look for the sender
- let mut source = ctx.source.lock();
+ let source = ctx.source.lock();
let Some(entity) = source.entity() else {
source.reply("I can't see you!");
return 0;