Class ItemStorage
Storage<ItemVariant>
instances.
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.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final BlockApiLookup<Storage<ItemVariant>,
@Nullable Direction> Sided block access to item variant storages. -
Method Summary
-
Field Details
-
SIDED
Sided block access to item variant storages. TheDirection
parameter may be null, meaning that the full inventory (ignoring side restrictions) should be queried. Refer toBlockApiLookup
for documentation on how to use this field.When the operations supported by a storage change, that is if the return value of
Storage.supportsInsertion()
orStorage.supportsExtraction()
changes, the storage should notify its neighbors with a block update so that they can refresh their connections if necessary.Block entities directly implementing
Inventory
orSidedInventory
are automatically handled by a fallback provider, and don't need to do anything. Blocks that implementInventoryProvider
and whose returned inventory is constant (it's the same for two subsequent calls) are also handled automatically and don't need to do anything. The fallback provider assumes that theInventory
"owns" its contents. If that's not the case, for example because it redirects all function calls to another inventory, then implementingInventory
should be avoided.Hoppers and droppers will interact with storages exposed through this lookup, thus implementing one of the vanilla APIs is not necessary.
Depending on the use case, the following strategies can be used to offer a
Storage<ItemVariant>
implementation:- Directly implementing
Inventory
orSidedInventory
on a block entity - it will be wrapped automatically. - Storing an inventory inside a block entity field, and converting it manually with
InventoryStorage.of(net.minecraft.inventory.Inventory, net.minecraft.util.math.Direction)
.SimpleInventory
can be used for easy implementation. SingleStackStorage
can also be used for more flexibility. Multiple of them can be combined withCombinedStorage
.- Directly providing a custom implementation of
Storage<ItemVariant>
is also possible.
A simple way to expose item variant storages for a block entity hierarchy is to extend
SidedStorageBlockEntity
.This may be queried safely both on the logical server and on the logical client threads. On the server thread (i.e. with a server world), all transfer functionality is always supported. On the client thread (i.e. with a client world), contents of queried Storages are unreliable and should not be modified.
- Directly implementing
-