Skip to content

Commit 268c625

Browse files
committed
add simulation-based pathfinder execution engine
1 parent fb92f65 commit 268c625

File tree

18 files changed

+759
-89
lines changed

18 files changed

+759
-89
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _Currently supported Minecraft version: `1.21.11`._
1818
## Features
1919

2020
- [Accurate physics](https://azalea.matdoes.dev/azalea_physics/) (but some features like entity pushing and elytras aren't implemented yet)
21-
- [Pathfinder](https://azalea.matdoes.dev/azalea/pathfinder/index.html) (partially based on Baritone and several times faster)
21+
- [Pathfinder](https://azalea.matdoes.dev/azalea/pathfinder/index.html)
2222
- [Swarms](https://azalea.matdoes.dev/azalea/swarm/index.html)
2323
- [Breaking blocks](https://azalea.matdoes.dev/azalea/struct.Client.html#method.mine)
2424
- [Block interactions & building](https://azalea.matdoes.dev/azalea/struct.Client.html#method.block_interact) (this doesn't predict the block interactions/placement on the client yet, but it's usually fine)

azalea-client/src/plugins/mining.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use azalea_inventory::ItemStack;
88
use azalea_physics::{PhysicsSystems, collision::BlockWithShape};
99
use azalea_protocol::packets::game::s_player_action::{self, ServerboundPlayerAction};
1010
use azalea_registry::builtin::{BlockKind, ItemKind};
11-
use azalea_world::{Worlds, WorldName};
11+
use azalea_world::{WorldName, Worlds};
1212
use bevy_app::{App, Plugin, Update};
1313
use bevy_ecs::prelude::*;
1414
use derive_more::{Deref, DerefMut};

azalea-client/tests/simulation/move_and_despawn_entity.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use azalea_client::test_utils::prelude::*;
2-
use azalea_core::position::{ChunkPos, Vec3};
2+
use azalea_core::{
3+
entity_id::MinecraftEntityId,
4+
position::{ChunkPos, Vec3},
5+
};
36
use azalea_protocol::{
47
common::movements::{PositionMoveRotation, RelativeMovements},
58
packets::{
@@ -8,7 +11,6 @@ use azalea_protocol::{
811
},
912
};
1013
use azalea_registry::builtin::EntityKind;
11-
use azalea_core::entity_id::MinecraftEntityId;
1214

1315
#[test]
1416
fn test_move_and_despawn_entity() {

azalea-client/tests/simulation/move_despawned_entity.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use azalea_client::test_utils::prelude::*;
2-
use azalea_core::position::ChunkPos;
2+
use azalea_core::{entity_id::MinecraftEntityId, position::ChunkPos};
33
use azalea_entity::metadata::Cow;
44
use azalea_protocol::packets::{ConnectionProtocol, game::ClientboundMoveEntityRot};
55
use azalea_registry::builtin::EntityKind;
6-
use azalea_core::entity_id::MinecraftEntityId;
76
use bevy_ecs::query::With;
87
use tracing::Level;
98

azalea-client/tests/simulation/teleport_movement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use azalea_client::test_utils::prelude::*;
22
use azalea_core::{
33
delta::{LpVec3, PositionDelta8},
4+
entity_id::MinecraftEntityId,
45
position::{BlockPos, ChunkPos, Vec3},
56
};
67
use azalea_entity::LookDirection;
@@ -16,7 +17,6 @@ use azalea_protocol::{
1617
},
1718
};
1819
use azalea_registry::builtin::BlockKind;
19-
use azalea_core::entity_id::MinecraftEntityId;
2020

2121
#[test]
2222
fn test_teleport_movement() {

azalea-core/src/position.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ macro_rules! vec3_impl {
126126
self.x * other.x + self.y * other.y + self.z * other.z
127127
}
128128

129+
#[inline]
130+
pub fn cross(&self, other: Self) -> Self {
131+
Self::new(
132+
self.y * other.z - self.z * other.y,
133+
self.z * other.x - self.x * other.z,
134+
self.x * other.y - self.y * other.x,
135+
)
136+
}
137+
129138
/// Make a new position with the lower coordinates for each axis.
130139
pub fn min(&self, other: Self) -> Self {
131140
Self {
@@ -333,6 +342,7 @@ impl simdnbt::FromNbtTag for Vec3 {
333342
impl Vec3 {
334343
/// Get the distance of this vector to the origin by doing
335344
/// `sqrt(x^2 + y^2 + z^2)`.
345+
#[doc(alias = "modulus")]
336346
pub fn length(&self) -> f64 {
337347
f64::sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
338348
}
@@ -343,6 +353,13 @@ impl Vec3 {
343353
(self - other).length()
344354
}
345355

356+
pub fn horizontal_distance_to(self, other: Self) -> f64 {
357+
self.horizontal_distance_squared_to(other).sqrt()
358+
}
359+
pub fn horizontal_distance(self) -> f64 {
360+
self.horizontal_distance_squared().sqrt()
361+
}
362+
346363
pub fn x_rot(self, radians: f32) -> Vec3 {
347364
let x_delta = math::cos(radians);
348365
let y_delta = math::sin(radians);

azalea-entity/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl LookDirection {
182182
pub fn update(&mut self, new: LookDirection) {
183183
self.update_with_sensitivity(new, 1.);
184184
}
185-
/// Update the `y_rot` to the given value, in degrees.
185+
/// Update the `y_rot` (yaw) to the given value, in degrees.
186186
///
187187
/// This is a shortcut for [`Self::update`] while keeping the `x_rot` the
188188
/// same.
@@ -192,7 +192,7 @@ impl LookDirection {
192192
x_rot: self.x_rot,
193193
});
194194
}
195-
/// Update the `x_rot` to the given value, in degrees.
195+
/// Update the `x_rot` (pitch) to the given value, in degrees.
196196
///
197197
/// This is a shortcut for [`Self::update`] while keeping the `y_rot` the
198198
/// same.

azalea-world/src/container.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Worlds {
9494
/// If two entities share the same world name, then Azalea assumes that they're
9595
/// in the same world.
9696
#[derive(Clone, Component, Debug, Deref, DerefMut, Eq, Hash, PartialEq)]
97-
#[doc(alias("worldname", "world name", "dimension"))]
97+
#[doc(alias("dimension"))]
9898
pub struct WorldName(pub Identifier);
9999
impl WorldName {
100100
/// Create a new `WorldName` with the given name.

azalea-world/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod world;
1212

1313
pub use bit_storage::BitStorage;
1414
pub use chunk_storage::{Chunk, ChunkStorage, PartialChunkStorage, Section};
15-
pub use container::{Worlds, WorldName};
15+
pub use container::{WorldName, Worlds};
1616
pub use world::*;
1717

1818
#[deprecated = "renamed to `WorldName`."]

azalea/examples/testbot/main.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,23 @@
1919
//! /particle a ton of times to show where it's pathfinding to. You should
2020
//! only have this on if the bot has operator permissions, otherwise it'll
2121
//! just spam the server console unnecessarily.
22+
//! - `--simulation-pathfinder`: Use the alternative simulation-based execution
23+
//! engine for the pathfinder.
2224
2325
mod commands;
2426
pub mod killaura;
2527

2628
use std::{env, process, sync::Arc, thread, time::Duration};
2729

2830
use azalea::{
29-
ClientInformation, brigadier::command_dispatcher::CommandDispatcher, ecs::prelude::*,
30-
pathfinder::debug::PathfinderDebugParticles, prelude::*, swarm::prelude::*,
31+
ClientInformation,
32+
brigadier::command_dispatcher::CommandDispatcher,
33+
ecs::prelude::*,
34+
pathfinder::{
35+
debug::PathfinderDebugParticles, execute::simulation::SimulationPathfinderExecutionPlugin,
36+
},
37+
prelude::*,
38+
swarm::prelude::*,
3139
};
3240
use commands::{CommandSource, register_commands};
3341
use parking_lot::Mutex;
@@ -44,6 +52,10 @@ async fn main() -> AppExit {
4452
.set_handler(handle)
4553
.set_swarm_handler(swarm_handle);
4654

55+
if args.simulation_pathfinder {
56+
builder = builder.add_plugins(SimulationPathfinderExecutionPlugin);
57+
}
58+
4759
for username_or_email in &args.accounts {
4860
let account = if username_or_email.contains('@') {
4961
Account::microsoft(username_or_email).await.unwrap()
@@ -210,13 +222,15 @@ pub struct Args {
210222
pub accounts: Vec<String>,
211223
pub server: String,
212224
pub pathfinder_debug_particles: bool,
225+
pub simulation_pathfinder: bool,
213226
}
214227

215228
fn parse_args() -> Args {
216229
let mut owner_username = "admin".to_owned();
217230
let mut accounts = Vec::new();
218231
let mut server = "localhost".to_owned();
219232
let mut pathfinder_debug_particles = false;
233+
let mut simulation_pathfinder = false;
220234

221235
let mut args = env::args().skip(1);
222236
while let Some(arg) = args.next() {
@@ -235,6 +249,9 @@ fn parse_args() -> Args {
235249
"--pathfinder-debug-particles" | "-P" => {
236250
pathfinder_debug_particles = true;
237251
}
252+
"--simulation-pathfinder" => {
253+
simulation_pathfinder = true;
254+
}
238255
_ => {
239256
eprintln!("Unknown argument: {arg}");
240257
process::exit(1);
@@ -251,5 +268,6 @@ fn parse_args() -> Args {
251268
accounts,
252269
server,
253270
pathfinder_debug_particles,
271+
simulation_pathfinder,
254272
}
255273
}

0 commit comments

Comments
 (0)