aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/pathfinder
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-02-22 23:01:54 +0000
committermat <git@matdoes.dev>2025-02-22 23:01:54 +0000
commit34f53baf85fb5c7163ec5d71a8ab9d45d3f271b6 (patch)
tree7920fec1203e8e96463a142f5f6da6164e76e684 /azalea/src/pathfinder
parentbdd2fc91e11e2896d8e1c7046df247e1075bd40d (diff)
downloadazalea-drasl-34f53baf85fb5c7163ec5d71a8ab9d45d3f271b6.tar.xz
update to rust edition 2024
Diffstat (limited to 'azalea/src/pathfinder')
-rw-r--r--azalea/src/pathfinder/debug.rs22
-rw-r--r--azalea/src/pathfinder/mining.rs2
-rw-r--r--azalea/src/pathfinder/mod.rs91
-rw-r--r--azalea/src/pathfinder/moves/basic.rs2
-rw-r--r--azalea/src/pathfinder/moves/mod.rs8
-rw-r--r--azalea/src/pathfinder/simulation.rs6
6 files changed, 69 insertions, 62 deletions
diff --git a/azalea/src/pathfinder/debug.rs b/azalea/src/pathfinder/debug.rs
index ca08cbc5..98778cad 100644
--- a/azalea/src/pathfinder/debug.rs
+++ b/azalea/src/pathfinder/debug.rs
@@ -1,4 +1,4 @@
-use azalea_client::{chat::SendChatEvent, InstanceHolder};
+use azalea_client::{InstanceHolder, chat::SendChatEvent};
use azalea_core::position::Vec3;
use bevy_ecs::prelude::*;
@@ -89,16 +89,16 @@ pub fn debug_render_path_with_particles(
z: start_vec3.z + (end_vec3.z - start_vec3.z) * percent,
};
let particle_command = format!(
- "/particle dust{{color:[{r},{g},{b}],scale:{size}}} {start_x} {start_y} {start_z} {delta_x} {delta_y} {delta_z} 0 {count}",
- size = 1,
- start_x = pos.x,
- start_y = pos.y,
- start_z = pos.z,
- delta_x = 0,
- delta_y = 0,
- delta_z = 0,
- count = 1
- );
+ "/particle dust{{color:[{r},{g},{b}],scale:{size}}} {start_x} {start_y} {start_z} {delta_x} {delta_y} {delta_z} 0 {count}",
+ size = 1,
+ start_x = pos.x,
+ start_y = pos.y,
+ start_z = pos.z,
+ delta_x = 0,
+ delta_y = 0,
+ delta_z = 0,
+ count = 1
+ );
chat_events.send(SendChatEvent {
entity,
content: particle_command,
diff --git a/azalea/src/pathfinder/mining.rs b/azalea/src/pathfinder/mining.rs
index 8c1b2e1d..40cdf8a2 100644
--- a/azalea/src/pathfinder/mining.rs
+++ b/azalea/src/pathfinder/mining.rs
@@ -1,7 +1,7 @@
use std::{cell::UnsafeCell, ops::RangeInclusive};
use azalea_block::{
- block_state::BlockStateIntegerRepr, properties::Waterlogged, BlockState, BlockStates,
+ BlockState, BlockStates, block_state::BlockStateIntegerRepr, properties::Waterlogged,
};
use azalea_inventory::Menu;
use nohash_hasher::IntMap;
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index ae23788b..0db627ac 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -14,8 +14,8 @@ pub mod world;
use std::collections::VecDeque;
use std::ops::RangeInclusive;
-use std::sync::atomic::{self, AtomicUsize};
use std::sync::Arc;
+use std::sync::atomic::{self, AtomicUsize};
use std::time::{Duration, Instant};
use std::{cmp, thread};
@@ -26,8 +26,8 @@ use azalea_client::movement::MoveEventsSet;
use azalea_client::{InstanceHolder, StartSprintEvent, StartWalkEvent};
use azalea_core::position::BlockPos;
use azalea_core::tick::GameTick;
-use azalea_entity::metadata::Player;
use azalea_entity::LocalEntity;
+use azalea_entity::metadata::Player;
use azalea_entity::{Physics, Position};
use azalea_physics::PhysicsSet;
use azalea_world::{InstanceContainer, InstanceName};
@@ -42,11 +42,12 @@ use parking_lot::RwLock;
use rel_block_pos::RelBlockPos;
use tracing::{debug, error, info, trace, warn};
-use self::debug::debug_render_path_with_particles;
pub use self::debug::PathfinderDebugParticles;
+use self::debug::debug_render_path_with_particles;
use self::goals::Goal;
use self::mining::MiningCache;
use self::moves::{ExecuteCtx, IsReachedCtx, SuccessorsFn};
+use crate::WalkDirection;
use crate::app::{App, Plugin};
use crate::bot::{JumpEvent, LookAtEvent};
use crate::ecs::{
@@ -57,7 +58,6 @@ use crate::ecs::{
system::{Commands, Query, Res},
};
use crate::pathfinder::{astar::a_star, moves::PathfinderCtx, world::CachedWorld};
-use crate::WalkDirection;
#[derive(Clone, Default)]
pub struct PathfinderPlugin;
@@ -874,54 +874,62 @@ pub fn recalculate_near_end_of_path(
&& !pathfinder.is_calculating
&& executing_path.is_path_partial
{
- if let Some(goal) = pathfinder.goal.as_ref().cloned() {
- debug!("Recalculating path because it's empty or ends soon");
- debug!(
- "recalculate_near_end_of_path executing_path.is_path_partial: {}",
- executing_path.is_path_partial
- );
- goto_events.send(GotoEvent {
- entity,
- goal,
- successors_fn,
- allow_mining: pathfinder.allow_mining,
- min_timeout: if executing_path.path.len() == 50 {
- // we have quite some time until the node is reached, soooo we might as well
- // burn some cpu cycles to get a good path
- PathfinderTimeout::Time(Duration::from_secs(5))
- } else {
- PathfinderTimeout::Time(Duration::from_secs(1))
- },
- max_timeout: pathfinder.max_timeout.expect("max_timeout should be set"),
- });
- pathfinder.is_calculating = true;
+ match pathfinder.goal.as_ref().cloned() {
+ Some(goal) => {
+ debug!("Recalculating path because it's empty or ends soon");
+ debug!(
+ "recalculate_near_end_of_path executing_path.is_path_partial: {}",
+ executing_path.is_path_partial
+ );
+ goto_events.send(GotoEvent {
+ entity,
+ goal,
+ successors_fn,
+ allow_mining: pathfinder.allow_mining,
+ min_timeout: if executing_path.path.len() == 50 {
+ // we have quite some time until the node is reached, soooo we might as
+ // well burn some cpu cycles to get a good
+ // path
+ PathfinderTimeout::Time(Duration::from_secs(5))
+ } else {
+ PathfinderTimeout::Time(Duration::from_secs(1))
+ },
+ max_timeout: pathfinder.max_timeout.expect("max_timeout should be set"),
+ });
+ pathfinder.is_calculating = true;
- if executing_path.path.is_empty() {
- if let Some(new_path) = executing_path.queued_path.take() {
- executing_path.path = new_path;
- if executing_path.path.is_empty() {
- info!("the path we just swapped to was empty, so reached end of path");
+ if executing_path.path.is_empty() {
+ if let Some(new_path) = executing_path.queued_path.take() {
+ executing_path.path = new_path;
+ if executing_path.path.is_empty() {
+ info!(
+ "the path we just swapped to was empty, so reached end of path"
+ );
+ walk_events.send(StartWalkEvent {
+ entity,
+ direction: WalkDirection::None,
+ });
+ commands.entity(entity).remove::<ExecutingPath>();
+ break;
+ }
+ } else {
walk_events.send(StartWalkEvent {
entity,
direction: WalkDirection::None,
});
commands.entity(entity).remove::<ExecutingPath>();
- break;
}
- } else {
+ }
+ }
+ _ => {
+ if executing_path.path.is_empty() {
+ // idk when this can happen but stop moving just in case
walk_events.send(StartWalkEvent {
entity,
direction: WalkDirection::None,
});
- commands.entity(entity).remove::<ExecutingPath>();
}
}
- } else if executing_path.path.is_empty() {
- // idk when this can happen but stop moving just in case
- walk_events.send(StartWalkEvent {
- entity,
- direction: WalkDirection::None,
- });
}
}
}
@@ -968,8 +976,7 @@ pub fn tick_execute_path(
};
trace!(
"executing move, position: {}, last_reached_node: {}",
- **position,
- executing_path.last_reached_node
+ **position, executing_path.last_reached_node
);
(movement.data.execute)(ctx);
}
@@ -1117,11 +1124,11 @@ mod tests {
use azalea_world::{Chunk, ChunkStorage, PartialChunkStorage};
use super::{
+ GotoEvent,
astar::PathfinderTimeout,
goals::BlockPosGoal,
moves,
simulation::{SimulatedPlayerBundle, Simulation},
- GotoEvent,
};
fn setup_blockposgoal_simulation(
diff --git a/azalea/src/pathfinder/moves/basic.rs b/azalea/src/pathfinder/moves/basic.rs
index 8a679376..4955ed08 100644
--- a/azalea/src/pathfinder/moves/basic.rs
+++ b/azalea/src/pathfinder/moves/basic.rs
@@ -6,7 +6,7 @@ use azalea_core::{
position::{BlockPos, Vec3},
};
-use super::{default_is_reached, Edge, ExecuteCtx, IsReachedCtx, MoveData, PathfinderCtx};
+use super::{Edge, ExecuteCtx, IsReachedCtx, MoveData, PathfinderCtx, default_is_reached};
use crate::pathfinder::{astar, costs::*, rel_block_pos::RelBlockPos};
pub fn basic_move(ctx: &mut PathfinderCtx, node: RelBlockPos) {
diff --git a/azalea/src/pathfinder/moves/mod.rs b/azalea/src/pathfinder/moves/mod.rs
index 68c65d5d..83e6369f 100644
--- a/azalea/src/pathfinder/moves/mod.rs
+++ b/azalea/src/pathfinder/moves/mod.rs
@@ -4,8 +4,8 @@ pub mod parkour;
use std::{fmt::Debug, sync::Arc};
use azalea_client::{
- inventory::SetSelectedHotbarSlotEvent, mining::StartMiningBlockEvent, SprintDirection,
- StartSprintEvent, StartWalkEvent, WalkDirection,
+ SprintDirection, StartSprintEvent, StartWalkEvent, WalkDirection,
+ inventory::SetSelectedHotbarSlotEvent, mining::StartMiningBlockEvent,
};
use azalea_core::position::{BlockPos, Vec3};
use azalea_inventory::Menu;
@@ -17,9 +17,9 @@ use super::{
astar,
mining::MiningCache,
rel_block_pos::RelBlockPos,
- world::{is_block_state_passable, CachedWorld},
+ world::{CachedWorld, is_block_state_passable},
};
-use crate::{auto_tool::best_tool_in_hotbar_for_block, JumpEvent, LookAtEvent};
+use crate::{JumpEvent, LookAtEvent, auto_tool::best_tool_in_hotbar_for_block};
type Edge = astar::Edge<RelBlockPos, MoveData>;
diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs
index 0067c19f..ab0e540a 100644
--- a/azalea/src/pathfinder/simulation.rs
+++ b/azalea/src/pathfinder/simulation.rs
@@ -2,10 +2,10 @@
use std::sync::Arc;
-use azalea_client::{inventory::Inventory, packet_handling::game::SendPacketEvent, PhysicsState};
+use azalea_client::{PhysicsState, inventory::Inventory, packet_handling::game::SendPacketEvent};
use azalea_core::{position::Vec3, resource_location::ResourceLocation, tick::GameTick};
use azalea_entity::{
- attributes::AttributeInstance, Attributes, EntityDimensions, LookDirection, Physics, Position,
+ Attributes, EntityDimensions, LookDirection, Physics, Position, attributes::AttributeInstance,
};
use azalea_registry::EntityKind;
use azalea_world::{ChunkStorage, Instance, InstanceContainer, MinecraftEntityId, PartialInstance};
@@ -87,7 +87,7 @@ fn create_simulation_instance(chunks: ChunkStorage) -> (App, Arc<RwLock<Instance
fn create_simulation_player_complete_bundle(
instance: Arc<RwLock<Instance>>,
player: &SimulatedPlayerBundle,
-) -> impl Bundle {
+) -> impl Bundle + use<> {
let instance_name = simulation_instance_name();
(