From abf995a70245028f9cc860ee231dc671f14adfcc Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 3 Jun 2025 03:48:36 +0500 Subject: replace wait_one_tick with wait_ticks and some other api improvements --- azalea/src/container.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'azalea/src/container.rs') 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> + Send; fn open_inventory(&self) -> Option; + fn get_held_item(&self) -> ItemStack; fn get_open_container(&self) -> Option; } @@ -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::(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) { self.0.click(operation); } + + /// A shortcut for [`Self::click`] with `PickupClick::Left`. + pub fn left_click(&self, slot: impl Into) { + 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) { + 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) { + self.click(PickupClick::Right { + slot: Some(slot.into() as u16), + }); + } } #[derive(Component, Debug)] -- cgit v1.2.3