diff options
| author | mat <git@matdoes.dev> | 2025-06-11 16:55:33 +1100 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-06-11 16:55:33 +1100 |
| commit | 9b0bd29db4faa9d94df0cec472346b814e7efcb9 (patch) | |
| tree | 4f681b5143eb5ebe69a0b5b53125ea7509f8026a /azalea-physics | |
| parent | 2a6ac0764fe9975f9b16d495ce773e4ae1f097e0 (diff) | |
| download | azalea-drasl-9b0bd29db4faa9d94df0cec472346b814e7efcb9.tar.xz | |
take BlockPos instead of &BlockPos in all function arguments
Diffstat (limited to 'azalea-physics')
| -rw-r--r-- | azalea-physics/src/clip.rs | 10 | ||||
| -rw-r--r-- | azalea-physics/src/collision/mod.rs | 8 | ||||
| -rw-r--r-- | azalea-physics/src/collision/shape.rs | 6 | ||||
| -rw-r--r-- | azalea-physics/src/fluids.rs | 10 | ||||
| -rw-r--r-- | azalea-physics/src/lib.rs | 14 | ||||
| -rw-r--r-- | azalea-physics/src/travel.rs | 6 | ||||
| -rw-r--r-- | azalea-physics/tests/physics.rs | 12 |
7 files changed, 31 insertions, 35 deletions
diff --git a/azalea-physics/src/clip.rs b/azalea-physics/src/clip.rs index e7d203d8..2cef15c4 100644 --- a/azalea-physics/src/clip.rs +++ b/azalea-physics/src/clip.rs @@ -49,7 +49,7 @@ impl ClipContext { &self, fluid_state: FluidState, world: &ChunkStorage, - pos: &BlockPos, + pos: BlockPos, ) -> &VoxelShape { if self.fluid_pick_type.can_pick(&fluid_state) { crate::collision::fluid_shape(&fluid_state, world, pos) @@ -139,7 +139,7 @@ pub fn clip(chunk_storage: &ChunkStorage, context: ClipContext) -> BlockHitResul fn clip_with_interaction_override( from: &Vec3, to: &Vec3, - block_pos: &BlockPos, + block_pos: BlockPos, block_shape: &VoxelShape, _block_state: &BlockState, ) -> Option<BlockHitResult> { @@ -168,7 +168,7 @@ pub fn traverse_blocks<C, T>( from: Vec3, to: Vec3, context: C, - get_hit_result: impl Fn(&C, &BlockPos) -> Option<T>, + get_hit_result: impl Fn(&C, BlockPos) -> Option<T>, get_miss_result: impl Fn(&C) -> T, ) -> T { if from == to { @@ -188,7 +188,7 @@ pub fn traverse_blocks<C, T>( }; let mut current_block = BlockPos::from(right_before_start); - if let Some(data) = get_hit_result(&context, ¤t_block) { + if let Some(data) = get_hit_result(&context, current_block) { return data; } @@ -249,7 +249,7 @@ pub fn traverse_blocks<C, T>( percentage.z += percentage_step.z; } - if let Some(data) = get_hit_result(&context, ¤t_block) { + if let Some(data) = get_hit_result(&context, current_block) { return data; } } diff --git a/azalea-physics/src/collision/mod.rs b/azalea-physics/src/collision/mod.rs index 2e46970d..ef994deb 100644 --- a/azalea-physics/src/collision/mod.rs +++ b/azalea-physics/src/collision/mod.rs @@ -322,13 +322,9 @@ fn collide_with_shapes( /// /// The instance and position are required so it can check if the block above is /// also the same fluid type. -pub fn fluid_shape( - fluid: &FluidState, - world: &ChunkStorage, - pos: &BlockPos, -) -> &'static VoxelShape { +pub fn fluid_shape(fluid: &FluidState, world: &ChunkStorage, pos: BlockPos) -> &'static VoxelShape { if fluid.amount == 9 { - let fluid_state_above = world.get_fluid_state(&pos.up(1)).unwrap_or_default(); + let fluid_state_above = world.get_fluid_state(pos.up(1)).unwrap_or_default(); if fluid_state_above.kind == fluid.kind { return &BLOCK_SHAPE; } diff --git a/azalea-physics/src/collision/shape.rs b/azalea-physics/src/collision/shape.rs index 59671622..4d430ee7 100644 --- a/azalea-physics/src/collision/shape.rs +++ b/azalea-physics/src/collision/shape.rs @@ -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; } @@ -424,7 +424,7 @@ impl VoxelShape { self.find_index(Axis::Z, right_after_start.z - block_pos.z as f64), ) { Some(BlockHitResult { - block_pos: *block_pos, + block_pos, direction: Direction::nearest(vector).opposite(), location: right_after_start, inside: true, @@ -755,7 +755,7 @@ mod tests { .clip( &Vec3::new(-0.3, 0.5, 0.), &Vec3::new(5.3, 0.5, 0.), - &BlockPos::new(0, 0, 0), + BlockPos::new(0, 0, 0), ) .unwrap(); diff --git a/azalea-physics/src/fluids.rs b/azalea-physics/src/fluids.rs index c4716a27..5ea6194a 100644 --- a/azalea-physics/src/fluids.rs +++ b/azalea-physics/src/fluids.rs @@ -116,7 +116,7 @@ fn update_fluid_height_and_do_fluid_pushing( for cur_y in min_y..max_y { for cur_z in min_z..max_z { let cur_pos = BlockPos::new(cur_x, cur_y, cur_z); - let Some(fluid_at_cur_pos) = world.get_fluid_state(&cur_pos) else { + let Some(fluid_at_cur_pos) = world.get_fluid_state(cur_pos) else { continue; }; if fluid_at_cur_pos.kind != checking_fluid { @@ -192,7 +192,7 @@ pub fn get_fluid_flow(fluid: &FluidState, world: &Instance, pos: BlockPos) -> Ve let adjacent_block_pos = pos.offset_with_direction(direction); let adjacent_block_state = world - .get_block_state(&adjacent_block_pos) + .get_block_state(adjacent_block_pos) .unwrap_or_default(); let adjacent_fluid_state = FluidState::from(adjacent_block_state); @@ -206,7 +206,7 @@ pub fn get_fluid_flow(fluid: &FluidState, world: &Instance, pos: BlockPos) -> Ve if !legacy_blocks_motion(adjacent_block_state) { let block_pos_below_adjacent = adjacent_block_pos.down(1); let fluid_below_adjacent = world - .get_fluid_state(&block_pos_below_adjacent) + .get_fluid_state(block_pos_below_adjacent) .unwrap_or_default(); if fluid.affects_flow(&fluid_below_adjacent) { @@ -250,8 +250,8 @@ fn is_solid_face( adjacent_pos: BlockPos, direction: Direction, ) -> bool { - let block_state = world.get_block_state(&adjacent_pos).unwrap_or_default(); - let fluid_state = world.get_fluid_state(&adjacent_pos).unwrap_or_default(); + let block_state = world.get_block_state(adjacent_pos).unwrap_or_default(); + let fluid_state = world.get_fluid_state(adjacent_pos).unwrap_or_default(); if fluid_state.is_same_kind(fluid) { return false; } diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index f384a90f..1f381174 100644 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -8,7 +8,7 @@ pub mod travel; use std::collections::HashSet; -use azalea_block::{BlockTrait, BlockState, fluid_state::FluidState, properties}; +use azalea_block::{BlockState, BlockTrait, fluid_state::FluidState, properties}; use azalea_core::{ math, position::{BlockPos, Vec3}, @@ -197,7 +197,7 @@ fn check_inside_blocks( // return; // } - let traversed_block_state = world.get_block_state(&traversed_block).unwrap_or_default(); + let traversed_block_state = world.get_block_state(traversed_block).unwrap_or_default(); if traversed_block_state.is_air() { continue; } @@ -268,7 +268,7 @@ fn handle_entity_inside_block( #[allow(clippy::single_match)] match registry_block { azalea_registry::Block::BubbleColumn => { - let block_above = world.get_block_state(&block_pos.up(1)).unwrap_or_default(); + let block_above = world.get_block_state(block_pos.up(1)).unwrap_or_default(); let is_block_above_empty = block_above.is_collision_shape_empty() && FluidState::from(block_above).is_empty(); let drag_down = block @@ -417,7 +417,7 @@ fn handle_relative_friction_and_calculate_movement( if physics.horizontal_collision || **jumping { let block_at_feet: azalea_registry::Block = world .chunks - .get_block_state(&(*position).into()) + .get_block_state((*position).into()) .unwrap_or_default() .into(); @@ -454,7 +454,7 @@ fn handle_on_climbable( && azalea_registry::Block::from( world .chunks - .get_block_state(&position.into()) + .get_block_state(position.into()) .unwrap_or_default(), ) != azalea_registry::Block::Scaffolding { @@ -486,10 +486,10 @@ 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 { - let block_at_pos = world.chunks.get_block_state(&position.into()); + let block_at_pos = world.chunks.get_block_state(position.into()); let block_below = world .chunks - .get_block_state(&get_block_pos_below_that_affects_movement(position)); + .get_block_state(get_block_pos_below_that_affects_movement(position)); let block_at_pos_jump_factor = if let Some(block) = block_at_pos { Box::<dyn BlockTrait>::from(block).behavior().jump_factor diff --git a/azalea-physics/src/travel.rs b/azalea-physics/src/travel.rs index 741267c2..a442f629 100644 --- a/azalea-physics/src/travel.rs +++ b/azalea-physics/src/travel.rs @@ -1,4 +1,4 @@ -use azalea_block::{BlockTrait, BlockState, fluid_state::FluidState}; +use azalea_block::{BlockState, BlockTrait, fluid_state::FluidState}; use azalea_core::{ aabb::AABB, position::{BlockPos, Vec3}, @@ -122,7 +122,7 @@ fn travel_in_air( let block_state_below = world .chunks - .get_block_state(&block_pos_below) + .get_block_state(block_pos_below) .unwrap_or(BlockState::AIR); let block_below: Box<dyn BlockTrait> = block_state_below.into(); let block_friction = block_below.behavior().friction; @@ -392,7 +392,7 @@ fn contains_any_liquid(world: &Instance, bounding_box: AABB) -> bool { for z in min.z..max.z { let block_state = world .chunks - .get_block_state(&BlockPos::new(x, y, z)) + .get_block_state(BlockPos::new(x, y, z)) .unwrap_or_default(); if !FluidState::from(block_state).is_empty() { return true; diff --git a/azalea-physics/tests/physics.rs b/azalea-physics/tests/physics.rs index ebe1cfad..8150e5b0 100644 --- a/azalea-physics/tests/physics.rs +++ b/azalea-physics/tests/physics.rs @@ -121,7 +121,7 @@ fn test_collision() { )) .id(); let block_state = partial_world.chunks.set_block_state( - &BlockPos { x: 0, y: 69, z: 0 }, + BlockPos { x: 0, y: 69, z: 0 }, azalea_registry::Block::Stone.into(), &world_lock.write().chunks, ); @@ -177,7 +177,7 @@ fn test_slab_collision() { )) .id(); let block_state = partial_world.chunks.set_block_state( - &BlockPos { x: 0, y: 69, z: 0 }, + BlockPos { x: 0, y: 69, z: 0 }, azalea_block::blocks::StoneSlab { kind: azalea_block::properties::Type::Bottom, waterlogged: false, @@ -227,7 +227,7 @@ fn test_top_slab_collision() { )) .id(); let block_state = world_lock.write().chunks.set_block_state( - &BlockPos { x: 0, y: 69, z: 0 }, + BlockPos { x: 0, y: 69, z: 0 }, azalea_block::blocks::StoneSlab { kind: azalea_block::properties::Type::Top, waterlogged: false, @@ -284,7 +284,7 @@ fn test_weird_wall_collision() { )) .id(); let block_state = world_lock.write().chunks.set_block_state( - &BlockPos { x: 0, y: 69, z: 0 }, + BlockPos { x: 0, y: 69, z: 0 }, azalea_block::blocks::CobblestoneWall { east: azalea_block::properties::WallEast::Low, north: azalea_block::properties::WallNorth::Low, @@ -346,7 +346,7 @@ fn test_negative_coordinates_weird_wall_collision() { )) .id(); let block_state = world_lock.write().chunks.set_block_state( - &BlockPos { + BlockPos { x: -8, y: 69, z: -8, @@ -440,7 +440,7 @@ fn test_afk_pool() { world_lock .write() .chunks - .set_block_state(&BlockPos { x, y, z }, b); + .set_block_state(BlockPos { x, y, z }, b); }; let stone = azalea_block::blocks::Stone {}.into(); |
