Transfer
These types move energy, items, and fluid between blocks and stacks, and let other mods use a mod’s own storage. They replace Forge’s capabilities and Fabric’s transfer and energy lookups, which differ between the loaders and count fluid in different units.
At a glance
Section titled “At a glance”| Type | Summary | Status | Since | Side | Thread |
|---|---|---|---|---|---|
EnergyAccess |
Energy storage, from Transfer#energy or a mod’s own EnergyBuffer. |
Experimental | 2.10.0 | server | server |
EnergyBuffer |
A mod’s energy storage. | Experimental | 2.10.0 | server | server |
FluidAccess |
Fluid storage, from Transfer#fluids or a mod’s own FluidTank. |
Experimental | 2.10.0 | server | server |
FluidAmount |
An amount of a fluid, in millibuckets (1000 to a bucket). | Experimental | 2.10.0 | both | any |
FluidTank |
A mod’s tank of one fluid. | Experimental | 2.10.0 | server | server |
ItemAccess |
Item storage, from Transfer#items or a mod’s own ItemSlots. |
Experimental | 2.10.0 | server | server |
ItemSlots |
A mod’s item slots. | Experimental | 2.10.0 | both | any |
Transfer |
Energy, item, and fluid storage on blocks and stacks. | Experimental | 2.10.0 | server | server |
Quick start
Section titled “Quick start”BatteryBoxBlockEntity keeps its energy in an EnergyBuffer field, energy. With
BATTERY_BOX, its block entity type from the mod’s Registrar, in the mod’s initializer:
Transfer.exposeEnergy(BATTERY_BOX, (box, side) -> box.energy);Transfer
Section titled “Transfer”Experimental · Since 2.10.0 · Side: server · Thread: server
Transfer finds another block’s storage on the face that touches it. In a generator’s block
entity, with energy its EnergyBuffer and FACING the side it pushes to, in its server tick:
// Spread over ticks: each generator pushes on its own tick of ten.if ((level.getGameTime() + worldPosition.asLong()) % 10 != 0) return;Direction facing = getBlockState().getValue(FACING);EnergyAccess target = Transfer.energy(level, worldPosition.relative(facing), facing.getOpposite());if (target != null) energy.extract(target.insert(energy.extract(1_000, true), false), false);Performance
Section titled “Performance”- Each find makes a new view of the storage, so a machine that moves something often finds it only as often as it moves.
See also
Section titled “See also”- Block behavior and rendering:
SyncedBlockEntity, which shows a tank’s fill on its clients. - Menus:
MenuValues, which shows stored energy on a machine’s screen. - Registration and ids:
Registrar, which registers the block entity types and items to expose.