Interface ContainerStorage
- All Superinterfaces:
Iterable<StorageView<ItemVariant>>, SlottedStorage<ItemVariant>, Storage<ItemVariant>
- All Known Subinterfaces:
PlayerInventoryStorage
Storage<ItemVariant> for vanilla's Container, WorldlyContainer and Inventory.
Container 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 SimpleContainer 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 container owns its slots. If the container does not own its slots, for example because it delegates to another container, this wrapper should not be used!
-
Method Summary
Modifier and TypeMethodDescriptiondefault SingleSlotStorage<ItemVariant> getSlot(int slot) Retrieve a specific slot of this storage.default intRetrieve the number of slots in this storage.@UnmodifiableView List<SingleSlotStorage<ItemVariant>> getSlots()Retrieve an unmodifiable list of the wrappers for the slots in this container.static ContainerStorageof(net.minecraft.world.Container container, @Nullable net.minecraft.core.Direction direction) Return a wrapper around anContainer.Methods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface Storage
extract, getVersion, insert, iterator, nonEmptyIterator, nonEmptyViews, supportsExtraction, supportsInsertion
-
Method Details
-
of
static ContainerStorage of(net.minecraft.world.Container container, @Nullable net.minecraft.core.Direction direction) Return a wrapper around anContainer.If the container is a
WorldlyContainerand the direction is nonnull, the wrapper wraps the sided container from the given direction. The returned wrapper contains only the slots with the indices returned byWorldlyContainer.getSlotsForFace(Direction)at query time.- Parameters:
container- The container to wrap.direction- The direction to use if the access is sided, ornullif the access is not sided.
-
getSlots
@UnmodifiableView List<SingleSlotStorage<ItemVariant>> getSlots()Retrieve an unmodifiable list of the wrappers for the slots in this container. Each wrapper corresponds to a single slot in the container.- Specified by:
getSlotsin interfaceSlottedStorage<ItemVariant>
-
getSlotCount
default int getSlotCount()Description copied from interface:SlottedStorageRetrieve the number of slots in this storage.- Specified by:
getSlotCountin interfaceSlottedStorage<ItemVariant>
-
getSlot
Description copied from interface:SlottedStorageRetrieve a specific slot of this storage.- Specified by:
getSlotin interfaceSlottedStorage<ItemVariant>
-