ContainerClientExt

Trait ContainerClientExt 

Source
pub trait ContainerClientExt {
    // Required methods
    fn open_container_at(
        &self,
        pos: BlockPos,
    ) -> impl Future<Output = Option<ContainerHandle>> + Send;
    fn open_container_at_with_timeout_ticks(
        &self,
        pos: BlockPos,
        timeout_ticks: Option<usize>,
    ) -> impl Future<Output = Option<ContainerHandle>> + Send;
    fn wait_for_container_open(
        &self,
        timeout_ticks: Option<usize>,
    ) -> impl Future<Output = Option<ContainerHandle>> + Send;
    fn open_inventory(&self) -> Option<ContainerHandle>;
    fn get_inventory(&self) -> ContainerHandleRef;
    fn get_held_item(&self) -> ItemStack;
}

Required Methods§

Source

fn open_container_at( &self, pos: BlockPos, ) -> impl Future<Output = Option<ContainerHandle>> + Send

Open a container in the world, like a chest.

Use Client::open_inventory to open your own inventory.

This function times out after 5 seconds (100 ticks). Use Self::open_container_at_with_timeout_ticks if you would like to configure this.

let target_pos = bot
    .world()
    .read()
    .find_block(bot.position(), &BlockKind::Chest.into());
let Some(target_pos) = target_pos else {
    bot.chat("no chest found");
    return;
};
let container = bot.open_container_at(target_pos).await;
Source

fn open_container_at_with_timeout_ticks( &self, pos: BlockPos, timeout_ticks: Option<usize>, ) -> impl Future<Output = Option<ContainerHandle>> + Send

Open a container in the world, or time out after a specified amount of ticks.

See Self::open_container_at for more information. That function defaults to a timeout of 5 seconds (100 ticks), which is usually good enough. However to detect failures faster or to account for server lag, you may find it useful to adjust the timeout to a different value.

The timeout is measured in game ticks (on the client, not the server), i.e. 1/20th of a second.

Source

fn wait_for_container_open( &self, timeout_ticks: Option<usize>, ) -> impl Future<Output = Option<ContainerHandle>> + Send

Wait until a container is open, up to the specified number of ticks.

Returns None if the container was immediately opened and closed, or if the timeout expired.

If timeout_ticks is None, there will be no timeout.

Source

fn open_inventory(&self) -> Option<ContainerHandle>

Open the player’s inventory.

This will return None if another container is open.

Note that this will send a packet to the server once it’s dropped. Also, due to how it’s implemented, you could call this function multiple times while another inventory handle already exists (but you shouldn’t).

If you just want to get the items in the player’s inventory without sending any packets, use Client::menu, Menu::player_slots_range, and Menu::slots.

Source

fn get_inventory(&self) -> ContainerHandleRef

Returns a ContainerHandleRef to the client’s currently open container, or their inventory.

This will not send a packet to close the container when it’s dropped, which may cause anticheat compatibility issues if you modify your inventory without closing it afterwards.

To simulate opening your own inventory (like pressing ‘e’) in a way that won’t trigger anticheats, use Client::open_inventory.

To open a container in the world, use Client::open_container_at.

Source

fn get_held_item(&self) -> ItemStack

Get the item in the bot’s hotbar that is currently being held in its main hand.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§