1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 23:44:38 +00:00

remove BlockPosGoal::from and Goal::goal_node

This commit is contained in:
mat 2023-09-30 12:38:09 -05:00
commit 3f62ff1113
4 changed files with 13 additions and 28 deletions

View file

@ -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(());

View file

@ -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);
}

View file

@ -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
}
}

View file

@ -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
}