fabric/fabric-transfer-api-v1
apple502j 7b20cbb0f8
1.21.5 porting fixes ()
* Fix behavior change in `SingleVariantStorage` serialization

25w09a port added `orElseThrow()` call in `readNbt`, changing the behavior for
missing `variant` field. This previously used `fallback` (or, if the `codec` was
somehow a unit codec/could accept empty NBT, successfully decoded), but the change
made it throw. This makes it use the fallback in both cases.
Given that it is unlikely for a variant to use a unit codec, the remaining change is
deemed acceptable.

* Fix handling of incorrect NBT type in `AttachmentSerializingImpl`

* fix typo

* Remove broken wandering trader trade registration code

* Fix typo
2025-03-23 15:19:53 +00:00
..
src 1.21.5 porting fixes () 2025-03-23 15:19:53 +00:00
build.gradle Add support for Item-containing Items () 2024-10-15 13:26:25 +01:00
README.md Fix links in transfer-api README.md () 2024-04-10 22:17:45 +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 components. 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 components. Fluids that wish to render differently depending on the stored components 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.