aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--azalea/examples/steal.rs2
-rw-r--r--azalea/examples/testbot.rs8
-rw-r--r--azalea/src/pathfinder/goals.rs21
-rw-r--r--azalea/src/pathfinder/mod.rs10
4 files changed, 13 insertions, 28 deletions
diff --git a/azalea/examples/steal.rs b/azalea/examples/steal.rs
index ce5b7d21..408d7b9b 100644
--- a/azalea/examples/steal.rs
+++ b/azalea/examples/steal.rs
@@ -44,7 +44,7 @@ async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<(
bot.chat("No chest found");
return Ok(());
};
- // bot.goto(BlockPosGoal::from(chest_block));
+ // bot.goto(BlockPosGoal(chest_block));
let Some(chest) = bot.open_container(chest_block).await else {
println!("Couldn't open chest");
return Ok(());
diff --git a/azalea/examples/testbot.rs b/azalea/examples/testbot.rs
index a0f60fbc..73870b59 100644
--- a/azalea/examples/testbot.rs
+++ b/azalea/examples/testbot.rs
@@ -127,10 +127,10 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result<
let entity_pos = bot.entity_component::<Position>(entity);
let target_pos: BlockPos = entity_pos.into();
println!("going to {target_pos:?}");
- bot.goto(BlockPosGoal::from(target_pos));
+ bot.goto(BlockPosGoal(target_pos));
}
"worldborder" => {
- bot.goto(BlockPosGoal::from(BlockPos::new(30_000_000, 70, 0)));
+ bot.goto(BlockPosGoal(BlockPos::new(30_000_000, 70, 0)));
}
"look" => {
let Some(entity) = entity else {
@@ -176,7 +176,7 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result<
);
if let Some(target_pos) = target_pos {
// +1 to stand on top of the block
- bot.goto(BlockPosGoal::from(target_pos.up(1)));
+ bot.goto(BlockPosGoal(target_pos.up(1)));
} else {
bot.chat("no diamond block found");
}
@@ -205,7 +205,7 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result<
bot.chat("no lever found");
return Ok(());
};
- bot.goto(BlockPosGoal::from(target_pos));
+ bot.goto(BlockPosGoal(target_pos));
bot.look_at(target_pos.center());
bot.block_interact(target_pos);
}
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
}