Inventory class

Slots of ItemStacks, the first hotbarSize of them the hotbar. How many of an item fit a slot and how long it lasts are the game's, asked through stackSize and maxDurability.

Constructors

Inventory({required int stackSize(String id), int maxDurability(String id)?, int capacity = 36, int hotbarSize = 9})
capacity empty slots.

Properties

capacity → int
How many slots.
final
hasEmptySlot → bool
Whether any slot is empty.
no setter
hashCode → int
The hash code for this object.
no setterinherited
hotbarSize → int
How many of the first slots are the hotbar.
final
listeners → List<void Function()>
Called after every change.
final
maxDurability → int Function(String id)
Uses item id survives; 0 for one that never wears.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
slots → List<ItemStack?>
The slots; null is empty.
final
stackSize → int Function(String id)
How many of item id fit one slot.
final

Methods

add(String id, int count) → int
Adds up to count of id, topping up stacks before opening slots; returns what did not fit.
addStack(ItemStack stack) → bool
Puts a copy of stack (bonus and wear kept) in the first empty slot; false when none is.
bonusAt(int i) → int
The bonus of slot i's stack.
countAt(int i) → int
How many in slot i.
countOf(String id) → int
How many of id in every slot.
durAt(int i) → int
Uses left on slot i's tool or weapon (its maximum when never worn), 0 for an item that never wears or an empty slot.
emitChanged() → void
Tells the listeners a slot changed from outside (a stack edited in place).
find(String id) → int
The first slot holding id, or -1.
fromJson(List<Object?> data, {bool known(String id)?}) → void
Reads data back; a slot naming an item known rejects stays empty.
idAt(int i) → String
The item in slot i, '' when empty.
isEmptySlot(int i) → bool
Whether slot i is empty.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(String id, int count) → bool
Takes count of id, from the last slots first; false (and nothing taken) when there are fewer.
roomFor(String id, int count) → int
How many of count id would fit right now.
setSlot(int i, ItemStack? stack) → void
Sets slot i to a copy of stack (null empties it).
swap(int a, int b) → void
Swaps slots a and b.
takeFromSlot(int i, int count) → ItemStack?
Takes up to count from slot i as a new stack; null when empty.
toJson() → List<Object>
Every slot, an empty map for an empty one.
toString() → String
A string representation of this object.
inherited
wear(int i, [int uses = 1]) → bool
Wears slot i's item by uses; true when it broke (the slot empties).

Operators

operator ==(Object other) → bool
The equality operator.
inherited