aboutsummaryrefslogtreecommitdiff
path: root/azalea
diff options
context:
space:
mode:
Diffstat (limited to 'azalea')
-rw-r--r--azalea/src/container.rs15
-rw-r--r--azalea/src/pathfinder/goals.rs8
-rw-r--r--azalea/src/pathfinder/mod.rs16
3 files changed, 27 insertions, 12 deletions
diff --git a/azalea/src/container.rs b/azalea/src/container.rs
index e5896d8a..da3ddb8a 100644
--- a/azalea/src/container.rs
+++ b/azalea/src/container.rs
@@ -32,6 +32,7 @@ pub trait ContainerClientExt {
fn open_inventory(&self) -> Option<ContainerHandle>;
fn get_held_item(&self) -> ItemStack;
fn get_open_container(&self) -> Option<ContainerHandleRef>;
+ fn view_inventory(&self) -> Menu;
}
impl ContainerClientExt for Client {
@@ -100,9 +101,8 @@ impl ContainerClientExt for Client {
/// Get the item in the bot's hotbar that is currently being held in its
/// main hand.
fn get_held_item(&self) -> ItemStack {
- let ecs = self.ecs.lock();
- let inventory = ecs.get::<Inventory>(self.entity).expect("no inventory");
- inventory.held_item()
+ self.map_get_component::<Inventory, _>(|inventory| inventory.held_item())
+ .expect("no inventory")
}
/// Get a handle to the open container. This will return None if no
@@ -123,6 +123,15 @@ impl ContainerClientExt for Client {
})
}
}
+
+ /// Returns the player's inventory menu.
+ ///
+ /// This is a shortcut for accessing the client's
+ /// [`Inventory::inventory_menu`].
+ fn view_inventory(&self) -> Menu {
+ self.map_get_component::<Inventory, _>(|inventory| inventory.inventory_menu.clone())
+ .expect("no inventory")
+ }
}
/// A handle to a container that may be open. This does not close the container
diff --git a/azalea/src/pathfinder/goals.rs b/azalea/src/pathfinder/goals.rs
index 5ab969c9..36fca762 100644
--- a/azalea/src/pathfinder/goals.rs
+++ b/azalea/src/pathfinder/goals.rs
@@ -29,7 +29,9 @@ impl Goal for BlockPosGoal {
xz_heuristic(dx, dz) + y_heuristic(dy)
}
fn success(&self, n: BlockPos) -> bool {
- n == self.0
+ // the second half of this condition is intended to fix issues when pathing to
+ // non-full blocks
+ n == self.0 || n.down(1) == self.0
}
}
@@ -219,8 +221,8 @@ impl Goal for ReachBlockPosGoal {
}
fn success(&self, n: BlockPos) -> bool {
// only do the expensive check if we're close enough
- let distance = (self.pos - n).length_squared();
- if distance > self.max_check_distance * self.max_check_distance {
+ let distance = self.pos.distance_squared_to(&n);
+ if distance > self.max_check_distance.pow(2) {
return false;
}
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index 5ee56643..b05d2aab 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -274,10 +274,8 @@ impl PathfinderClientExt for azalea_client::Client {
}
fn is_goto_target_reached(&self) -> bool {
- self.map_get_component::<Pathfinder, _>(|p| {
- p.map(|p| p.goal.is_none() && !p.is_calculating)
- .unwrap_or(true)
- })
+ self.map_get_component::<Pathfinder, _>(|p| p.goal.is_none() && !p.is_calculating)
+ .unwrap_or(true)
}
}
@@ -689,7 +687,12 @@ pub fn timeout_movement(
let world_lock = instance_container
.get(instance_name)
.expect("Entity tried to pathfind but the entity isn't in a valid world");
- let successors_fn: moves::SuccessorsFn = pathfinder.successors_fn.unwrap();
+ let Some(successors_fn) = pathfinder.successors_fn else {
+ warn!(
+ "pathfinder was going to patch path because of timeout, but there was no successors_fn"
+ );
+ return;
+ };
let custom_state = custom_state.cloned().unwrap_or_default();
@@ -749,7 +752,8 @@ pub fn check_node_reached(
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
+ // 0.5 to handle non-full blocks
+ && BlockPos::from(position.up(0.5)) == movement.target
// adding the delta like this isn't a perfect solution but it helps to make
// sure we don't keep going if our delta is high
&& (x_difference_from_center + physics.velocity.x).abs() < 0.2