Record Class WrappedItemEnergyContainer

java.lang.Object
java.lang.Record
earth.terrarium.botarium.common.energy.impl.WrappedItemEnergyContainer
Record Components:
stack - The item stack.
container - The wrapped energy container. Botarium provides a default implementation for this with SimpleEnergyContainer.
All Implemented Interfaces:
EnergyContainer, Serializable, Updatable, net.minecraft.world.Clearable

public record WrappedItemEnergyContainer(net.minecraft.world.item.ItemStack stack, EnergyContainer container) extends Record implements EnergyContainer, Updatable
Represents a wrapped energy container for an item. This class implements the EnergyContainer interface and the Updatable interface. It delegates energy-related operations to the wrapped energy container, and updates the item when the energy is changed.
  • Constructor Details

    • WrappedItemEnergyContainer

      public WrappedItemEnergyContainer(net.minecraft.world.item.ItemStack stack, EnergyContainer container)
      Creates an instance of a WrappedItemEnergyContainer record class.
      Parameters:
      stack - the value for the stack record component
      container - the value for the container record component
  • Method Details

    • insertEnergy

      public long insertEnergy(long energy, boolean simulate)
      Description copied from interface: EnergyContainer
      Inserts a given amount of energy into the container.
      Specified by:
      insertEnergy in interface EnergyContainer
      Parameters:
      energy - The amount to be inserted into the container.
      simulate - If true, the container will not be modified.
      Returns:
      The amount of energy that was added to the container.
    • extractEnergy

      public long extractEnergy(long energy, boolean simulate)
      Description copied from interface: EnergyContainer
      Extracts a given amount of energy into the container.
      Specified by:
      extractEnergy in interface EnergyContainer
      Parameters:
      energy - The amount to be extracted from the container.
      simulate - If true, the container will not be modified.
      Returns:
      The amount of energy that was removed from the container.
    • internalInsert

      public long internalInsert(long amount, boolean simulate)
      Description copied from interface: EnergyContainer
      An internal version of EnergyContainer.insertEnergy(long, boolean) that is used by mod authors looking to directly interact with their own containers.

      You should not call this method for other mod's containers, instead use EnergyContainer.insertEnergy(long, boolean).

      Specified by:
      internalInsert in interface EnergyContainer
    • internalExtract

      public long internalExtract(long amount, boolean simulate)
      Description copied from interface: EnergyContainer
      An internal version of EnergyContainer.extractEnergy(long, boolean) that is used by mod authors looking to directly interact with their own containers.

      You should not call this method for other mod's containers, instead use EnergyContainer.extractEnergy(long, boolean).

      Specified by:
      internalExtract in interface EnergyContainer
    • setEnergy

      public void setEnergy(long energy)
      Description copied from interface: EnergyContainer
      Sets a given amount of energy in the container.
      Specified by:
      setEnergy in interface EnergyContainer
      Parameters:
      energy - The amount of energy to set in the container.
    • getStoredEnergy

      public long getStoredEnergy()
      Specified by:
      getStoredEnergy in interface EnergyContainer
      Returns:
      The amount of energy in the container.
    • getMaxCapacity

      public long getMaxCapacity()
      Specified by:
      getMaxCapacity in interface EnergyContainer
      Returns:
      The maximum amount of energy that can be stored in the container.
    • maxInsert

      public long maxInsert()
      Specified by:
      maxInsert in interface EnergyContainer
      Returns:
      The maximum amount of energy that can be inserted into the container at a time.
    • maxExtract

      public long maxExtract()
      Specified by:
      maxExtract in interface EnergyContainer
      Returns:
      The maximum amount of energy that can be extracted from the container at a time.
    • allowsInsertion

      public boolean allowsInsertion()
      Specified by:
      allowsInsertion in interface EnergyContainer
      Returns:
      Weather the container allows for energy to be inserted.
    • allowsExtraction

      public boolean allowsExtraction()
      Specified by:
      allowsExtraction in interface EnergyContainer
      Returns:
      Weather the container allows for energy to be extracted.
    • createSnapshot

      public EnergySnapshot createSnapshot()
      Specified by:
      createSnapshot in interface EnergyContainer
      Returns:
      A EnergySnapshot of the given state of the EnergyContainer.
    • deserialize

      public void deserialize(net.minecraft.nbt.CompoundTag nbt)
      Description copied from interface: Serializable
      Deserializes the information of an object from a CompoundTag.
      Specified by:
      deserialize in interface Serializable
      Parameters:
      nbt - The CompoundTag to deserialize from.
    • serialize

      public net.minecraft.nbt.CompoundTag serialize(net.minecraft.nbt.CompoundTag nbt)
      Description copied from interface: Serializable
      Serializes the information of an object to a CompoundTag.
      Specified by:
      serialize in interface Serializable
      Parameters:
      nbt - The CompoundTag to serialize to.
      Returns:
      The CompoundTag that was passed in but with the information of the object serialized added to it.
    • update

      public void update()
      Description copied from interface: Updatable
      Called when the operation has been completed and the data has been updated.
      Specified by:
      update in interface Updatable
    • clearContent

      public void clearContent()
      Specified by:
      clearContent in interface net.minecraft.world.Clearable
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • stack

      public net.minecraft.world.item.ItemStack stack()
      Returns the value of the stack record component.
      Returns:
      the value of the stack record component
    • container

      public EnergyContainer container()
      Returns the value of the container record component.
      Returns:
      the value of the container record component