aboutsummaryrefslogtreecommitdiff
path: root/azalea/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-03-06 11:12:07 +0500
committermat <git@matdoes.dev>2026-03-06 11:12:07 +0500
commit8dc511bb1b77da67d5428e8bafeab92ad3bfabf4 (patch)
treeb155417c3470412bc9dcf2f39f8440f71c805335 /azalea/src
parent62eb3ec38cca04ac09156bb2693a9f8ca82b3da6 (diff)
downloadazalea-drasl-8dc511bb1b77da67d5428e8bafeab92ad3bfabf4.tar.xz
fix various regressions from optimization attempts
Diffstat (limited to 'azalea/src')
-rw-r--r--azalea/src/pathfinder/execute/mod.rs5
-rw-r--r--azalea/src/pathfinder/execute/simulation.rs53
-rw-r--r--azalea/src/pathfinder/mod.rs13
-rw-r--r--azalea/src/pathfinder/simulation.rs8
4 files changed, 51 insertions, 28 deletions
diff --git a/azalea/src/pathfinder/execute/mod.rs b/azalea/src/pathfinder/execute/mod.rs
index d022885c..f4214054 100644
--- a/azalea/src/pathfinder/execute/mod.rs
+++ b/azalea/src/pathfinder/execute/mod.rs
@@ -26,7 +26,7 @@ use crate::{
system::{Commands, Query, Res},
},
pathfinder::{
- ExecutingPath, GotoEvent, Pathfinder,
+ ExecutingPath, GotoEvent, Pathfinder, PathfinderSystems,
astar::PathfinderTimeout,
custom_state::CustomPathfinderState,
debug::debug_render_path_with_particles,
@@ -60,7 +60,8 @@ impl Plugin for DefaultPathfinderExecutionPlugin {
.after(PhysicsSystems)
.after(azalea_client::movement::send_position)
.after(MiningSystems)
- .after(debug_render_path_with_particles),
+ .after(debug_render_path_with_particles)
+ .in_set(PathfinderSystems),
);
}
}
diff --git a/azalea/src/pathfinder/execute/simulation.rs b/azalea/src/pathfinder/execute/simulation.rs
index a002df4d..7287587b 100644
--- a/azalea/src/pathfinder/execute/simulation.rs
+++ b/azalea/src/pathfinder/execute/simulation.rs
@@ -25,7 +25,7 @@ use crate::{
system::{Commands, Query},
},
pathfinder::{
- ExecutingPath,
+ ExecutingPath, PathfinderSystems,
debug::debug_render_path_with_particles,
moves::{ExecuteCtx, IsReachedCtx},
simulation::{SimulatedPlayerBundle, Simulation},
@@ -68,7 +68,8 @@ impl Plugin for SimulationPathfinderExecutionPlugin {
.after(PhysicsSystems)
.after(azalea_client::movement::send_position)
.after(MiningSystems)
- .after(debug_render_path_with_particles),
+ .after(debug_render_path_with_particles)
+ .in_set(PathfinderSystems),
);
}
}
@@ -213,6 +214,7 @@ pub fn tick_execute_path(
direction: SprintDirection::Forward,
});
} else if physics_state.was_sprinting {
+ // have to let go for a tick to be able to start walking
walk_events.write(StartWalkEvent {
entity,
direction: WalkDirection::None,
@@ -342,6 +344,10 @@ fn run_one_simulation(
let start = BlockPos::from(player.position);
sim.reset(player);
+ // run an Update to initialize some things, including at least the Bot component
+ // (which is needed for jumping)
+ sim.run_update_schedule();
+
let simulating_to_block = simulating_to.movement.target;
let mut success = false;
@@ -349,6 +355,27 @@ fn run_one_simulation(
for ticks in 1..=timeout_ticks {
let position = sim.position();
+ let physics = sim.physics();
+
+ if physics.horizontal_collision
+ || physics.is_in_lava()
+ || (physics.velocity.y < -0.7 && !physics.is_in_water())
+ {
+ // fail
+ break;
+ }
+
+ if (simulating_to.movement.data.is_reached)(IsReachedCtx {
+ target: simulating_to_block,
+ start,
+ position,
+ physics: &physics,
+ }) {
+ success = true;
+ total_ticks = ticks;
+ break;
+ }
+
let ecs = sim.app.world_mut();
ecs.get_mut::<LookDirection>(sim.entity)
@@ -362,7 +389,7 @@ fn run_one_simulation(
});
} else if ecs
.get::<PhysicsState>(sim.entity)
- .map(|p| p.trying_to_sprint)
+ .map(|p| p.was_sprinting)
.unwrap_or_default()
{
// have to let go for a tick to be able to start walking
@@ -388,26 +415,6 @@ fn run_one_simulation(
}
sim.tick();
-
- let physics = sim.physics();
- if physics.horizontal_collision
- || physics.is_in_lava()
- || (physics.velocity.y < -0.7 && !physics.is_in_water())
- {
- // fail
- break;
- }
-
- if (simulating_to.movement.data.is_reached)(IsReachedCtx {
- target: simulating_to_block,
- start,
- position: sim.position(),
- physics: &physics,
- }) {
- success = true;
- total_ticks = ticks;
- break;
- }
}
if success {
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index 6f1a0d8a..0269389b 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -82,8 +82,11 @@ impl Plugin for PathfinderPlugin {
app.add_message::<GotoEvent>()
.add_message::<PathFoundEvent>()
.add_message::<StopPathfindingEvent>()
- .add_systems(GameTick, debug_render_path_with_particles)
- .add_systems(PreUpdate, add_default_pathfinder)
+ .add_systems(
+ GameTick,
+ debug_render_path_with_particles.in_set(PathfinderSystems),
+ )
+ .add_systems(PreUpdate, add_default_pathfinder.in_set(PathfinderSystems))
.add_systems(
Update,
(
@@ -95,12 +98,16 @@ impl Plugin for PathfinderPlugin {
)
.chain()
.before(MoveEventsSystems)
- .before(InventorySystems),
+ .before(InventorySystems)
+ .in_set(PathfinderSystems),
)
.add_plugins(DefaultPathfinderExecutionPlugin);
}
}
+#[derive(Clone, Debug, Eq, Hash, PartialEq, SystemSet)]
+pub struct PathfinderSystems;
+
/// A component that makes this client able to pathfind.
#[derive(Clone, Component, Default)]
#[non_exhaustive]
diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs
index 72e5e048..82d93370 100644
--- a/azalea/src/pathfinder/simulation.rs
+++ b/azalea/src/pathfinder/simulation.rs
@@ -152,9 +152,17 @@ impl Simulation {
}
pub fn tick(&mut self) {
+ self.run_update_schedule();
+ self.run_gametick_schedule();
+ }
+
+ pub fn run_update_schedule(&mut self) {
self.app.update();
+ }
+ pub fn run_gametick_schedule(&mut self) {
self.app.world_mut().run_schedule(GameTick);
}
+
pub fn component<T: Component + Clone>(&self) -> T {
self.app.world().get::<T>(self.entity).unwrap().clone()
}