aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/pathfinder
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-09-30 12:38:09 -0500
committermat <git@matdoes.dev>2023-09-30 12:38:09 -0500
commit3f62ff11134f66f197b76ccbbcb6d667436914df (patch)
tree2da6dff2f09eb3e90133e26999d44682ecf2262d /azalea/src/pathfinder
parent4b9499a123d3d0160f76e74278210efbc53dd3bc (diff)
downloadazalea-drasl-3f62ff11134f66f197b76ccbbcb6d667436914df.tar.xz
remove BlockPosGoal::from and Goal::goal_node
Diffstat (limited to 'azalea/src/pathfinder')
-rw-r--r--azalea/src/pathfinder/goals.rs21
-rw-r--r--azalea/src/pathfinder/mod.rs10
2 files changed, 8 insertions, 23 deletions
diff --git a/azalea/src/pathfinder/goals.rs b/azalea/src/pathfinder/goals.rs
index a76e0314..9818c80d 100644
--- a/azalea/src/pathfinder/goals.rs
+++ b/azalea/src/pathfinder/goals.rs
@@ -2,26 +2,15 @@ use azalea_core::BlockPos;
use super::Goal;
-pub struct BlockPosGoal {
- pub pos: BlockPos,
-}
+pub struct BlockPosGoal(pub BlockPos);
impl Goal for BlockPosGoal {
fn heuristic(&self, n: BlockPos) -> f32 {
- let dx = (self.pos.x - n.x) as f32;
- let dy = (self.pos.y - n.y) as f32;
- let dz = (self.pos.z - n.z) as f32;
+ let dx = (self.0.x - n.x) as f32;
+ let dy = (self.0.y - n.y) as f32;
+ let dz = (self.0.z - n.z) as f32;
dx * dx + dy * dy + dz * dz
}
fn success(&self, n: BlockPos) -> bool {
- n == self.pos
- }
- fn goal_node(&self) -> BlockPos {
- self.pos
- }
-}
-
-impl From<BlockPos> for BlockPosGoal {
- fn from(pos: BlockPos) -> Self {
- Self { pos }
+ n == self.0
}
}
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index dcedb9be..e656be47 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -109,7 +109,7 @@ impl PathfinderClientExt for azalea_client::Client {
/// # use azalea::prelude::*;
/// # use azalea::{BlockPos, pathfinder::goals::BlockPosGoal};
/// # fn example(bot: &Client) {
- /// bot.goto(BlockPosGoal::from(BlockPos::new(0, 70, 0)));
+ /// bot.goto(BlockPosGoal(BlockPos::new(0, 70, 0)));
/// # }
/// ```
fn goto(&self, goal: impl Goal + Send + Sync + 'static) {
@@ -160,13 +160,12 @@ fn goto_listener(
let world_lock = instance_container
.get(instance_name)
.expect("Entity tried to pathfind but the entity isn't in a valid world");
- let end = event.goal.goal_node();
let goal = event.goal.clone();
let entity = event.entity;
let task = thread_pool.spawn(async move {
- debug!("start: {start:?}, end: {end:?}");
+ debug!("start: {start:?}");
let successors = |pos: BlockPos| {
let world = world_lock.read();
@@ -477,9 +476,6 @@ fn stop_pathfinding_on_instance_change(
pub trait Goal {
fn heuristic(&self, n: BlockPos) -> f32;
fn success(&self, n: BlockPos) -> bool;
- // TODO: this should be removed and mtdstarlite should stop depending on
- // being given a goal node
- fn goal_node(&self) -> BlockPos;
}
/// Returns whether the entity is at the node and should start going to the
@@ -563,7 +559,7 @@ mod tests {
simulation.app.world.send_event(GotoEvent {
entity: simulation.entity,
- goal: Arc::new(BlockPosGoal::from(end_pos)),
+ goal: Arc::new(BlockPosGoal(end_pos)),
});
simulation
}