tutorial:transfer-api_storage
This is an old revision of the document!
−Table of Contents
Fabric Transfer API: Understanding Storage<T>
This article is part of a series on the Fabric Transfer API. Link to the home page of the series.
Storage<FluidVariant>
is a thing that contains fluids, it is what tanks, buckets, etc… implement and it is what pipe mods and others use to move fluids between containers.
You already used Storage<FluidVariant>
Now that you implemented a simple tank, let's have a look at what exactly this SingleVariantStorage<FluidVariant>
is.
public abstract class SingleVariantStorage<T extends TransferVariant<?>> extends ... implements SingleSlotStorage<T> { ... } public interface SingleSlotStorage<T> extends Storage<T>, ... { ... }
The takeaway here is that SingleVariantStorage<FluidVariant>
is a Storage<FluidVariant>
, which is what we registered to FluidStorage.SIDED
!
Retrieving a Storage<FluidVariant> from the world
Let's see how we can retrieve one from the world:
World world = ...; // Important: must be a server world!!! You must never query this on the client. BlockPos pos = ...; // The postion in the world Direction direction = ...; // The side for which we want a storage. @Nullable Storage<FluidVariant> storage = FluidStorage.SIDED.find(world, pos, direction); if (storage != null) { // Use the storage }
What you can do with a Storage<FluidVariant>
Let's have a look at Storage.java
:
public interface Storage<T> { // Insert a resource in the storage. long insert(T resource, long maxAmount, TransactionContext transaction); // Extract a resource from the storage. long extract(T resource, long maxAmount, TransactionContext transaction); // Iterate over the contents of this storage. default Iterable<StorageView<T>> iterable(TransactionContext transaction) { ... } ...
tutorial/transfer-api_storage.1635586638.txt.gz · Last modified: 2021/10/30 09:37 by technici4n