Class PersistentLightEnergyStorage
java.lang.Object
etithespirit.orimod.common.tile.light.PersistentLightEnergyStorage
- All Implemented Interfaces:
ILightEnergyStorage
An extension to Forge's EnergyStorage that binds to a TileEntity and automatically modifies its NBT and marks it as dirty. This variant is specifically
designed for ILightEnergyStorage rather than the standard IEnergyStorage
- Author:
- Eti
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected double
protected double
static final String
The default key used to save the energy stored in this instance to NBT.If set, this string will be used to save this container's energy to NBT.protected double
protected double
-
Constructor Summary
ConstructorsConstructorDescriptionPersistentLightEnergyStorage
(Runnable markDirty, double capacity) PersistentLightEnergyStorage
(Runnable markDirty, double capacity, double maxTransfer) PersistentLightEnergyStorage
(Runnable markDirty, double capacity, double maxTransfer, boolean allowRFConversion) PersistentLightEnergyStorage
(Runnable markDirty, double capacity, double maxReceive, double maxExtract) PersistentLightEnergyStorage
(Runnable markDirty, double capacity, double maxReceive, double maxExtract, boolean allowRFConversion) PersistentLightEnergyStorage
(Runnable markDirty, double capacity, double maxReceive, double maxExtract, boolean allowRFConversion, double energy) Construct a new storage with the given TE's markDirty() method, the given maximum capacity, maximum transfer amounts, and starting energy. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Whether or not this storage is a valid candidate for use in theLight Energy Adapter
(for conversion to RF).boolean
Returns if this storage can have energy extracted.boolean
Used to determine if this storage can receive energy.double
extractLight
(double maxExtract, boolean simulate) Removes energy from the storage.double
double
void
readFromNBT
(net.minecraft.nbt.CompoundTag nbt) Should be called from the TileEntity that instantiated this instance, this appends the energy data to the entity.double
receiveLight
(double maxReceive, boolean simulate) Adds energy to the storage.net.minecraft.nbt.CompoundTag
writeToNBT
(net.minecraft.nbt.CompoundTag nbt) Should be called from the TileEntity that instantiated this instance, this writes the energy data to NBT.
-
Field Details
-
ENERGY_KEY
The default key used to save the energy stored in this instance to NBT.- See Also:
-
energy
protected double energy -
capacity
protected double capacity -
maxReceive
protected double maxReceive -
maxExtract
protected double maxExtract -
allowRFConversion
protected boolean allowRFConversion -
energyKeyOverride
If set, this string will be used to save this container's energy to NBT. If left alone, thenENERGY_KEY
will be used.
-
-
Constructor Details
-
PersistentLightEnergyStorage
-
PersistentLightEnergyStorage
public PersistentLightEnergyStorage(@Nullable Runnable markDirty, double capacity, double maxTransfer) -
PersistentLightEnergyStorage
public PersistentLightEnergyStorage(@Nullable Runnable markDirty, double capacity, double maxTransfer, boolean allowRFConversion) -
PersistentLightEnergyStorage
public PersistentLightEnergyStorage(@Nullable Runnable markDirty, double capacity, double maxReceive, double maxExtract) -
PersistentLightEnergyStorage
public PersistentLightEnergyStorage(@Nullable Runnable markDirty, double capacity, double maxReceive, double maxExtract, boolean allowRFConversion) -
PersistentLightEnergyStorage
public PersistentLightEnergyStorage(@Nullable Runnable markDirty, double capacity, double maxReceive, double maxExtract, boolean allowRFConversion, double energy) Construct a new storage with the given TE's markDirty() method, the given maximum capacity, maximum transfer amounts, and starting energy.- Parameters:
markDirty
- The markDirty method associated with a TileEntity. This will be automatically set if needed.capacity
- The maximum amount of energy this storage can containemaxReceive
- The maximum amount of energy that can be stored in a single action.maxExtract
- The maximum amount of energy that can be extracted in a single action.allowRFConversion
- Whether or not this storage can convert to and from RFenergy
- The amount of energy within this storage at first.
-
-
Method Details
-
readFromNBT
public void readFromNBT(net.minecraft.nbt.CompoundTag nbt) Should be called from the TileEntity that instantiated this instance, this appends the energy data to the entity.- Parameters:
nbt
- The NBT tag to read from.
-
writeToNBT
public net.minecraft.nbt.CompoundTag writeToNBT(net.minecraft.nbt.CompoundTag nbt) Should be called from the TileEntity that instantiated this instance, this writes the energy data to NBT.- Parameters:
nbt
- The NBT tag to write to.- Returns:
- The modified NBT tag.
-
receiveLight
public double receiveLight(double maxReceive, boolean simulate) Description copied from interface:ILightEnergyStorage
Adds energy to the storage. Returns quantity of energy that was accepted.- Specified by:
receiveLight
in interfaceILightEnergyStorage
- Parameters:
maxReceive
- Maximum amount of energy to be inserted.simulate
- If TRUE, the insertion will only be simulated.- Returns:
- Amount of energy that was (or would have been, if simulated) accepted by the storage.
-
extractLight
public double extractLight(double maxExtract, boolean simulate) Description copied from interface:ILightEnergyStorage
Removes energy from the storage. Returns quantity of energy that was removed.- Specified by:
extractLight
in interfaceILightEnergyStorage
- Parameters:
maxExtract
- Maximum amount of energy to be extracted.simulate
- If TRUE, the extraction will only be simulated.- Returns:
- Amount of energy that was (or would have been, if simulated) extracted from the storage.
-
getLightStored
public double getLightStored()- Specified by:
getLightStored
in interfaceILightEnergyStorage
- Returns:
- The amount of energy currently stored.
-
getMaxLightStored
public double getMaxLightStored()- Specified by:
getMaxLightStored
in interfaceILightEnergyStorage
- Returns:
- The maximum amount of energy that can be stored.
-
canExtractLight
public boolean canExtractLight()Description copied from interface:ILightEnergyStorage
Returns if this storage can have energy extracted. If this is false, then any calls to extractEnergy will return 0.- Specified by:
canExtractLight
in interfaceILightEnergyStorage
- Returns:
- Whether or not this storage can have energy extracted from it.
-
canReceiveLight
public boolean canReceiveLight()Description copied from interface:ILightEnergyStorage
Used to determine if this storage can receive energy. If this is false, then any calls to receiveEnergy will return 0.- Specified by:
canReceiveLight
in interfaceILightEnergyStorage
- Returns:
- Whether or not this storage can have energy added to it.
-
acceptsConversion
public boolean acceptsConversion()Description copied from interface:ILightEnergyStorage
Whether or not this storage is a valid candidate for use in theLight Energy Adapter
(for conversion to RF).- Specified by:
acceptsConversion
in interfaceILightEnergyStorage
- Returns:
- whether or not this can interact with RF (as opposed to Light), which determines its usability in
LightEnergyAdapter
.
-