class

Rosegold::Inventory

Inherits Reference / Object

Utility methods for interacting with the open window.

Constructors

Instance methods

boots(*args, **options)

Equipment slot accessors

Source
boots(*args, **options, &)

Equipment slot accessors

Source
chestplate(*args, **options)

Equipment slot accessors

Source
chestplate(*args, **options, &)

Equipment slot accessors

Source
count(spec, slots = player_inventory_slots)

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 &.empty? # => 2 inventory.count { |slot| slot.name == "diamond_pickaxe" && slot.efficiency >= 4 } # => 1 inventory.count "stone", slots # => 5 (count in entire window including container)

Source
count
Source
deposit_at_least(count, spec)

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

Source
deposit_at_least(count, &spec : Slot -> _)
Source
helmet(*args, **options)

Equipment slot accessors

Source
helmet(*args, **options, &)

Equipment slot accessors

Source
leggings(*args, **options)

Equipment slot accessors

Source
leggings(*args, **options, &)

Equipment slot accessors

Source
off_hand(*args, **options)

Equipment slot accessors

Source
off_hand(*args, **options, &)

Equipment slot accessors

Source
pick(spec)

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:

  1. Keeps the main hand if it already matches and is not close to breaking.
  2. Otherwise searches the hotbar, picking the most-damaged usable tool first so tools wear out evenly instead of leaving partially-damaged leftovers.
  3. 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

Source
pick!(spec)
Source
refill_hand

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)

Source
replenish(count, spec)

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

Source
replenish(count, &spec : Slot -> _)
Source
throw_all_of(name)
Source
withdraw_at_least(count, spec)

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

Source
withdraw_at_least(count, &spec : Slot -> _)
Source

Macros

method_missing(call)
Source

Nested types