Interface InventoryStorage
- All Superinterfaces:
Iterable<StorageView<ItemVariant>>
,SlottedStorage<ItemVariant>
,Storage<ItemVariant>
- All Known Subinterfaces:
PlayerInventoryStorage
Storage<ItemVariant>
for vanilla's Inventory
, SidedInventory
and PlayerInventory
.
Inventory
is often nicer to implement than Storage<ItemVariant>
, but harder to use for item transfer.
This wrapper allows one to have the best of both worlds, for example by storing a subclass of SimpleInventory
in a block entity class,
while exposing it as a Storage<ItemVariant>
to the item transfer API.
In particular, note that getSlots()
can be combined with CombinedStorage
to retrieve a wrapper around a specific range of slots.
Important note: This wrapper assumes that the inventory owns its slots. If the inventory does not own its slots, for example because it delegates to another inventory, this wrapper should not be used!
Experimental feature, we reserve the right to remove or change it without further notice. The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
-
Method Summary
Modifier and TypeMethodDescriptiondefault SingleSlotStorage
<ItemVariant> getSlot
(int slot) Retrieve a specific slot of this storage.default int
Retrieve the number of slots in this storage.@UnmodifiableView List
<SingleSlotStorage<ItemVariant>> getSlots()
Retrieve an unmodifiable list of the wrappers for the slots in this inventory.static InventoryStorage
Return a wrapper around anInventory
.Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.Storage
exactView, extract, getVersion, insert, iterator, nonEmptyIterator, nonEmptyViews, simulateExtract, simulateInsert, supportsExtraction, supportsInsertion
-
Method Details
-
of
Return a wrapper around anInventory
.If the inventory is a
SidedInventory
and the direction is nonnull, the wrapper wraps the sided inventory from the given direction. The returned wrapper contains only the slots with the indices returned bySidedInventory.getAvailableSlots(net.minecraft.util.math.Direction)
at query time.- Parameters:
inventory
- The inventory to wrap.direction
- The direction to use if the access is sided, ornull
if the access is not sided.
-
getSlots
@UnmodifiableView List<SingleSlotStorage<ItemVariant>> getSlots()Retrieve an unmodifiable list of the wrappers for the slots in this inventory. Each wrapper corresponds to a single slot in the inventory.- Specified by:
getSlots
in interfaceSlottedStorage<ItemVariant>
-
getSlotCount
default int getSlotCount()Description copied from interface:SlottedStorage
Retrieve the number of slots in this storage.- Specified by:
getSlotCount
in interfaceSlottedStorage<ItemVariant>
-
getSlot
Description copied from interface:SlottedStorage
Retrieve a specific slot of this storage.- Specified by:
getSlot
in interfaceSlottedStorage<ItemVariant>
-