From f3a5e91a8ccbcd03a239aa3565dbfddabb26fa76 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 3 Jun 2025 09:52:30 +0930 Subject: fix issues when pathfinding to non-full blocks and add Client::view_inventory --- azalea/src/container.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'azalea/src/container.rs') 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; fn get_held_item(&self) -> ItemStack; fn get_open_container(&self) -> Option; + 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::(self.entity).expect("no inventory"); - inventory.held_item() + self.map_get_component::(|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_menu.clone()) + .expect("no inventory") + } } /// A handle to a container that may be open. This does not close the container -- cgit v1.2.3