From a2606569bb79867d07a075bcf7b05730e4264d72 Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 11 Jun 2025 22:58:41 -0630 Subject: use owned instead of borrowed Vec3 more --- azalea-entity/src/dimensions.rs | 2 +- azalea-entity/src/lib.rs | 26 +++++++++++++------------- azalea-entity/src/plugin/mod.rs | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'azalea-entity/src') 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>) { 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; } } -- cgit v1.2.3