Fabric Flux
Important: This modification is not part of Fabric. It is a third-party library that allows developers to create energy mods for the Fabric platform.
Fabric Flux (abbreviated as FF) is a library designed to implement an energy system in mods for the Fabric platform.
Battery
Try using this battery on various entities.
How It Works
The system is based on two main concepts: containers and interfaces.
- Flux Container is an object that provides access to interfaces. Some containers may require additional data for access. For example, an item will require an ItemStack to provide an interface.
- Flux Interface is used to transfer energy between containers. Two interfaces are required to complete an energy transfer.
Recommendations for Developers
- Every
Itemthat accepts energy should implementIFluxContainerand always check ingetFluxForif the object type isItemStack. Other object types are also supported. - Any
BlockEntitycan implement bothIFluxandIFluxContainer. If a controller is implemented, thegetFluxFormethod should always check if the object type isDirection. Other object types are also supported. - If an interface simply does not accept input/output, it should return
-1instead of the energy amount (which cannot be less than0). This should be checked before calculating energy. - DO NOT STORE Flux Interfaces, only containers. Some interfaces can be created anew by a controller. There are exceptions for items, such as charging/discharging a battery (
Itemmust create a new interface because it cannot be stored in an item stack). IFlux::toshould be used to transfer energy. This method can be overridden.- The
FluxBatteryclass is provided in the API as a basic interface.
Differences from Other Energy APIs
FF is slightly different from Forge Energy API. This modification has fewer methods to implement and is not capability-based (instead, it uses containers). There are no equivalents to canExtractEnergy/canReceiveEnergy, checking with extractFlux/receiveFlux(0, true) does the same thing, although it is not required.