Skip to content

Commit

Permalink
better pathfinder debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Dec 28, 2024
1 parent 5693191 commit ebaf512
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
9 changes: 4 additions & 5 deletions azalea-physics/src/collision/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ pub fn fluid_shape(
return &BLOCK_SHAPE;
}
}
if fluid.amount > 9 {
warn!("Tried to calculate shape for fluid with height > 9: {fluid:?} at {pos}");
return &EMPTY_SHAPE;
}

// pre-calculate these in a LazyLock so this function can return a
// reference instead
Expand All @@ -375,11 +379,6 @@ pub fn fluid_shape(
]
});

if fluid.amount > 9 {
warn!("Tried to calculate shape for fluid with height > 9: {fluid:?} at {pos}");
return &EMPTY_SHAPE;
}

&FLUID_SHAPES[fluid.amount as usize]
}
fn calculate_shape_for_fluid(amount: u8) -> VoxelShape {
Expand Down
20 changes: 19 additions & 1 deletion azalea/examples/testbot/commands/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
use azalea::{
brigadier::prelude::*,
entity::{EyeHeight, Position},
pathfinder::goals::{BlockPosGoal, XZGoal},
pathfinder::goals::{BlockPosGoal, RadiusGoal, XZGoal},
prelude::*,
BlockPos, SprintDirection, WalkDirection,
};
Expand Down Expand Up @@ -42,6 +42,24 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
1
}),
)))
.then(literal("radius").then(argument("radius", float()).then(
argument("x", integer()).then(argument("y", integer()).then(
argument("z", integer()).executes(|ctx: &Ctx| {
let source = ctx.source.lock();
let radius = get_float(ctx, "radius").unwrap();
let x = get_integer(ctx, "x").unwrap();
let y = get_integer(ctx, "y").unwrap();
let z = get_integer(ctx, "z").unwrap();
println!("goto radius {radius}, position: {x} {y} {z}");
source.reply("ok");
source.bot.goto(RadiusGoal {
pos: BlockPos::new(x, y, z).center(),
radius,
});
1
}),
)),
)))
.then(argument("x", integer()).then(argument("y", integer()).then(
argument("z", integer()).executes(|ctx: &Ctx| {
let source = ctx.source.lock();
Expand Down
4 changes: 2 additions & 2 deletions azalea/src/pathfinder/goals.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The goals that a pathfinder can try to reach.
use std::f32::consts::SQRT_2;
use std::{f32::consts::SQRT_2, fmt::Debug};

use azalea_core::position::{BlockPos, Vec3};
use azalea_world::ChunkStorage;
Expand All @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};

use super::costs::{COST_HEURISTIC, FALL_N_BLOCKS_COST, JUMP_ONE_BLOCK_COST};

pub trait Goal {
pub trait Goal: Debug {
#[must_use]
fn heuristic(&self, n: BlockPos) -> f32;
#[must_use]
Expand Down
16 changes: 12 additions & 4 deletions azalea/src/pathfinder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub fn goto_listener(
let Ok((mut pathfinder, executing_path, position, instance_name, inventory)) =
query.get_mut(event.entity)
else {
warn!("got goto event for an entity that can't pathfind");
continue;
};

Expand All @@ -243,6 +244,7 @@ pub fn goto_listener(
pathfinder.goal = None;
pathfinder.successors_fn = None;
pathfinder.is_calculating = false;
debug!("already at goal, not pathfinding");
continue;
}

Expand All @@ -262,10 +264,16 @@ pub fn goto_listener(
} else {
BlockPos::from(position)
};
info!(
"got goto, starting from {start:?} (currently at {:?})",
BlockPos::from(position)
);

if start == BlockPos::from(position) {
info!("got goto {:?}, starting from {start:?}", event.goal);
} else {
info!(
"got goto {:?}, starting from {start:?} (currently at {:?})",
event.goal,
BlockPos::from(position)
);
}

let successors_fn: moves::SuccessorsFn = event.successors_fn;

Expand Down

0 comments on commit ebaf512

Please sign in to comment.