ArchieEnergyStorage¶
@Serializable
(with = ArchieEnergyStorage.Serializer::class)class ArchieEnergyStorage(capacity: Long, onUpdate: () -> Unit = {}) : ValueStorage, UpdateManager<NbtTag>
Archie's platform-agnostic energy buffer: implements Common Storage Lib's ValueStorage - the energy analogue of the CommonStorage<ItemResource>/CommonStorage<FluidResource> ArchieItemStorage/ArchieFluidStorage implement - plus Archie's NBT serialization for save/load, mirroring their shape.
Not exposed to third-party mods' pipes/hoppers by default - call BlockEntityType.exposeEnergyStorage once, at registration time, to register it with Common Storage Lib's EnergyApi.BLOCK, which (unlike a lookup you'd build yourself) is wired straight through to each platform's native capability system - no dependency on Common Storage Lib required on the consuming side. Any additional platform-specific bridge you still want on top of that (NeoForge's IEnergyStorage, Fabric's Team Reborn Energy API) is still on you to wire in your own mod.
Usually created through net.kernelpanicsoft.archie.serialization.NBTHolder.energyField rather than directly.
Parameters¶
-
capacity: The maximum amount of energy this storage can hold.
-
onUpdate: Invoked whenever this storage's contents change, for persistence/sync.
Constructors¶
ArchieEnergyStorage¶
Parameters
-
capacity: The maximum amount of energy this storage can hold.
-
onUpdate: Invoked whenever this storage's contents change, for persistence/sync.
Types¶
Serializer¶
object Serializer : KSerializer<ArchieEnergyStorage>
Serializes an ArchieEnergyStorage as its capacity followed by its stored amount.
Properties¶
capacity¶
storedAmount¶
open override val storedAmount: Long
Functions¶
allowsExtraction¶
open override fun allowsExtraction(): Boolean
allowsInsertion¶
open override fun allowsInsertion(): Boolean
createSnapshot¶
open override fun createSnapshot(): NbtTag
Snapshots this storage's getCapacity and stored amount as an NbtTag, for save/sync.
extract¶
Extracts up to amount energy, returning how much was actually removed. When simulate is true, no state is changed - only the extractable amount is calculated.
getCapacity¶
open override fun getCapacity(): Long
The maximum amount of energy this storage can hold.
getStoredAmount¶
open override fun getStoredAmount(): Long
The amount of energy currently stored.
insert¶
Inserts up to amount energy, returning how much was actually accepted. When simulate is true, no state is changed - only the acceptable amount is calculated.
readSnapshot¶
open override fun readSnapshot(snapshot: NbtTag)
Restores this storage's capacity and stored amount from a snapshot produced by createSnapshot. capacity is clamped to non-negative and amount to 0..capacity - a malformed or stale snapshot (e.g. from before a capacity change) shouldn't be able to leave this storage over-capacity or negative, which would otherwise wedge insert/extract.
set¶
Directly overwrites the stored amount, clamped to 0..getCapacity.
update¶
open override fun update()