class Rosegold::ContainerHandle

Overview

User-facing handle for interacting with an open container. Wraps a Menu and provides intent-level operations (withdraw, deposit) as well as item-level operations (pickup, put_down, move, swap). Auto-closes via ensure when used with a block.

Defined in:

rosegold/inventory/container_handle.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(client : Rosegold::Client, menu : Rosegold::Menu) #

Wraps an already-open menu. Prefer Bot#open_container_handle, which waits for opening and closes the handle in an ensure block.


[View source]

Instance Method Detail

def as_anvil : AnvilMenu | Nil #

Returns the menu as an anvil, or nil when it is another type.


[View source]
def as_brewing_stand : BrewingStandMenu | Nil #

Returns the menu as a brewing stand, or nil when it is another type.


[View source]
def as_chest : ChestMenu | Nil #

Returns the menu as a chest, or nil when the open menu is another type.


[View source]
def as_crafting : CraftingMenu | Nil #

Returns the menu as a crafting table, or nil when it is another type.


[View source]
def as_enchantment : EnchantmentMenu | Nil #

Returns the menu as an enchanting table, or nil when it is another type.


[View source]
def as_furnace : FurnaceMenu | Nil #

Returns the menu as a furnace, or nil when it is another type.


[View source]
def as_hopper : HopperMenu | Nil #

Returns the menu as a hopper, or nil when it is another type.


[View source]
def as_merchant : MerchantMenu | Nil #

Returns the menu as a merchant, or nil when it is another type.


[View source]
def close #

Closes the wrapped menu. It queues the close packet without waiting for a later player-inventory update.


[View source]
def count_in_container(spec) : Int32 #

Count matching items in the container.


[View source]
def count_in_player(spec) : Int32 #

Count matching items in the player inventory.


[View source]
def deposit(spec, count : Int32 = Int32::MAX) : Int32 #

Transfer items from player inventory to container via shift-click. Stops once at least count items have moved, or no progress is possible. Whole stacks are shift-clicked, so the result may exceed count. Returns the item-count change observed in the local menu, not a server acknowledgment.


[View source]
def drop(slot : Int32, full_stack : Bool = false) #

Drop items from a slot.


[View source]
def find_in_container(spec) : WindowSlot | Nil #

Find the first slot matching spec in the container.


[View source]
def find_in_inventory(spec) : WindowSlot | Nil #

Find the first slot matching spec in the player inventory.


[View source]
def menu : Menu #

The active server menu wrapped by this handle.


[View source]
def pickup(slot : Int32, count : Int32 = Int32::MAX) #

Pick up items from a slot into the cursor. Uses left-click for full stack, right-click for half.


[View source]
def put_down(slot : Int32, count : Int32 = Int32::MAX) #

Put down items from cursor into a slot. Left-click places all, right-click places one.


[View source]
def quick_move(slot : Int32) #

Shift-click a slot (moves items between container and player inventory).


[View source]
def swap_with_hotbar(slot : Int32, hotbar_slot : Int32) #

Swap a slot with a hotbar slot (number keys 1-9).


[View source]
def swap_with_offhand(slot : Int32) #

Swap a slot with the offhand (F key).


[View source]
def withdraw(spec, count : Int32 = Int32::MAX) : Int32 #

Transfer items from container to player inventory via shift-click. Stops once at least count items have moved, or no progress is possible. Whole stacks are shift-clicked, so the result may exceed count. Returns the item-count change observed in the local menu, not a server acknowledgment.


[View source]