9ff28f4026
A common source of crashes on modded Minecraft servers comes from modders accidently calling client only code from the client, this PR is another large step towards elimitating that. This PR has been months in the making and years in the planning, requiring major changes to Loom & Loader. In recent Minecraft versions Mojang has made it easier than ever to cleanly split the jar, going against the status-quo of merging the client and server into one jar. From the start we have designed Fabric to have a very clear split between client and common (client & server) code. Fabric has always encoraged keeping client only code seprate from the server, this can be seen at a fundamental level with the entrypoints in Loader. Fabric API's have all been designed with this mind. This PR provides a compile safety net around Fabric API using client only code on the server. Even though there are almost 400 changed files, minimal changes beyond moving the files were required to achieve this in Fabric API, thanks to the effort of all contributors in the past. These changes should not affect modders or players in anyway, a single "universal" jar is still produced. Im happy to awnswer any questions. |
||
---|---|---|
.. | ||
src | ||
build.gradle | ||
README.md |
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 Storage
s,
for example to move resources between two Storage
s.
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.
Fluid
s 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.