aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/pathfinder/simulation.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-01-18 09:50:45 -1245
committermat <git@matdoes.dev>2026-01-19 05:35:49 +0700
commit268c62587e090c72b67a29e1cc42cda6c9d7340b (patch)
tree961d0b4d0bd22d17f4ad6c8b77f02f02566b838e /azalea/src/pathfinder/simulation.rs
parentfb92f65b3da49b6487bf6fa05010b12a3ab5d4ed (diff)
downloadazalea-drasl-268c62587e090c72b67a29e1cc42cda6c9d7340b.tar.xz
add simulation-based pathfinder execution engine
Diffstat (limited to 'azalea/src/pathfinder/simulation.rs')
-rw-r--r--azalea/src/pathfinder/simulation.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs
index 94837f9e..a8f24480 100644
--- a/azalea/src/pathfinder/simulation.rs
+++ b/azalea/src/pathfinder/simulation.rs
@@ -130,18 +130,23 @@ fn create_simulation_player(
pub struct Simulation {
pub app: App,
pub entity: Entity,
- _world: Arc<RwLock<World>>,
+ pub world: Arc<RwLock<World>>,
}
impl Simulation {
pub fn new(chunks: ChunkStorage, player: SimulatedPlayerBundle) -> Self {
let (mut app, world) = create_simulation_world(chunks);
let entity = create_simulation_player(app.world_mut(), world.clone(), player);
- Self {
- app,
- entity,
- _world: world,
- }
+ Self { app, entity, world }
+ }
+
+ /// Despawn the old simulated player and create a new one.
+ ///
+ /// This is cheaper than creating a new [`Simulation`] from scratch.
+ pub fn reset(&mut self, player: SimulatedPlayerBundle) {
+ self.app.world_mut().despawn(self.entity);
+ let entity = create_simulation_player(self.app.world_mut(), self.world.clone(), player);
+ self.entity = entity;
}
pub fn tick(&mut self) {
@@ -157,6 +162,9 @@ impl Simulation {
pub fn position(&self) -> Vec3 {
*self.component::<Position>()
}
+ pub fn physics(&self) -> Physics {
+ self.component::<Physics>().clone()
+ }
pub fn is_mining(&self) -> bool {
// return true if the component is present and Some
self.get_component::<azalea_client::mining::MineBlockPos>()