fabric/fabric-transfer-api-v1
Technici4n 2373a54507 Transfer API improvements 3
- **(Slightly source-breaking change)** Change the return type of `Storage#iterator` and `Storage#iterable` from `Iterator<StorageView<T>>` to `Iterator<? extends StorageView<T>>` to allow returning a list directly. Most modders shouldn't be affected by this (this only broke one call site in the whole module).
- Precise that using the iterator or a view after the transaction is closed is "undefined behavior". Also specify that calling remove on the iterator is not allowed.
- Add `StorageView#getUnderlyingView` to be able to tell if some views are equal. This is useful to **compute the contents of multiple storage views without duplicates** (see testmod).
- Expose the lifecycle of the transaction manager cleanly with an enum.
- Definalize some methods in `SingleStackStorage` to allow custom implementations of some of them if needed.
- Add a note to `BlockApiLookup` to fix #1998.
- Play the composter empty sound when it is emptied through the transfer API, as a comment in the source code suggests.

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>
2022-04-10 16:42:38 +01:00
..
src Transfer API improvements 3 2022-04-10 16:42:38 +01:00
build.gradle Port to 22w06a (#1989) 2022-02-11 17:02:44 +00:00
README.md Fabric Transfer API: item transfer and fluid-containing items. (#1553) 2021-08-17 19:08:09 +01:00

Fabric Transfer API (v1)

This module provides common facilities for the transfer of fluids and other game resources.

Transactions

The Transaction system provides a scope that can be used to simulate any number of transfer operations, and then cancel or validate all of them at once. One can think of transactions as video game checkpoints. A more detailed explanation can be found in the class javadoc of Transaction. Every transfer operation requires a Transaction parameter. SnapshotParticipant is the reference implementation of a "participant", that is an object participating in a transaction.

Storages

A Storage<T> is any object that can store resources of type T. Its contents can be read, and resources can be inserted into it or extracted from it. StorageUtil provides a few helpful functions to work with Storages, for example to move resources between two Storages. The storage/base package provides a few helpers to accelerate implementation of Storage<T>.

Implementors of inventories with a fixed number of "slots" or "tanks" can use SingleVariantStorage, and combine them with CombinedStorage.

Fluid transfer

A Storage<FluidVariant> is any object that can store fluids. It is just a Storage<T>, where T is FluidVariant, the immutable combination of a Fluid and additional NBT data. Instances can be accessed through the API lookups defined in FluidStorage.

The unit for fluid transfer is 1/81000ths of a bucket, also known as droplets. FluidConstants contains a few helpful constants to work with droplets.

Client-side Fluid variant rendering will use regular fluid rendering by default, ignoring the additional NBT data. Fluids that wish to render differently depending on the stored NBT data can register a FluidVariantRenderHandler.

Item transfer

A Storage<ItemVariant> is any object that can store items. Instances can be accessed through the API lookup defined in ItemStorage.

The lookup already provides compatibility with vanilla inventories, however it may sometimes be interesting to use InventoryStorage or PlayerInventoryStorage when interaction with Inventory-based APIs is required.

ContainerItemContext

ContainerItemContext is a context designed for ItemApiLookup queries that allows the returned APIs to interact with the containing inventory. Notably, it is used by the FluidStorage.ITEM lookup for fluid-containing items.