aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/container.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-03 09:52:30 +0930
committermat <git@matdoes.dev>2025-06-03 09:52:30 +0930
commitf3a5e91a8ccbcd03a239aa3565dbfddabb26fa76 (patch)
treeb9f34dda5ba68bbfc4159dd1631455c8dd84e2ad /azalea/src/container.rs
parent7517a207db658c98d5b97b3b3f44df6725c025a2 (diff)
downloadazalea-drasl-f3a5e91a8ccbcd03a239aa3565dbfddabb26fa76.tar.xz
fix issues when pathfinding to non-full blocks and add Client::view_inventory
Diffstat (limited to 'azalea/src/container.rs')
-rw-r--r--azalea/src/container.rs15
1 files changed, 12 insertions, 3 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