Class PersistentLightEnergyStorage

java.lang.Object
etithespirit.orimod.common.tile.light.PersistentLightEnergyStorage
All Implemented Interfaces:
ILightEnergyStorage

public class PersistentLightEnergyStorage extends Object implements 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 Details

    • ENERGY_KEY

      public static final String 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

      public String energyKeyOverride
      If set, this string will be used to save this container's energy to NBT. If left alone, then ENERGY_KEY will be used.
  • Constructor Details

    • PersistentLightEnergyStorage

      public PersistentLightEnergyStorage(@Nullable Runnable markDirty, double capacity)
    • 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 containe
      maxReceive - 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 RF
      energy - 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 interface ILightEnergyStorage
      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 interface ILightEnergyStorage
      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 interface ILightEnergyStorage
      Returns:
      The amount of energy currently stored.
    • getMaxLightStored

      public double getMaxLightStored()
      Specified by:
      getMaxLightStored in interface ILightEnergyStorage
      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 interface ILightEnergyStorage
      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 interface ILightEnergyStorage
      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 the Light Energy Adapter (for conversion to RF).
      Specified by:
      acceptsConversion in interface ILightEnergyStorage
      Returns:
      whether or not this can interact with RF (as opposed to Light), which determines its usability in LightEnergyAdapter.