class
Rosegold::Inventory
- Rosegold::Inventory
- Reference
- Object
Overview
Utility methods for interacting with the open window.
Defined in:
rosegold/control/inventory.crConstructors
-
.new(client : Rosegold::Client)
Creates an inventory facade over the client's currently active menu.
Macro Summary
-
method_missing(call)
Forwards unrecognized menu accessors to the active
Client#container_menu.
Instance Method Summary
-
#boots(*args, **options)
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
-
#boots(*args, **options, &)
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
-
#chestplate(*args, **options)
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
-
#chestplate(*args, **options, &)
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
-
#count(spec, slots = player_inventory_slots)
Returns the number of matching items in the player inventory (inventory + hotbar), or in the given slots range.
-
#count(&spec : Slot -> _)
Sums item counts in player-inventory stacks selected by the predicate.
-
#deposit_at_least(count, spec)
Tries to transfer at least
#countmatching items from the player inventory to the container, using shift-clicking. -
#deposit_at_least(count, &spec : Slot -> _)
Deposits matching whole stacks until at least count items have moved or no progress is possible.
-
#helmet(*args, **options)
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
-
#helmet(*args, **options, &)
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
-
#leggings(*args, **options)
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
-
#leggings(*args, **options, &)
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
-
#off_hand(*args, **options)
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
-
#off_hand(*args, **options, &)
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
-
#pick(spec)
Selects a matching item into the main hand, if one exists in the inventory.
-
#pick(&spec : Slot -> _)
Selects the first usable item matched by the predicate into the main hand.
-
#pick!(spec)
Selects a matching usable item, raising
ItemNotFoundErrorif none exists. -
#pick!(&spec : Slot -> _)
Selects an item matched by the predicate, raising
ItemNotFoundErrorwhen no eligible slot exists. -
#refill_hand
Refills the main hand to its maximum stack size by manually combining stacks.
-
#replenish(count, spec)
Ensures the player has at least
#countitems of the specified type in their inventory. -
#replenish(count, &spec : Slot -> _)
Withdraws predicate-matching stacks until the player holds at least count.
-
#throw_all_of(name)
Drops every stack named name from the active menu and returns the item count queued for dropping.
-
#withdraw_at_least(count, spec)
Tries to transfer at least
#countmatching items from the container to the player inventory, using shift-clicking. -
#withdraw_at_least(count, &spec : Slot -> _)
Withdraws matching whole stacks until at least count items have moved or no progress is possible.
Constructor Detail
Creates an inventory facade over the client's currently active menu.
Macro Detail
Forwards unrecognized menu accessors to the active Client#container_menu.
This keeps the inventory DSL available for both the player inventory and an
open container. #slots covers the whole active window; #inventory and
#hotbar are the player's storage slots, while #content is the container
portion of a non-player menu. These accessors are live menu views, not
independently enumerable collections owned by Inventory.
Instance Method Detail
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
Returns the number of matching items in the player inventory (inventory + hotbar), or in the given slots range.
Example:
inventory.count "diamond_pickaxe" # => 2
inventory.count { |slot| slot.name.ends_with?("_pickaxe") } # sum of matching stacks
inventory.count { |slot| slot.name == "diamond_pickaxe" && slot.efficiency >= 4 } # => 1
inventory.count "stone", slots # => 5 (count in entire window including container)
Sums item counts in player-inventory stacks selected by the predicate. Pass an explicit slot range to the non-block overload to count another portion of the active menu.
Tries to transfer at least #count matching items from the player inventory to the container, using shift-clicking.
Returns the number of actually transferred items.
Example:
inventory.deposit_at_least 5, "diamond_pickaxe" # => 3
inventory.deposit_at_least 5, &.empty? # => 1
inventory.deposit_at_least(5) { |slot| slot.name == "diamond_pickaxe" && slot.efficiency >= 4 } # => 2
Deposits matching whole stacks until at least count items have moved or no progress is possible. Uses the predicate to select stacks.
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
Equipment slots from the player's inventory menu: helmet, chestplate, leggings, boots, and off-hand.
Selects a matching item into the main hand, if one exists in the inventory. Returns true if an item was picked, false otherwise.
Example:
inventory.pick "diamond_pickaxe" # => true
inventory.pick &.empty? # => true
inventory.pick { |slot| slot.name == "diamond_pickaxe" && slot.efficiency >= 4 } # => false
Durability-aware selection
#pick is smarter than a plain find-and-equip. For each call it:
- Keeps the main hand if it already matches and is not close to breaking.
- Otherwise searches the hotbar, picking the most-damaged usable tool first so tools wear out evenly instead of leaving partially-damaged leftovers.
- Falls back to the rest of the inventory, swapping the chosen slot into the hotbar.
Because the most-damaged usable tool is chosen each time, calling #pick
regularly in a loop will automatically rotate in fresh tools from the
inventory as the hotbar wears down — no manual reselection needed.
Avoiding tool destruction
Slots that needs_repair? are treated as if they don't match, so #pick
will not hand you a tool that's about to shatter. "Needs repair" means an
enchanted diamond or netherite tool with fewer than 12 uses left whose
repair_cost is still below the cutoff (see below). Such tools are
preserved for the anvil.
Tools that are not worth repairing — unenchanted tools, wood/stone/ iron/gold tools, or diamond/netherite tools whose repair cost has climbed above the cutoff — are still selected and will be used until they break. The rationale: if repairing costs too many levels, it's cheaper to craft a fresh one.
Tuning the repair cutoff
The cutoff is Rosegold::Slot.max_repair_cost (default 31). Raise it to
keep babying heavily-repaired tools, or lower it to retire them sooner:
Rosegold::Slot.max_repair_cost = 15 # retire tools past "Prior Work: 15" Rosegold::Slot.max_repair_cost = 0 # never preserve — use everything to breakage
Selects the first usable item matched by the predicate into the main hand.
Returns true on selection and false when no eligible slot exists.
Selects an item matched by the predicate, raising ItemNotFoundError when
no eligible slot exists.
Refills the main hand to its maximum stack size by manually combining stacks. Only works when no container is open (player inventory only). Returns the final quantity in the main hand after refilling.
Example:
inventory.refill_hand # => 64 (if main hand was stone and got filled to max stack)
inventory.refill_hand # => 32 (if only 32 items were available)
inventory.refill_hand # => 0 (if main hand is empty)
Ensures the player has at least #count items of the specified type in their inventory.
If there are already enough items, returns the current count.
If not enough items are present, attempts to withdraw more from a container.
Returns the total count after replenishment attempt.
Example:
inventory.replenish 10, "stone" # => 10 (if successful)
inventory.replenish 5, "diamond" # => 3 (if only 3 available)
inventory.replenish 3 { |slot| slot.name == "diamond_pickaxe" && slot.efficiency >= 4 } # => 2
Withdraws predicate-matching stacks until the player holds at least count. Returns the resulting item count, which can be below or above the target.
Drops every stack named name from the active menu and returns the item count queued for dropping. The server applies the click packets asynchronously.
Tries to transfer at least #count matching items from the container to the player inventory, using shift-clicking.
Returns the number of actually transferred items.
Example:
inventory.withdraw_at_least 5, "diamond_pickaxe" # => 3
inventory.withdraw_at_least 5, &.empty? # => 1
inventory.withdraw_at_least(5) { |slot| slot.name == "diamond_pickaxe" && slot.efficiency >= 4 } # => 2
Withdraws matching whole stacks until at least count items have moved or no progress is possible. Uses the predicate to select stacks.