User Tools

Site Tools


tutorial:transfer-api_storage

This is an old revision of the document!


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.

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. 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. 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
}
tutorial/transfer-api_storage.1635586250.txt.gz · Last modified: 2021/10/30 09:30 by technici4n