mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
make sure pathfinder is always centered on the destination block (fixes tests)
This commit is contained in:
parent
30702d94f6
commit
94ef48d9f2
4 changed files with 33 additions and 10 deletions
|
@ -53,7 +53,13 @@ impl Client {
|
|||
|
||||
/// Whether the player has an attack cooldown.
|
||||
pub fn has_attack_cooldown(&self) -> bool {
|
||||
let ticks_since_last_attack = *self.component::<AttackStrengthScale>();
|
||||
let Some(AttackStrengthScale(ticks_since_last_attack)) =
|
||||
self.get_component::<AttackStrengthScale>()
|
||||
else {
|
||||
// they don't even have an AttackStrengthScale so they probably can't attack
|
||||
// lmao, just return false
|
||||
return false;
|
||||
};
|
||||
ticks_since_last_attack < 1.0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,10 +23,14 @@ impl Client {
|
|||
/// # }
|
||||
/// ```
|
||||
pub fn query<'w, Q: WorldQuery>(&self, ecs: &'w mut World) -> <Q as WorldQuery>::Item<'w> {
|
||||
ecs.query::<Q>().get_mut(ecs, self.entity).expect(&format!(
|
||||
"Our client is missing a required component {:?}",
|
||||
std::any::type_name::<Q>()
|
||||
))
|
||||
ecs.query::<Q>()
|
||||
.get_mut(ecs, self.entity)
|
||||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"Our client is missing a required component {:?}",
|
||||
std::any::type_name::<Q>()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// Return a lightweight [`Entity`] for the entity that matches the given
|
||||
|
@ -67,10 +71,12 @@ impl Client {
|
|||
pub fn entity_component<Q: Component + Clone>(&mut self, entity: Entity) -> Q {
|
||||
let mut ecs = self.ecs.lock();
|
||||
let mut q = ecs.query::<&Q>();
|
||||
let components = q.get(&ecs, entity).expect(&format!(
|
||||
"Entity is missing a required component {:?}",
|
||||
std::any::type_name::<Q>()
|
||||
));
|
||||
let components = q.get(&ecs, entity).unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"Entity is missing a required component {:?}",
|
||||
std::any::type_name::<Q>()
|
||||
)
|
||||
});
|
||||
components.clone()
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,11 @@ macro_rules! vec3_impl {
|
|||
self.x * self.x + self.z * self.z
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn horizontal_distance_to_sqr(&self, other: &Self) -> $type {
|
||||
(self - other).horizontal_distance_sqr()
|
||||
}
|
||||
|
||||
/// Return a new instance of this position with the y coordinate
|
||||
/// decreased by the given number.
|
||||
#[inline]
|
||||
|
|
|
@ -381,7 +381,13 @@ fn tick_execute_path(
|
|||
physics,
|
||||
};
|
||||
let extra_strict_if_last = if i == pathfinder.path.len() - 1 {
|
||||
physics.on_ground && BlockPos::from(position) == movement.target
|
||||
let x_difference_from_center = position.x - (movement.target.x as f64 + 0.5);
|
||||
let z_difference_from_center = position.z - (movement.target.z as f64 + 0.5);
|
||||
// this is to make sure we don't fall off immediately after finishing the path
|
||||
physics.on_ground
|
||||
&& BlockPos::from(position) == movement.target
|
||||
&& x_difference_from_center.abs() < 0.2
|
||||
&& z_difference_from_center.abs() < 0.2
|
||||
} else {
|
||||
true
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue