Package net.neoforged.neoforge.energy
Class EnergyStorage
java.lang.Object
net.neoforged.neoforge.energy.EnergyStorage
- All Implemented Interfaces:
INBTSerializable<Tag>
,IEnergyStorage
Reference implementation of
IEnergyStorage
. Use/extend this or implement your own.
Derived from the Redstone Flux power system designed by King Lemming and originally utilized in Thermal Expansion and related mods.
Created with consent and permission of King Lemming and Team CoFH. Released with permission under LGPL 2.1 when bundled with Forge.-
Field Summary
Modifier and TypeFieldDescriptionprotected int
protected int
protected int
protected int
-
Constructor Summary
ConstructorDescriptionEnergyStorage
(int capacity) EnergyStorage
(int capacity, int maxTransfer) EnergyStorage
(int capacity, int maxReceive, int maxExtract) EnergyStorage
(int capacity, int maxReceive, int maxExtract, int energy) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns if this storage can have energy extracted.boolean
Used to determine if this storage can receive energy.void
deserializeNBT
(HolderLookup.Provider provider, Tag nbt) int
extractEnergy
(int toExtract, boolean simulate) Removes energy from the storage.int
Returns the amount of energy currently stored.int
Returns the maximum amount of energy that can be stored.int
receiveEnergy
(int toReceive, boolean simulate) Adds energy to the storage.serializeNBT
(HolderLookup.Provider provider)
-
Field Details
-
energy
protected int energy -
capacity
protected int capacity -
maxReceive
protected int maxReceive -
maxExtract
protected int maxExtract
-
-
Constructor Details
-
EnergyStorage
public EnergyStorage(int capacity) -
EnergyStorage
public EnergyStorage(int capacity, int maxTransfer) -
EnergyStorage
public EnergyStorage(int capacity, int maxReceive, int maxExtract) -
EnergyStorage
public EnergyStorage(int capacity, int maxReceive, int maxExtract, int energy)
-
-
Method Details
-
receiveEnergy
public int receiveEnergy(int toReceive, boolean simulate) Description copied from interface:IEnergyStorage
Adds energy to the storage. Returns the amount of energy that was accepted.- Specified by:
receiveEnergy
in interfaceIEnergyStorage
- Parameters:
toReceive
- The amount of energy being received.simulate
- If true, the insertion will only be simulated, meaningIEnergyStorage.getEnergyStored()
will not change.- Returns:
- Amount of energy that was (or would have been, if simulated) accepted by the storage.
-
extractEnergy
public int extractEnergy(int toExtract, boolean simulate) Description copied from interface:IEnergyStorage
Removes energy from the storage. Returns the amount of energy that was removed.- Specified by:
extractEnergy
in interfaceIEnergyStorage
- Parameters:
toExtract
- The amount of energy being extracted.simulate
- If true, the extraction will only be simulated, meaningIEnergyStorage.getEnergyStored()
will not change.- Returns:
- Amount of energy that was (or would have been, if simulated) extracted from the storage.
-
getEnergyStored
public int getEnergyStored()Description copied from interface:IEnergyStorage
Returns the amount of energy currently stored.- Specified by:
getEnergyStored
in interfaceIEnergyStorage
-
getMaxEnergyStored
public int getMaxEnergyStored()Description copied from interface:IEnergyStorage
Returns the maximum amount of energy that can be stored.- Specified by:
getMaxEnergyStored
in interfaceIEnergyStorage
-
canExtract
public boolean canExtract()Description copied from interface:IEnergyStorage
Returns if this storage can have energy extracted. If this is false, then any calls to extractEnergy will return 0.- Specified by:
canExtract
in interfaceIEnergyStorage
-
canReceive
public boolean canReceive()Description copied from interface:IEnergyStorage
Used to determine if this storage can receive energy. If this is false, then any calls to receiveEnergy will return 0.- Specified by:
canReceive
in interfaceIEnergyStorage
-
serializeNBT
- Specified by:
serializeNBT
in interfaceINBTSerializable<Tag>
-
deserializeNBT
- Specified by:
deserializeNBT
in interfaceINBTSerializable<Tag>
-