diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 02625326..f73e939b 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -338,13 +338,6 @@ impl Client { /// Similar to [`Self::get_component`], but doesn't clone the component /// since it's passed as a reference. [`Self::ecs`] will remain locked /// while the callback is being run. - /// - /// ``` - /// # use azalea_client::{Client, mining::Mining}; - /// # fn example(bot: &Client) { - /// let is_mining = bot.map_get_component::(|m| m).is_some(); - /// # } - /// ``` pub fn map_get_component(&self, f: impl FnOnce(&T) -> R) -> Option { let mut ecs = self.ecs.lock(); let value = self.query::>(&mut ecs); diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs index ad225400..0f33e01e 100644 --- a/azalea-entity/src/lib.rs +++ b/azalea-entity/src/lib.rs @@ -455,7 +455,12 @@ impl EntityBundle { world_name: ResourceLocation, ) -> Self { let dimensions = EntityDimensions::from(kind); - let eye_height = dimensions.height * 0.85; + let eye_height = match kind { + // TODO: codegen hardcoded eye heights, search withEyeHeight with mojmap + // also, eye height should change depending on pose (like sneaking, swimming, etc) + azalea_registry::EntityKind::Player => 1.62, + _ => dimensions.height * 0.85, + }; Self { kind: EntityKind(kind), diff --git a/azalea-physics/src/collision/shape.rs b/azalea-physics/src/collision/shape.rs index e27e4c2a..902ae20c 100644 --- a/azalea-physics/src/collision/shape.rs +++ b/azalea-physics/src/collision/shape.rs @@ -399,17 +399,8 @@ impl VoxelShape { } pub fn find_index(&self, axis: Axis, coord: f64) -> i32 { - // let r = binary_search(0, (self.shape().size(axis) + 1) as i32, &|t| { - // coord < self.get(axis, t as usize) - // }) - 1; - // r - match self { - VoxelShape::Cube(s) => s.find_index(axis, coord), - _ => { - let upper_limit = (self.shape().size(axis) + 1) as i32; - binary_search(0, upper_limit, |t| coord < self.get(axis, t as usize)) - 1 - } - } + let upper_limit = (self.shape().size(axis) + 1) as i32; + binary_search(0, upper_limit, |t| coord < self.get(axis, t as usize)) - 1 } pub fn clip(&self, from: &Vec3, to: &Vec3, block_pos: &BlockPos) -> Option { @@ -420,7 +411,7 @@ impl VoxelShape { if vector.length_squared() < EPSILON { return None; } - let right_after_start = from + &(vector * 0.0001); + 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), @@ -645,7 +636,6 @@ impl ArrayVoxelShape { impl CubeVoxelShape { pub fn new(shape: DiscreteVoxelShape) -> Self { - // pre-calculate the coor let x_coords = Self::calculate_coords(&shape, Axis::X); let y_coords = Self::calculate_coords(&shape, Axis::Y); let z_coords = Self::calculate_coords(&shape, Axis::Z); @@ -679,10 +669,11 @@ impl CubeVoxelShape { axis.choose(&self.x_coords, &self.y_coords, &self.z_coords) } - fn find_index(&self, axis: Axis, coord: f64) -> i32 { - let n = self.shape().size(axis); - (f64::clamp(coord * (n as f64), -1f64, n as f64)) as i32 - } + // unused + // fn find_index(&self, axis: Axis, coord: f64) -> i32 { + // let n = self.shape().size(axis); + // (f64::clamp(coord * (n as f64), -1f64, n as f64)) as i32 + // } } #[derive(Debug)] @@ -752,4 +743,32 @@ mod tests { let joined = Shapes::matches_anywhere(&shape, &shape2, |a, b| a && b); assert!(joined, "Shapes should intersect"); } + + #[test] + fn clip_in_front_of_block() { + 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.), + &BlockPos::new(0, 0, 0), + ) + .unwrap(); + + assert_eq!( + block_hit_result, + BlockHitResult { + location: Vec3 { + x: 0.0, + y: 0.5, + z: 0.0 + }, + direction: Direction::West, + block_pos: BlockPos { x: 0, y: 0, z: 0 }, + inside: false, + world_border: false, + miss: false + } + ); + } } diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index b05d2aab..c4586d29 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -1569,7 +1569,7 @@ mod tests { simulation.app.world_mut().send_event(GotoEvent { entity: simulation.entity, - goal: Arc::new(BlockPosGoal(BlockPos::new(0, 70, 0))), + goal: Arc::new(BlockPosGoal(BlockPos::new(0, 69, 0))), successors_fn: moves::default_move, allow_mining: true, min_timeout: PathfinderTimeout::Nodes(1_000_000),