An Energy API used by TechReborn
- Fully unit tested
- Depends on Minecraft and fabric-loader
Currently WIP, the API may change at any time! I am very open to feedback and suggestions on the issue tracker.
This may seem quite different from any energy API that you have seen before (code wise), as this is because I wanted to try something different.
- 1 coal = 4000
- 1 plank = 750
Add the following into your dependencies block in build.gradle
modApi 'teamreborn:energy:<latest_version>'
include 'teamreborn:energy:<latest_version>'
This basic example shows how to move energy from place to another, the source or target can be anything that has a registered holder.
Energy.of(source)
.side(side)
.into(
Energy.of(target).side(side.getOpposite())
)
.move();
WIP will be done at some point
Energy.of(object)
will return an EnergyHandler
that can be used to read or interact with the energy of a supplied object (More on this later).
The Object may be an instance of EnergyStorage
or any other object that has a supported holder registered (More on this later).
RebornCore (Included in TechReborn) registers a holder for Minecraft's ItemStack
, allow you easily get the energy off an ItemStack
. BlockEntities are expected to implement EnergyStorage
Energy.valid
will return true if the given object is supported
An instance of EnergyHandler can be got from Energy.of()
Returns the current amount of stored energy
double energy = Energy.of(object).getEnergy()
Returns the maximum amount of energy that the holder can store
double energy = Energy.of(object).getEnergy()
Set the amount of energy stored in the holder
Energy.of(object).set(250)
Extract upto the amount of energy provided, returns the amount of energy that was extracted. This is limited by the max output of the holder, as well as the amount of energy that is held in the holder. Returns the the amount of energy actually extracted from the holder.
double extracted = Energy.of(object).extract(20)
Insert upto the amount of energy provided, returns the amount of energy that was inserted. This is limited by the max input of the holder, as well as the amount of free space in the hold. Returns the the amount of energy actually inserted from the holder.
double inserted = Energy.of(object).insert(20)