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.

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>

tutorial/transfer-api_storage.1635586385.txt.gz · Last modified: 2021/10/30 09:33 by technici4n