aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-11 22:58:41 -0630
committermat <git@matdoes.dev>2025-06-11 22:58:41 -0630
commita2606569bb79867d07a075bcf7b05730e4264d72 (patch)
treefb97fb52aa0c4d7575f6bd5e4e36c2f01c87f942
parent89ddd5e85f4f2fb98697df15528df6e07a3ddd07 (diff)
downloadazalea-drasl-a2606569bb79867d07a075bcf7b05730e4264d72.tar.xz
use owned instead of borrowed Vec3 more
-rw-r--r--azalea-block/src/fluid_state.rs2
-rw-r--r--azalea-client/src/entity_query.rs2
-rw-r--r--azalea-client/src/plugins/interact.rs14
-rw-r--r--azalea-client/src/plugins/packet/game/mod.rs4
-rw-r--r--azalea-core/src/aabb.rs166
-rw-r--r--azalea-core/src/position.rs57
-rw-r--r--azalea-entity/src/dimensions.rs2
-rw-r--r--azalea-entity/src/lib.rs26
-rw-r--r--azalea-entity/src/plugin/mod.rs2
-rw-r--r--azalea-physics/src/clip.rs28
-rw-r--r--azalea-physics/src/collision/mod.rs79
-rw-r--r--azalea-physics/src/collision/shape.rs16
-rw-r--r--azalea-physics/src/fluids.rs4
-rw-r--r--azalea-physics/src/lib.rs73
-rw-r--r--azalea-physics/src/travel.rs28
-rw-r--r--azalea/examples/testbot/killaura.rs2
-rw-r--r--azalea/src/bot.rs4
-rw-r--r--azalea/src/nearest_entity.rs10
-rw-r--r--azalea/src/pathfinder/debug.rs2
-rw-r--r--azalea/src/pathfinder/goals.rs10
-rw-r--r--azalea/src/pathfinder/mod.rs2
21 files changed, 231 insertions, 302 deletions
diff --git a/azalea-block/src/fluid_state.rs b/azalea-block/src/fluid_state.rs
index edceac05..cfddcc7f 100644
--- a/azalea-block/src/fluid_state.rs
+++ b/azalea-block/src/fluid_state.rs
@@ -20,7 +20,7 @@ pub struct FluidState {
/// set (see FlowingFluid.getFlowing)
pub falling: bool,
}
-#[derive(Default, Clone, Debug, PartialEq, Eq)]
+#[derive(Default, Clone, Copy, Debug, PartialEq, Eq)]
pub enum FluidKind {
#[default]
Empty,
diff --git a/azalea-client/src/entity_query.rs b/azalea-client/src/entity_query.rs
index 5b19bb24..ee99d0f4 100644
--- a/azalea-client/src/entity_query.rs
+++ b/azalea-client/src/entity_query.rs
@@ -162,7 +162,7 @@ where
entities.sort_by_cached_key(|(_, position)| {
// to_bits is fine here as long as the number is positive
- position.distance_squared_to(&nearest_to).to_bits()
+ position.distance_squared_to(nearest_to).to_bits()
});
entities
diff --git a/azalea-client/src/plugins/interact.rs b/azalea-client/src/plugins/interact.rs
index 31b5acf4..d91597d6 100644
--- a/azalea-client/src/plugins/interact.rs
+++ b/azalea-client/src/plugins/interact.rs
@@ -363,7 +363,7 @@ pub fn update_hit_result_component(
};
let instance = instance_lock.read();
- let hit_result = pick(look_direction, &eye_position, &instance.chunks, pick_range);
+ let hit_result = pick(*look_direction, eye_position, &instance.chunks, pick_range);
if let Some(mut hit_result_ref) = hit_result_ref {
**hit_result_ref = hit_result;
} else {
@@ -384,8 +384,8 @@ pub fn update_hit_result_component(
///
/// TODO: does not currently check for entities
pub fn pick(
- look_direction: &LookDirection,
- eye_position: &Vec3,
+ look_direction: LookDirection,
+ eye_position: Vec3,
chunks: &azalea_world::ChunkStorage,
pick_range: f64,
) -> HitResult {
@@ -400,18 +400,18 @@ pub fn pick(
///
/// Also see [`pick`].
pub fn pick_block(
- look_direction: &LookDirection,
- eye_position: &Vec3,
+ look_direction: LookDirection,
+ eye_position: Vec3,
chunks: &azalea_world::ChunkStorage,
pick_range: f64,
) -> BlockHitResult {
let view_vector = view_vector(look_direction);
- let end_position = eye_position + &(view_vector * pick_range);
+ let end_position = eye_position + (view_vector * pick_range);
azalea_physics::clip::clip(
chunks,
ClipContext {
- from: *eye_position,
+ from: eye_position,
to: end_position,
block_shape_type: BlockShapeType::Outline,
fluid_pick_type: FluidPickType::None,
diff --git a/azalea-client/src/plugins/packet/game/mod.rs b/azalea-client/src/plugins/packet/game/mod.rs
index b2a4abc4..e1477d21 100644
--- a/azalea-client/src/plugins/packet/game/mod.rs
+++ b/azalea-client/src/plugins/packet/game/mod.rs
@@ -428,7 +428,7 @@ impl GamePacketHandler<'_> {
p.relative
.apply(&p.change, &mut position, &mut direction, &mut physics);
// old_pos is set to the current position when we're teleported
- physics.set_old_pos(&position);
+ physics.set_old_pos(*position);
// send the relevant packets
commands.trigger(SendPacketEvent::new(
@@ -828,7 +828,7 @@ impl GamePacketHandler<'_> {
&mut physics,
);
// old_pos is set to the current position when we're teleported
- physics.set_old_pos(&old_position);
+ physics.set_old_pos(old_position);
});
},
));
diff --git a/azalea-core/src/aabb.rs b/azalea-core/src/aabb.rs
index 03a754f0..09abf047 100644
--- a/azalea-core/src/aabb.rs
+++ b/azalea-core/src/aabb.rs
@@ -15,14 +15,16 @@ pub struct AABB {
pub struct ClipPointOpts<'a> {
pub t: &'a mut f64,
pub approach_dir: Option<Direction>,
- pub delta: &'a Vec3,
+ pub delta: Vec3,
pub begin: f64,
+
pub min_x: f64,
pub min_z: f64,
pub max_x: f64,
pub max_z: f64,
+
pub result_dir: Direction,
- pub start: &'a Vec3,
+ pub start: Vec3,
}
impl AABB {
@@ -51,85 +53,51 @@ impl AABB {
AABB { min, max }
}
- pub fn expand_towards(&self, other: &Vec3) -> AABB {
- let mut min_x = self.min.x;
- let mut min_y = self.min.y;
- let mut min_z = self.min.z;
-
- let mut max_x = self.max.x;
- let mut max_y = self.max.y;
- let mut max_z = self.max.z;
+ pub fn expand_towards(&self, other: Vec3) -> AABB {
+ let mut min = self.min;
+ let mut max = self.max;
if other.x < 0.0 {
- min_x += other.x;
+ min.x += other.x;
} else if other.x > 0.0 {
- max_x += other.x;
+ max.x += other.x;
}
if other.y < 0.0 {
- min_y += other.y;
+ min.y += other.y;
} else if other.y > 0.0 {
- max_y += other.y;
+ max.y += other.y;
}
if other.z < 0.0 {
- min_z += other.z;
+ min.z += other.z;
} else if other.z > 0.0 {
- max_z += other.z;
+ max.z += other.z;
}
- AABB {
- min: Vec3::new(min_x, min_y, min_z),
- max: Vec3::new(max_x, max_y, max_z),
- }
+ AABB { min, max }
}
pub fn inflate(&self, amount: Vec3) -> AABB {
- let min_x = self.min.x - amount.x;
- let min_y = self.min.y - amount.y;
- let min_z = self.min.z - amount.z;
+ let min = self.min - amount;
+ let max = self.max + amount;
- let max_x = self.max.x + amount.x;
- let max_y = self.max.y + amount.y;
- let max_z = self.max.z + amount.z;
-
- AABB {
- min: Vec3::new(min_x, min_y, min_z),
- max: Vec3::new(max_x, max_y, max_z),
- }
+ AABB { min, max }
}
pub fn inflate_all(&self, amount: f64) -> AABB {
self.inflate(Vec3::new(amount, amount, amount))
}
pub fn intersect(&self, other: &AABB) -> AABB {
- let min_x = self.min.x.max(other.min.x);
- let min_y = self.min.y.max(other.min.y);
- let min_z = self.min.z.max(other.min.z);
-
- let max_x = self.max.x.min(other.max.x);
- let max_y = self.max.y.min(other.max.y);
- let max_z = self.max.z.min(other.max.z);
-
- AABB {
- min: Vec3::new(min_x, min_y, min_z),
- max: Vec3::new(max_x, max_y, max_z),
- }
+ let min = self.min.max(other.min);
+ let max = self.max.min(other.max);
+ AABB { min, max }
}
pub fn minmax(&self, other: &AABB) -> AABB {
- let min_x = self.min.x.min(other.min.x);
- let min_y = self.min.y.min(other.min.y);
- let min_z = self.min.z.min(other.min.z);
-
- let max_x = self.max.x.max(other.max.x);
- let max_y = self.max.y.max(other.max.y);
- let max_z = self.max.z.max(other.max.z);
-
- AABB {
- min: Vec3::new(min_x, min_y, min_z),
- max: Vec3::new(max_x, max_y, max_z),
- }
+ let min = self.min.min(other.min);
+ let max = self.max.max(other.max);
+ AABB { min, max }
}
pub fn move_relative(&self, delta: Vec3) -> AABB {
@@ -147,22 +115,13 @@ impl AABB {
&& self.min.z < other.max.z
&& self.max.z > other.min.z
}
- pub fn intersects_vec3(&self, corner1: &Vec3, corner2: &Vec3) -> bool {
- self.intersects_aabb(&AABB {
- min: Vec3::new(
- corner1.x.min(corner2.x),
- corner1.y.min(corner2.y),
- corner1.z.min(corner2.z),
- ),
- max: Vec3::new(
- corner1.x.max(corner2.x),
- corner1.y.max(corner2.y),
- corner1.z.max(corner2.z),
- ),
- })
+ pub fn intersects_vec3(&self, corner1: Vec3, corner2: Vec3) -> bool {
+ let min = corner1.min(corner2);
+ let max = corner1.max(corner2);
+ self.intersects_aabb(&AABB { min, max })
}
- pub fn contains(&self, point: &Vec3) -> bool {
+ pub fn contains(&self, point: Vec3) -> bool {
point.x >= self.min.x
&& point.x < self.max.x
&& point.y >= self.min.y
@@ -178,6 +137,7 @@ impl AABB {
(x + y + z) / 3.0
}
+ #[inline]
pub fn get_size(&self, axis: Axis) -> f64 {
axis.choose(
self.max.x - self.min.x,
@@ -193,24 +153,24 @@ impl AABB {
self.deflate(Vec3::new(amount, amount, amount))
}
- pub fn clip(&self, min: &Vec3, max: &Vec3) -> Option<Vec3> {
+ pub fn clip(&self, min: Vec3, max: Vec3) -> Option<Vec3> {
let mut t = 1.0;
let delta = max - min;
- let _dir = Self::get_direction_aabb(self, min, &mut t, None, &delta)?;
- Some(min + &(delta * t))
+ let _dir = Self::get_direction_aabb(self, min, &mut t, None, delta)?;
+ Some(min + (delta * t))
}
- pub fn clip_with_from_and_to(min: &Vec3, max: &Vec3, from: &Vec3, to: &Vec3) -> Option<Vec3> {
+ pub fn clip_with_from_and_to(min: Vec3, max: Vec3, from: Vec3, to: Vec3) -> Option<Vec3> {
let mut t = 1.0;
let delta = to - from;
- let _dir = Self::get_direction(min, max, from, &mut t, None, &delta)?;
- Some(from + &(delta * t))
+ let _dir = Self::get_direction(min, max, from, &mut t, None, delta)?;
+ Some(from + (delta * t))
}
pub fn clip_iterable(
- boxes: &Vec<AABB>,
- from: &Vec3,
- to: &Vec3,
+ boxes: &[AABB],
+ from: Vec3,
+ to: Vec3,
pos: BlockPos,
) -> Option<BlockHitResult> {
let mut t = 1.0;
@@ -223,12 +183,12 @@ impl AABB {
from,
&mut t,
dir,
- &delta,
+ delta,
);
}
let dir = dir?;
Some(BlockHitResult {
- location: from + &(delta * t),
+ location: from + (delta * t),
direction: dir,
block_pos: pos,
inside: false,
@@ -239,32 +199,34 @@ impl AABB {
fn get_direction_aabb(
&self,
- from: &Vec3,
+ from: Vec3,
t: &mut f64,
dir: Option<Direction>,
- delta: &Vec3,
+ delta: Vec3,
) -> Option<Direction> {
- AABB::get_direction(&self.min, &self.max, from, t, dir, delta)
+ AABB::get_direction(self.min, self.max, from, t, dir, delta)
}
fn get_direction(
- min: &Vec3,
- max: &Vec3,
- from: &Vec3,
+ min: Vec3,
+ max: Vec3,
+ from: Vec3,
t: &mut f64,
mut dir: Option<Direction>,
- delta: &Vec3,
+ delta: Vec3,
) -> Option<Direction> {
if delta.x > EPSILON {
dir = Self::clip_point(ClipPointOpts {
t,
approach_dir: dir,
delta,
+
begin: min.x,
min_x: min.y,
max_x: max.y,
min_z: min.z,
max_z: max.z,
+
result_dir: Direction::West,
start: from,
});
@@ -273,11 +235,13 @@ impl AABB {
t,
approach_dir: dir,
delta,
+
begin: max.x,
min_x: min.y,
max_x: max.y,
min_z: min.z,
max_z: max.z,
+
result_dir: Direction::East,
start: from,
});
@@ -287,7 +251,7 @@ impl AABB {
dir = Self::clip_point(ClipPointOpts {
t,
approach_dir: dir,
- delta: &Vec3 {
+ delta: Vec3 {
x: delta.y,
y: delta.z,
z: delta.x,
@@ -298,7 +262,7 @@ impl AABB {
min_z: min.x,
max_z: max.x,
result_dir: Direction::Down,
- start: &Vec3 {
+ start: Vec3 {
x: from.y,
y: from.z,
z: from.x,
@@ -308,7 +272,7 @@ impl AABB {
dir = Self::clip_point(ClipPointOpts {
t,
approach_dir: dir,
- delta: &Vec3 {
+ delta: Vec3 {
x: delta.y,
y: delta.z,
z: delta.x,
@@ -319,7 +283,7 @@ impl AABB {
min_z: min.x,
max_z: max.x,
result_dir: Direction::Up,
- start: &Vec3 {
+ start: Vec3 {
x: from.y,
y: from.z,
z: from.x,
@@ -331,7 +295,7 @@ impl AABB {
dir = Self::clip_point(ClipPointOpts {
t,
approach_dir: dir,
- delta: &Vec3 {
+ delta: Vec3 {
x: delta.z,
y: delta.x,
z: delta.y,
@@ -342,7 +306,7 @@ impl AABB {
min_z: min.y,
max_z: max.y,
result_dir: Direction::North,
- start: &Vec3 {
+ start: Vec3 {
x: from.z,
y: from.x,
z: from.y,
@@ -352,7 +316,7 @@ impl AABB {
dir = Self::clip_point(ClipPointOpts {
t,
approach_dir: dir,
- delta: &Vec3 {
+ delta: Vec3 {
x: delta.z,
y: delta.x,
z: delta.y,
@@ -363,7 +327,7 @@ impl AABB {
min_z: min.y,
max_z: max.y,
result_dir: Direction::South,
- start: &Vec3 {
+ start: Vec3 {
x: from.z,
y: from.x,
z: from.y,
@@ -431,7 +395,7 @@ impl AABB {
axis.choose(self.min.x, self.min.y, self.min.z)
}
- pub fn collided_along_vector(&self, vector: Vec3, boxes: &Vec<AABB>) -> bool {
+ pub fn collided_along_vector(&self, vector: Vec3, boxes: &[AABB]) -> bool {
let center = self.get_center();
let new_center = center + vector;
@@ -441,11 +405,11 @@ impl AABB {
self.get_size(Axis::Y) * 0.5,
self.get_size(Axis::Z) * 0.5,
));
- if inflated.contains(&new_center) || inflated.contains(&center) {
+ if inflated.contains(new_center) || inflated.contains(center) {
return true;
}
- if inflated.clip(&center, &new_center).is_some() {
+ if inflated.clip(center, new_center).is_some() {
return true;
}
}
@@ -494,12 +458,12 @@ mod tests {
fn test_aabb_clip_iterable() {
assert_ne!(
AABB::clip_iterable(
- &vec![AABB {
+ &[AABB {
min: Vec3::new(0., 0., 0.),
max: Vec3::new(1., 1., 1.),
}],
- &Vec3::new(-1., -1., -1.),
- &Vec3::new(1., 1., 1.),
+ Vec3::new(-1., -1., -1.),
+ Vec3::new(1., 1., 1.),
BlockPos::new(0, 0, 0),
),
None
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index d6e67dc2..5a8d3e0c 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -34,7 +34,7 @@ macro_rules! vec3_impl {
/// Get the squared distance from this position to another position.
/// Equivalent to `(self - other).length_squared()`.
#[inline]
- pub fn distance_squared_to(&self, other: &Self) -> $type {
+ pub fn distance_squared_to(self, other: Self) -> $type {
(self - other).length_squared()
}
@@ -44,7 +44,7 @@ macro_rules! vec3_impl {
}
#[inline]
- pub fn horizontal_distance_squared_to(&self, other: &Self) -> $type {
+ pub fn horizontal_distance_squared_to(self, other: Self) -> $type {
(self - other).horizontal_distance_squared()
}
@@ -115,6 +115,23 @@ macro_rules! vec3_impl {
self.x * other.x + self.y * other.y + self.z * other.z
}
+ /// Make a new position with the lower coordinates for each axis.
+ pub fn min(&self, other: Self) -> Self {
+ Self {
+ x: self.x.min(other.x),
+ y: self.x.min(other.y),
+ z: self.x.min(other.z),
+ }
+ }
+ /// Make a new position with the higher coordinates for each axis.
+ pub fn max(&self, other: Self) -> Self {
+ Self {
+ x: self.x.max(other.x),
+ y: self.x.max(other.y),
+ z: self.x.max(other.z),
+ }
+ }
+
/// Replace the Y with 0.
#[inline]
pub fn xz(&self) -> Self {
@@ -298,7 +315,7 @@ impl Vec3 {
/// Get the distance from this position to another position.
/// Equivalent to `(self - other).length()`.
- pub fn distance_to(&self, other: &Self) -> f64 {
+ pub fn distance_to(self, other: Self) -> f64 {
(self - other).length()
}
@@ -382,40 +399,6 @@ impl BlockPos {
(self.x.abs() + self.y.abs() + self.z.abs()) as u32
}
- /// Make a new BlockPos with the lower coordinates for each axis.
- ///
- /// ```
- /// # use azalea_core::position::BlockPos;
- /// assert_eq!(
- /// BlockPos::min(&BlockPos::new(1, 20, 300), &BlockPos::new(50, 40, 30),),
- /// BlockPos::new(1, 20, 30),
- /// );
- /// ```
- pub fn min(&self, other: &Self) -> Self {
- Self {
- x: self.x.min(other.x),
- y: self.y.min(other.y),
- z: self.z.min(other.z),
- }
- }
-
- /// Make a new BlockPos with the higher coordinates for each axis.
- ///
- /// ```
- /// # use azalea_core::position::BlockPos;
- /// assert_eq!(
- /// BlockPos::max(&BlockPos::new(1, 20, 300), &BlockPos::new(50, 40, 30),),
- /// BlockPos::new(50, 40, 300),
- /// );
- /// ```
- pub fn max(&self, other: &Self) -> Self {
- Self {
- x: self.x.max(other.x),
- y: self.y.max(other.y),
- z: self.z.max(other.z),
- }
- }
-
pub fn offset_with_direction(self, direction: Direction) -> Self {
self + direction.normal()
}
diff --git a/azalea-entity/src/dimensions.rs b/azalea-entity/src/dimensions.rs
index 8d9a1eae..8770fa94 100644
--- a/azalea-entity/src/dimensions.rs
+++ b/azalea-entity/src/dimensions.rs
@@ -12,7 +12,7 @@ impl EntityDimensions {
Self { width, height }
}
- pub fn make_bounding_box(&self, pos: &Vec3) -> AABB {
+ pub fn make_bounding_box(&self, pos: Vec3) -> AABB {
let radius = (self.width / 2.0) as f64;
let height = self.height as f64;
AABB {
diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs
index 0058708f..cf2222d4 100644
--- a/azalea-entity/src/lib.rs
+++ b/azalea-entity/src/lib.rs
@@ -39,15 +39,15 @@ pub use crate::plugin::*;
pub fn move_relative(
physics: &mut Physics,
- direction: &LookDirection,
+ direction: LookDirection,
speed: f32,
- acceleration: &Vec3,
+ acceleration: Vec3,
) {
let input_vector = input_vector(direction, speed, acceleration);
physics.velocity += input_vector;
}
-pub fn input_vector(direction: &LookDirection, speed: f32, acceleration: &Vec3) -> Vec3 {
+pub fn input_vector(direction: LookDirection, speed: f32, acceleration: Vec3) -> Vec3 {
let distance = acceleration.length_squared();
if distance < 1.0E-7 {
return Vec3::ZERO;
@@ -55,7 +55,7 @@ pub fn input_vector(direction: &LookDirection, speed: f32, acceleration: &Vec3)
let acceleration = if distance > 1.0 {
acceleration.normalize()
} else {
- *acceleration
+ acceleration
}
.scale(speed as f64);
let y_rot = math::sin(direction.y_rot * 0.017453292f32);
@@ -67,7 +67,7 @@ pub fn input_vector(direction: &LookDirection, speed: f32, acceleration: &Vec3)
}
}
-pub fn view_vector(look_direction: &LookDirection) -> Vec3 {
+pub fn view_vector(look_direction: LookDirection) -> Vec3 {
let x_rot = look_direction.x_rot * 0.017453292;
let y_rot = -look_direction.y_rot * 0.017453292;
let y_rot_cos = math::cos(y_rot);
@@ -82,7 +82,7 @@ pub fn view_vector(look_direction: &LookDirection) -> Vec3 {
}
/// Get the position of the block below the entity, but a little lower.
-pub fn on_pos_legacy(chunk_storage: &ChunkStorage, position: &Position) -> BlockPos {
+pub fn on_pos_legacy(chunk_storage: &ChunkStorage, position: Position) -> BlockPos {
on_pos(0.2, chunk_storage, position)
}
@@ -98,7 +98,7 @@ pub fn on_pos_legacy(chunk_storage: &ChunkStorage, position: &Position) -> Block
// }
// }
// return var5;
-pub fn on_pos(offset: f32, chunk_storage: &ChunkStorage, pos: &Position) -> BlockPos {
+pub fn on_pos(offset: f32, chunk_storage: &ChunkStorage, pos: Position) -> BlockPos {
let x = pos.x.floor() as i32;
let y = (pos.y - offset as f64).floor() as i32;
let z = pos.z.floor() as i32;
@@ -323,7 +323,7 @@ impl Physics {
no_jump_delay: 0,
- bounding_box: dimensions.make_bounding_box(&pos),
+ bounding_box: dimensions.make_bounding_box(pos),
dimensions,
has_impulse: false,
@@ -375,8 +375,8 @@ impl Physics {
self.lava_fluid_height > 0.
}
- pub fn set_old_pos(&mut self, pos: &Position) {
- self.old_position = **pos;
+ pub fn set_old_pos(&mut self, pos: Position) {
+ self.old_position = *pos;
}
}
@@ -496,10 +496,10 @@ impl EntityBundle {
/// If this is for a client then all of our clients will have this.
///
/// This component is not removed from clients when they disconnect.
-#[derive(Component, Clone, Debug, Default)]
+#[derive(Component, Clone, Copy, Debug, Default)]
pub struct LocalEntity;
-#[derive(Component, Clone, Debug, PartialEq, Deref, DerefMut)]
+#[derive(Component, Clone, Copy, Debug, PartialEq, Deref, DerefMut)]
pub struct FluidOnEyes(FluidKind);
impl FluidOnEyes {
@@ -508,5 +508,5 @@ impl FluidOnEyes {
}
}
-#[derive(Component, Clone, Debug, PartialEq, Deref, DerefMut)]
+#[derive(Component, Clone, Copy, Debug, PartialEq, Deref, DerefMut)]
pub struct OnClimbable(bool);
diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs
index e64f9823..65b28a59 100644
--- a/azalea-entity/src/plugin/mod.rs
+++ b/azalea-entity/src/plugin/mod.rs
@@ -199,7 +199,7 @@ pub fn clamp_look_direction(mut query: Query<&mut LookDirection>) {
/// Cached position in the world must be updated.
pub fn update_bounding_box(mut query: Query<(&Position, &mut Physics), Changed<Position>>) {
for (position, mut physics) in query.iter_mut() {
- let bounding_box = physics.dimensions.make_bounding_box(position);
+ let bounding_box = physics.dimensions.make_bounding_box(**position);
physics.bounding_box = bounding_box;
}
}
diff --git a/azalea-physics/src/clip.rs b/azalea-physics/src/clip.rs
index 2cef15c4..8d2b5dd1 100644
--- a/azalea-physics/src/clip.rs
+++ b/azalea-physics/src/clip.rs
@@ -101,22 +101,22 @@ pub fn clip(chunk_storage: &ChunkStorage, context: ClipContext) -> BlockHitResul
let block_shape = ctx.block_shape(block_state);
let interaction_clip = clip_with_interaction_override(
- &ctx.from,
- &ctx.to,
+ ctx.from,
+ ctx.to,
block_pos,
block_shape,
- &block_state,
+ block_state,
);
let fluid_shape = ctx.fluid_shape(fluid_state, chunk_storage, block_pos);
- let fluid_clip = fluid_shape.clip(&ctx.from, &ctx.to, block_pos);
+ let fluid_clip = fluid_shape.clip(ctx.from, ctx.to, block_pos);
let distance_to_interaction = interaction_clip
.as_ref()
- .map(|hit| ctx.from.distance_squared_to(&hit.location))
+ .map(|hit| ctx.from.distance_squared_to(hit.location))
.unwrap_or(f64::MAX);
let distance_to_fluid = fluid_clip
.as_ref()
- .map(|hit| ctx.from.distance_squared_to(&hit.location))
+ .map(|hit| ctx.from.distance_squared_to(hit.location))
.unwrap_or(f64::MAX);
if distance_to_interaction <= distance_to_fluid {
@@ -137,11 +137,11 @@ pub fn clip(chunk_storage: &ChunkStorage, context: ClipContext) -> BlockHitResul
}
fn clip_with_interaction_override(
- from: &Vec3,
- to: &Vec3,
+ from: Vec3,
+ to: Vec3,
block_pos: BlockPos,
block_shape: &VoxelShape,
- _block_state: &BlockState,
+ _block_state: BlockState,
) -> Option<BlockHitResult> {
let block_hit_result = block_shape.clip(from, to, block_pos);
@@ -255,7 +255,7 @@ pub fn traverse_blocks<C, T>(
}
}
-pub fn box_traverse_blocks(from: &Vec3, to: &Vec3, aabb: &AABB) -> HashSet<BlockPos> {
+pub fn box_traverse_blocks(from: Vec3, to: Vec3, aabb: &AABB) -> HashSet<BlockPos> {
let delta = to - from;
let traversed_blocks = BlockPos::between_closed_aabb(aabb);
if delta.length_squared() < (0.99999_f32 * 0.99999) as f64 {
@@ -346,10 +346,10 @@ pub fn add_collisions_along_travel(
step_count += 1;
let Some(clip_location) = AABB::clip_with_from_and_to(
- &Vec3::new(min_x as f64, min_y as f64, min_z as f64),
- &Vec3::new((min_x + 1) as f64, (min_y + 1) as f64, (min_z + 1) as f64),
- &from,
- &to,
+ Vec3::new(min_x as f64, min_y as f64, min_z as f64),
+ Vec3::new((min_x + 1) as f64, (min_y + 1) as f64, (min_z + 1) as f64),
+ from,
+ to,
) else {
continue;
};
diff --git a/azalea-physics/src/collision/mod.rs b/azalea-physics/src/collision/mod.rs
index ef994deb..41fc6c85 100644
--- a/azalea-physics/src/collision/mod.rs
+++ b/azalea-physics/src/collision/mod.rs
@@ -35,7 +35,7 @@ pub enum MoverType {
// Entity.collide
fn collide(
- movement: &Vec3,
+ movement: Vec3,
world: &Instance,
physics: &azalea_entity::Physics,
source_entity: Option<Entity>,
@@ -51,7 +51,7 @@ fn collide(
collidable_entity_query,
);
let collided_delta = if movement.length_squared() == 0.0 {
- *movement
+ movement
} else {
collide_bounding_box(movement, &entity_bounding_box, world, &entity_collisions)
};
@@ -65,20 +65,20 @@ fn collide(
let max_up_step = 0.6;
if max_up_step > 0. && on_ground && (x_collision || z_collision) {
let mut step_to_delta = collide_bounding_box(
- &movement.with_y(max_up_step),
+ movement.with_y(max_up_step),
&entity_bounding_box,
world,
&entity_collisions,
);
let directly_up_delta = collide_bounding_box(
- &Vec3::ZERO.with_y(max_up_step),
- &entity_bounding_box.expand_towards(&Vec3::new(movement.x, 0., movement.z)),
+ Vec3::ZERO.with_y(max_up_step),
+ &entity_bounding_box.expand_towards(Vec3::new(movement.x, 0., movement.z)),
world,
&entity_collisions,
);
if directly_up_delta.y < max_up_step {
let target_movement = collide_bounding_box(
- &movement.with_y(0.),
+ movement.with_y(0.),
&entity_bounding_box.move_relative(directly_up_delta),
world,
&entity_collisions,
@@ -95,7 +95,7 @@ fn collide(
> collided_delta.horizontal_distance_squared()
{
return step_to_delta.add(collide_bounding_box(
- &Vec3::ZERO.with_y(-step_to_delta.y + movement.y),
+ Vec3::ZERO.with_y(-step_to_delta.y + movement.y),
&entity_bounding_box.move_relative(step_to_delta),
world,
&entity_collisions,
@@ -112,7 +112,7 @@ fn collide(
#[allow(clippy::too_many_arguments)]
pub fn move_colliding(
_mover_type: MoverType,
- movement: &Vec3,
+ movement: Vec3,
world: &Instance,
position: &mut Mut<azalea_entity::Position>,
physics: &mut azalea_entity::Physics,
@@ -180,7 +180,7 @@ pub fn move_colliding(
// TODO: minecraft checks for a "minor" horizontal collision here
- let _block_pos_below = azalea_entity::on_pos_legacy(&world.chunks, position);
+ let _block_pos_below = azalea_entity::on_pos_legacy(&world.chunks, **position);
// let _block_state_below = self
// .world
// .get_block_state(&block_pos_below)
@@ -239,7 +239,7 @@ pub fn move_colliding(
}
fn collide_bounding_box(
- movement: &Vec3,
+ movement: Vec3,
entity_bounding_box: &AABB,
world: &Instance,
entity_collisions: &[VoxelShape],
@@ -259,63 +259,44 @@ fn collide_bounding_box(
}
fn collide_with_shapes(
- movement: &Vec3,
+ mut movement: Vec3,
mut entity_box: AABB,
- collision_boxes: &Vec<VoxelShape>,
+ collision_boxes: &[VoxelShape],
) -> Vec3 {
if collision_boxes.is_empty() {
- return *movement;
+ return movement;
}
- let mut x_movement = movement.x;
- let mut y_movement = movement.y;
- let mut z_movement = movement.z;
- if y_movement != 0. {
- y_movement = Shapes::collide(&Axis::Y, &entity_box, collision_boxes, y_movement);
- if y_movement != 0. {
- entity_box = entity_box.move_relative(Vec3 {
- x: 0.,
- y: y_movement,
- z: 0.,
- });
+ if movement.y != 0. {
+ movement.y = Shapes::collide(Axis::Y, &entity_box, collision_boxes, movement.y);
+ if movement.y != 0. {
+ entity_box = entity_box.move_relative(Vec3::new(0., movement.y, 0.));
}
}
// whether the player is moving more in the z axis than x
// this is done to fix a movement bug, minecraft does this too
- let more_z_movement = x_movement.abs() < z_movement.abs();
-
- if more_z_movement && z_movement != 0. {
- z_movement = Shapes::collide(&Axis::Z, &entity_box, collision_boxes, z_movement);
- if z_movement != 0. {
- entity_box = entity_box.move_relative(Vec3 {
- x: 0.,
- y: 0.,
- z: z_movement,
- });
+ let more_z_movement = movement.x.abs() < movement.z.abs();
+
+ if more_z_movement && movement.z != 0. {
+ movement.z = Shapes::collide(Axis::Z, &entity_box, collision_boxes, movement.z);
+ if movement.z != 0. {
+ entity_box = entity_box.move_relative(Vec3::new(0., 0., movement.z));
}
}
- if x_movement != 0. {
- x_movement = Shapes::collide(&Axis::X, &entity_box, collision_boxes, x_movement);
- if x_movement != 0. {
- entity_box = entity_box.move_relative(Vec3 {
- x: x_movement,
- y: 0.,
- z: 0.,
- });
+ if movement.x != 0. {
+ movement.x = Shapes::collide(Axis::X, &entity_box, collision_boxes, movement.x);
+ if movement.x != 0. {
+ entity_box = entity_box.move_relative(Vec3::new(movement.x, 0., 0.));
}
}
- if !more_z_movement && z_movement != 0. {
- z_movement = Shapes::collide(&Axis::Z, &entity_box, collision_boxes, z_movement);
+ if !more_z_movement && movement.z != 0. {
+ movement.z = Shapes::collide(Axis::Z, &entity_box, collision_boxes, movement.z);
}
- Vec3 {
- x: x_movement,
- y: y_movement,
- z: z_movement,
- }
+ movement
}
/// Get the [`VoxelShape`] for the given fluid state.
diff --git a/azalea-physics/src/collision/shape.rs b/azalea-physics/src/collision/shape.rs
index 4d430ee7..9caae590 100644
--- a/azalea-physics/src/collision/shape.rs
+++ b/azalea-physics/src/collision/shape.rs
@@ -98,9 +98,9 @@ impl Shapes {
}
pub fn collide(
- axis: &Axis,
+ axis: Axis,
entity_box: &AABB,
- collision_boxes: &Vec<VoxelShape>,
+ collision_boxes: &[VoxelShape],
mut movement: f64,
) -> f64 {
for shape in collision_boxes {
@@ -408,7 +408,7 @@ impl VoxelShape {
}
}
- pub fn clip(&self, from: &Vec3, to: &Vec3, block_pos: BlockPos) -> Option<BlockHitResult> {
+ pub fn clip(&self, from: Vec3, to: Vec3, block_pos: BlockPos) -> Option<BlockHitResult> {
if self.is_empty() {
return None;
}
@@ -416,7 +416,7 @@ impl VoxelShape {
if vector.length_squared() < EPSILON {
return None;
}
- let right_after_start = from + &(vector * 0.001);
+ let right_after_start = from + (vector * 0.001);
if self.shape().is_full_wide(
self.find_index(Axis::X, right_after_start.x - block_pos.x as f64),
@@ -436,8 +436,8 @@ impl VoxelShape {
}
}
- pub fn collide(&self, axis: &Axis, entity_box: &AABB, movement: f64) -> f64 {
- self.collide_x(AxisCycle::between(*axis, Axis::X), entity_box, movement)
+ pub fn collide(&self, axis: Axis, entity_box: &AABB, movement: f64) -> f64 {
+ self.collide_x(AxisCycle::between(axis, Axis::X), entity_box, movement)
}
pub fn collide_x(&self, axis_cycle: AxisCycle, entity_box: &AABB, mut movement: f64) -> f64 {
if self.shape().is_empty() {
@@ -753,8 +753,8 @@ mod tests {
let block_shape = &*BLOCK_SHAPE;
let block_hit_result = block_shape
.clip(
- &Vec3::new(-0.3, 0.5, 0.),
- &Vec3::new(5.3, 0.5, 0.),
+ Vec3::new(-0.3, 0.5, 0.),
+ Vec3::new(5.3, 0.5, 0.),
BlockPos::new(0, 0, 0),
)
.unwrap();
diff --git a/azalea-physics/src/fluids.rs b/azalea-physics/src/fluids.rs
index 5ea6194a..ea0f12e2 100644
--- a/azalea-physics/src/fluids.rs
+++ b/azalea-physics/src/fluids.rs
@@ -32,7 +32,7 @@ pub fn update_in_water_state_and_do_fluid_pushing(
physics.water_fluid_height = 0.;
physics.lava_fluid_height = 0.;
- update_in_water_state_and_do_water_current_pushing(&mut physics, &world, position);
+ update_in_water_state_and_do_water_current_pushing(&mut physics, &world, *position);
// right now doing registries.dimension_type() clones the entire registry which
// is very inefficient, so for now we're doing this instead
@@ -63,7 +63,7 @@ pub fn update_in_water_state_and_do_fluid_pushing(
fn update_in_water_state_and_do_water_current_pushing(
physics: &mut Physics,
world: &Instance,
- _position: &Position,
+ _position: Position,
) {
// TODO: implement vehicles and boats
// if vehicle == AbstractBoat {
diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs
index 1f381174..d0db3c22 100644
--- a/azalea-physics/src/lib.rs
+++ b/azalea-physics/src/lib.rs
@@ -18,6 +18,7 @@ use azalea_entity::{
Attributes, InLoadedChunk, Jumping, LocalEntity, LookDirection, OnClimbable, Physics, Pose,
Position, metadata::Sprinting, move_relative,
};
+use azalea_registry::Block;
use azalea_world::{Instance, InstanceContainer, InstanceName};
use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
@@ -110,9 +111,9 @@ pub fn ai_step(
{
jump_from_ground(
&mut physics,
- position,
- look_direction,
- sprinting,
+ *position,
+ *look_direction,
+ *sprinting,
instance_name,
&instance_container,
);
@@ -187,11 +188,11 @@ fn check_inside_blocks(
for movement in movements {
let bounding_box_at_target = physics
.dimensions
- .make_bounding_box(&movement.to)
+ .make_bounding_box(movement.to)
.deflate_all(1.0E-5);
for traversed_block in
- box_traverse_blocks(&movement.from, &movement.to, &bounding_box_at_target)
+ box_traverse_blocks(movement.from, movement.to, &bounding_box_at_target)
{
// if (!this.isAlive()) {
// return;
@@ -221,8 +222,8 @@ fn check_inside_blocks(
if entity_inside_collision_shape != &*BLOCK_SHAPE
&& !collided_with_shape_moving_from(
- &movement.from,
- &movement.to,
+ movement.from,
+ movement.to,
traversed_block,
entity_inside_collision_shape,
physics,
@@ -241,8 +242,8 @@ fn check_inside_blocks(
}
fn collided_with_shape_moving_from(
- from: &Vec3,
- to: &Vec3,
+ from: Vec3,
+ to: Vec3,
traversed_block: BlockPos,
entity_inside_collision_shape: &VoxelShape,
physics: &Physics,
@@ -304,9 +305,9 @@ pub struct EntityMovement {
pub fn jump_from_ground(
physics: &mut Physics,
- position: &Position,
- look_direction: &LookDirection,
- sprinting: &Sprinting,
+ position: Position,
+ look_direction: LookDirection,
+ sprinting: Sprinting,
instance_name: &InstanceName,
instance_container: &InstanceContainer,
) {
@@ -322,7 +323,7 @@ pub fn jump_from_ground(
y: jump_power,
z: old_delta_movement.z,
};
- if **sprinting {
+ if *sprinting {
// sprint jumping gives some extra velocity
let y_rot = look_direction.y_rot * 0.017453292;
physics.velocity += Vec3 {
@@ -337,11 +338,11 @@ pub fn jump_from_ground(
pub fn update_old_position(mut query: Query<(&mut Physics, &Position)>) {
for (mut physics, position) in &mut query {
- physics.set_old_pos(position);
+ physics.set_old_pos(*position);
}
}
-fn get_block_pos_below_that_affects_movement(position: &Position) -> BlockPos {
+fn get_block_pos_below_that_affects_movement(position: Position) -> BlockPos {
BlockPos::new(
position.x.floor() as i32,
// TODO: this uses bounding_box.min_y instead of position.y
@@ -355,13 +356,13 @@ struct HandleRelativeFrictionAndCalculateMovementOpts<'a, 'b, 'world, 'state> {
block_friction: f32,
world: &'a Instance,
physics: &'a mut Physics,
- direction: &'a LookDirection,
+ direction: LookDirection,
position: Mut<'a, Position>,
attributes: &'a Attributes,
is_sprinting: bool,
- on_climbable: &'a OnClimbable,
- pose: Option<&'a Pose>,
- jumping: &'a Jumping,
+ on_climbable: OnClimbable,
+ pose: Option<Pose>,
+ jumping: Jumping,
entity: Entity,
physics_query: &'a PhysicsQuery<'world, 'state, 'b>,
collidable_entity_query: &'a CollidableEntityQuery<'world, 'state>,
@@ -387,18 +388,18 @@ fn handle_relative_friction_and_calculate_movement(
physics,
direction,
get_friction_influenced_speed(physics, attributes, block_friction, is_sprinting),
- &Vec3 {
- x: physics.x_acceleration as f64,
- y: physics.y_acceleration as f64,
- z: physics.z_acceleration as f64,
- },
+ Vec3::new(
+ physics.x_acceleration as f64,
+ physics.y_acceleration as f64,
+ physics.z_acceleration as f64,
+ ),
);
- physics.velocity = handle_on_climbable(physics.velocity, on_climbable, &position, world, pose);
+ physics.velocity = handle_on_climbable(physics.velocity, on_climbable, *position, world, pose);
move_colliding(
MoverType::Own,
- &physics.velocity.clone(),
+ physics.velocity,
world,
&mut position,
physics,
@@ -414,14 +415,14 @@ fn handle_relative_friction_and_calculate_movement(
// PowderSnowBlock.canEntityWalkOnPowderSnow(entity))) { var3 = new
// Vec3(var3.x, 0.2D, var3.z); }
- if physics.horizontal_collision || **jumping {
- let block_at_feet: azalea_registry::Block = world
+ if physics.horizontal_collision || *jumping {
+ let block_at_feet: Block = world
.chunks
.get_block_state((*position).into())
.unwrap_or_default()
.into();
- if **on_climbable || block_at_feet == azalea_registry::Block::PowderSnow {
+ if *on_climbable || block_at_feet == Block::PowderSnow {
physics.velocity.y = 0.2;
}
}
@@ -431,12 +432,12 @@ fn handle_relative_friction_and_calculate_movement(
fn handle_on_climbable(
velocity: Vec3,
- on_climbable: &OnClimbable,
- position: &Position,
+ on_climbable: OnClimbable,
+ position: Position,
world: &Instance,
- pose: Option<&Pose>,
+ pose: Option<Pose>,
) -> Vec3 {
- if !**on_climbable {
+ if !*on_climbable {
return velocity;
}
@@ -450,7 +451,7 @@ fn handle_on_climbable(
// sneaking on ladders/vines
if y < 0.0
- && pose.copied() == Some(Pose::Sneaking)
+ && pose == Some(Pose::Sneaking)
&& azalea_registry::Block::from(
world
.chunks
@@ -485,7 +486,7 @@ fn get_friction_influenced_speed(
/// Returns the what the entity's jump should be multiplied by based on the
/// block they're standing on.
-fn block_jump_factor(world: &Instance, position: &Position) -> f32 {
+fn block_jump_factor(world: &Instance, position: Position) -> f32 {
let block_at_pos = world.chunks.get_block_state(position.into());
let block_below = world
.chunks
@@ -513,7 +514,7 @@ fn block_jump_factor(world: &Instance, position: &Position) -> f32 {
// public double getJumpBoostPower() {
// return this.hasEffect(MobEffects.JUMP) ? (double)(0.1F *
// (float)(this.getEffect(MobEffects.JUMP).getAmplifier() + 1)) : 0.0D; }
-fn jump_power(world: &Instance, position: &Position) -> f32 {
+fn jump_power(world: &Instance, position: Position) -> f32 {
0.42 * block_jump_factor(world, position)
}
diff --git a/azalea-physics/src/travel.rs b/azalea-physics/src/travel.rs
index a442f629..dba991d5 100644
--- a/azalea-physics/src/travel.rs
+++ b/azalea-physics/src/travel.rs
@@ -73,7 +73,7 @@ pub fn travel(
&world,
entity,
&mut physics,
- &direction,
+ *direction,
position,
attributes,
sprinting,
@@ -86,13 +86,13 @@ pub fn travel(
&world,
entity,
&mut physics,
- &direction,
+ *direction,
position,
attributes,
sprinting,
- on_climbable,
+ *on_climbable,
pose,
- jumping,
+ *jumping,
&physics_query,
&collidable_entity_query,
);
@@ -106,19 +106,19 @@ fn travel_in_air(
world: &Instance,
entity: Entity,
physics: &mut Physics,
- direction: &LookDirection,
+ direction: LookDirection,
position: Mut<Position>,
attributes: &Attributes,
sprinting: Sprinting,
- on_climbable: &OnClimbable,
+ on_climbable: OnClimbable,
pose: Option<&Pose>,
- jumping: &Jumping,
+ jumping: Jumping,
physics_query: &PhysicsQuery,
collidable_entity_query: &CollidableEntityQuery,
) {
let gravity = get_effective_gravity();
- let block_pos_below = get_block_pos_below_that_affects_movement(&position);
+ let block_pos_below = get_block_pos_below_that_affects_movement(*position);
let block_state_below = world
.chunks
@@ -144,7 +144,7 @@ fn travel_in_air(
attributes,
is_sprinting: *sprinting,
on_climbable,
- pose,
+ pose: pose.copied(),
jumping,
entity,
physics_query,
@@ -177,7 +177,7 @@ fn travel_in_fluid(
world: &Instance,
entity: Entity,
physics: &mut Physics,
- direction: &LookDirection,
+ direction: LookDirection,
mut position: Mut<Position>,
attributes: &Attributes,
sprinting: Sprinting,
@@ -212,10 +212,10 @@ fn travel_in_fluid(
// waterMovementSpeed = 0.96F;
// }
- move_relative(physics, direction, speed, &acceleration);
+ move_relative(physics, direction, speed, acceleration);
move_colliding(
MoverType::Own,
- &physics.velocity.clone(),
+ physics.velocity.clone(),
world,
&mut position,
physics,
@@ -236,10 +236,10 @@ fn travel_in_fluid(
physics.velocity =
get_fluid_falling_adjusted_movement(gravity, moving_down, new_velocity, sprinting);
} else {
- move_relative(physics, direction, 0.02, &acceleration);
+ move_relative(physics, direction, 0.02, acceleration);
move_colliding(
MoverType::Own,
- &physics.velocity.clone(),
+ physics.velocity,
world,
&mut position,
physics,
diff --git a/azalea/examples/testbot/killaura.rs b/azalea/examples/testbot/killaura.rs
index 5458ea4e..586d90b2 100644
--- a/azalea/examples/testbot/killaura.rs
+++ b/azalea/examples/testbot/killaura.rs
@@ -31,7 +31,7 @@ pub fn tick(bot: Client, state: State) -> anyhow::Result<()> {
continue;
}
- let distance = bot_position.distance_to(position);
+ let distance = bot_position.distance_to(**position);
if distance < 4. && distance < nearest_distance {
nearest_entity = Some(entity_id);
nearest_distance = distance;
diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs
index 9e8566bf..745f3fdb 100644
--- a/azalea/src/bot.rs
+++ b/azalea/src/bot.rs
@@ -229,7 +229,7 @@ fn look_at_listener(
for event in events.read() {
if let Ok((position, eye_height, mut look_direction)) = query.get_mut(event.entity) {
let new_look_direction =
- direction_looking_at(&position.up(eye_height.into()), &event.position);
+ direction_looking_at(position.up(eye_height.into()), event.position);
trace!("look at {} (currently at {})", event.position, **position);
*look_direction = new_look_direction;
}
@@ -238,7 +238,7 @@ fn look_at_listener(
/// Return the look direction that would make a client at `current` be
/// looking at `target`.
-pub fn direction_looking_at(current: &Vec3, target: &Vec3) -> LookDirection {
+pub fn direction_looking_at(current: Vec3, target: Vec3) -> LookDirection {
// borrowed from mineflayer's Bot.lookAt because i didn't want to do math
let delta = target - current;
let y_rot = (PI - f64::atan2(-delta.x, -delta.z)) * (180.0 / PI);
diff --git a/azalea/src/nearest_entity.rs b/azalea/src/nearest_entity.rs
index 7ac4fff0..df54273a 100644
--- a/azalea/src/nearest_entity.rs
+++ b/azalea/src/nearest_entity.rs
@@ -69,7 +69,7 @@ where
/// multiple entities are within range, only the closest one is returned.
pub fn nearest_to_position(
&'a self,
- position: &Position,
+ position: Position,
instance_name: &InstanceName,
max_distance: f64,
) -> Option<Entity> {
@@ -81,7 +81,7 @@ where
continue;
}
- let target_distance = position.distance_to(e_pos);
+ let target_distance = position.distance_to(**e_pos);
if target_distance < min_distance {
nearest_entity = Some(target_entity);
min_distance = target_distance;
@@ -111,7 +111,7 @@ where
continue;
}
- let target_distance = position.distance_to(e_pos);
+ let target_distance = position.distance_to(**e_pos);
if target_distance < min_distance {
nearest_entity = Some(target_entity);
min_distance = target_distance;
@@ -140,7 +140,7 @@ where
return None;
}
- let distance = position.distance_to(e_pos);
+ let distance = position.distance_to(**e_pos);
if distance < max_distance {
Some((target_entity, distance))
} else {
@@ -181,7 +181,7 @@ where
return None;
}
- let distance = position.distance_to(e_pos);
+ let distance = position.distance_to(**e_pos);
if distance < max_distance {
Some((target_entity, distance))
} else {
diff --git a/azalea/src/pathfinder/debug.rs b/azalea/src/pathfinder/debug.rs
index 6b319531..d0d264d3 100644
--- a/azalea/src/pathfinder/debug.rs
+++ b/azalea/src/pathfinder/debug.rs
@@ -65,7 +65,7 @@ pub fn debug_render_path_with_particles(
let start_vec3 = start.center();
let end_vec3 = end.center();
- let step_count = (start_vec3.distance_squared_to(&end_vec3).sqrt() * 4.0) as usize;
+ let step_count = (start_vec3.distance_to(end_vec3) * 4.0) as usize;
let target_block_state = chunks.get_block_state(movement.target).unwrap_or_default();
let above_target_block_state = chunks
diff --git a/azalea/src/pathfinder/goals.rs b/azalea/src/pathfinder/goals.rs
index c19bf504..95786561 100644
--- a/azalea/src/pathfinder/goals.rs
+++ b/azalea/src/pathfinder/goals.rs
@@ -230,16 +230,16 @@ impl Goal for ReachBlockPosGoal {
}
// only do the expensive check if we're close enough
- let distance = self.pos.distance_squared_to(&n);
- if distance > self.max_check_distance.pow(2) {
+ let distance_squared = self.pos.distance_squared_to(n);
+ if distance_squared > self.max_check_distance.pow(2) {
return false;
}
let eye_position = n.center_bottom().up(1.62);
- let look_direction = crate::direction_looking_at(&eye_position, &self.pos.center());
+ let look_direction = crate::direction_looking_at(eye_position, self.pos.center());
let block_hit_result = azalea_client::interact::pick_block(
- &look_direction,
- &eye_position,
+ look_direction,
+ eye_position,
&self.chunk_storage,
self.distance,
);
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index e75c99c4..9786e1de 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -641,7 +641,7 @@ pub fn timeout_movement(
// don't timeout if we're mining
if let Some(mining) = mining {
// also make sure we're close enough to the block that's being mined
- if mining.pos.distance_squared_to(&BlockPos::from(position)) < 6_i32.pow(2) {
+ if mining.pos.distance_squared_to(position.into()) < 6_i32.pow(2) {
// also reset the last_node_reached_at so we don't timeout after we finish
// mining
executing_path.last_node_reached_at = Instant::now();