class
Rosegold::Inventory
- Rosegold::Inventory
- Reference
- Object
Overview
Utility methods for interacting with the open window.
Defined in:
rosegold/control/inventory.crConstructors
Macro Summary
Instance Method Summary
-
#boots(*args, **options)
Equipment slot accessors
-
#boots(*args, **options, &)
Equipment slot accessors
-
#chestplate(*args, **options)
Equipment slot accessors
-
#chestplate(*args, **options, &)
Equipment slot accessors
-
#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 -> _)
-
#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 -> _)
-
#helmet(*args, **options)
Equipment slot accessors
-
#helmet(*args, **options, &)
Equipment slot accessors
-
#leggings(*args, **options)
Equipment slot accessors
-
#leggings(*args, **options, &)
Equipment slot accessors
-
#off_hand(*args, **options)
Equipment slot accessors
-
#off_hand(*args, **options, &)
Equipment slot accessors
-
#pick(spec)
Selects a matching item into the main hand, if one exists in the inventory.
- #pick!(spec)
-
#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 -> _)
- #throw_all_of(name)
-
#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 -> _)
Constructor Detail
Macro Detail
Instance Method Detail
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)
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
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
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
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