diff options
| author | mat <git@matdoes.dev> | 2025-06-03 03:48:36 +0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-06-03 03:48:36 +0500 |
| commit | abf995a70245028f9cc860ee231dc671f14adfcc (patch) | |
| tree | 3e6052c028c409e4bc7279dbd2e6bcc6bed63748 /azalea/src/container.rs | |
| parent | 04dd6dd0a44faa760906bd60c9861a1b06a664a1 (diff) | |
| download | azalea-drasl-abf995a70245028f9cc860ee231dc671f14adfcc.tar.xz | |
replace wait_one_tick with wait_ticks and some other api improvements
Diffstat (limited to 'azalea/src/container.rs')
| -rw-r--r-- | azalea/src/container.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/azalea/src/container.rs b/azalea/src/container.rs index 6715cd63..e5896d8a 100644 --- a/azalea/src/container.rs +++ b/azalea/src/container.rs @@ -6,7 +6,10 @@ use azalea_client::{ packet::game::ReceiveGamePacketEvent, }; use azalea_core::position::BlockPos; -use azalea_inventory::{ItemStack, Menu, operations::ClickOperation}; +use azalea_inventory::{ + ItemStack, Menu, + operations::{ClickOperation, PickupClick, QuickMoveClick}, +}; use azalea_protocol::packets::game::ClientboundGamePacket; use bevy_app::{App, Plugin, Update}; use bevy_ecs::{component::Component, prelude::EventReader, system::Commands}; @@ -27,6 +30,7 @@ pub trait ContainerClientExt { pos: BlockPos, ) -> impl Future<Output = Option<ContainerHandle>> + Send; fn open_inventory(&self) -> Option<ContainerHandle>; + fn get_held_item(&self) -> ItemStack; fn get_open_container(&self) -> Option<ContainerHandleRef>; } @@ -93,6 +97,14 @@ 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() + } + /// Get a handle to the open container. This will return None if no /// container is open. This will not close the container when it's dropped. /// @@ -228,6 +240,25 @@ impl ContainerHandle { pub fn click(&self, operation: impl Into<ClickOperation>) { self.0.click(operation); } + + /// A shortcut for [`Self::click`] with `PickupClick::Left`. + pub fn left_click(&self, slot: impl Into<usize>) { + self.click(PickupClick::Left { + slot: Some(slot.into() as u16), + }); + } + /// A shortcut for [`Self::click`] with `QuickMoveClick::Left`. + pub fn shift_click(&self, slot: impl Into<usize>) { + self.click(QuickMoveClick::Left { + slot: slot.into() as u16, + }); + } + /// A shortcut for [`Self::click`] with `PickupClick::Right`. + pub fn right_click(&self, slot: impl Into<usize>) { + self.click(PickupClick::Right { + slot: Some(slot.into() as u16), + }); + } } #[derive(Component, Debug)] |
