Interface EnergyContainer

All Superinterfaces:
net.minecraft.world.Clearable, Serializable
All Known Implementing Classes:
ExtractOnlyEnergyContainer, InsertOnlyEnergyContainer, PlatformBlockEnergyManager, PlatformItemEnergyManager, SimpleEnergyContainer, UnlimitedEnergyContainer, WrappedBlockEnergyContainer, WrappedItemEnergyContainer

public interface EnergyContainer extends Serializable, net.minecraft.world.Clearable
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    boolean
     
     
    long
    extractEnergy(long maxAmount, boolean simulate)
    Extracts a given amount of energy into the container.
    long
     
    long
     
    static boolean
    holdsEnergy(net.minecraft.world.item.ItemStack stack)
    Checks if an ItemStack holds energy.
    static boolean
    holdsEnergy(net.minecraft.world.level.block.entity.BlockEntity block, @Nullable net.minecraft.core.Direction direction)
    Checks if the given block entity holds energy.
    static boolean
    holdsEnergy(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction direction)
    Checks if the given block at the specified position and state holds energy.
    static boolean
    holdsEnergy(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.world.level.block.state.BlockState state, @Nullable net.minecraft.world.level.block.entity.BlockEntity entity, @Nullable net.minecraft.core.Direction direction)
    Checks if the given block at the specified position and state holds energy.
    long
    insertEnergy(long maxAmount, boolean simulate)
    Inserts a given amount of energy into the container.
    default long
    internalExtract(long amount, boolean simulate)
    An internal version of extractEnergy(long, boolean) that is used by mod authors looking to directly interact with their own containers.
    default long
    internalInsert(long amount, boolean simulate)
    An internal version of insertEnergy(long, boolean) that is used by mod authors looking to directly interact with their own containers.
    long
     
    long
     
    static @Nullable EnergyContainer
    Retrieves an instance of EnergyContainer for the given item stack holder.
    static @Nullable EnergyContainer
    of(net.minecraft.world.level.block.entity.BlockEntity block, @Nullable net.minecraft.core.Direction direction)
    Retrieves an instance of EnergyContainer for the given block entity and direction.
    static @Nullable EnergyContainer
    of(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction direction)
    Retrieves an instance of EnergyContainer for the given level, position, and direction.
    static @Nullable EnergyContainer
    of(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.world.level.block.state.BlockState state, @Nullable net.minecraft.world.level.block.entity.BlockEntity entity, @Nullable net.minecraft.core.Direction direction)
    Retrieves an instance of EnergyContainer for the given level, position, state, entity, and direction.
    default void
    Sets the EnergyContainer with the given state of EnergySnapshot.
    void
    setEnergy(long energy)
    Sets a given amount of energy in the container.

    Methods inherited from interface net.minecraft.world.Clearable

    clearContent

    Methods inherited from interface earth.terrarium.botarium.util.Serializable

    deserialize, serialize
  • Method Details

    • of

      @Nullable @ImplementedByExtension static @Nullable EnergyContainer of(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.world.level.block.state.BlockState state, @Nullable @Nullable net.minecraft.world.level.block.entity.BlockEntity entity, @Nullable @Nullable net.minecraft.core.Direction direction)
      Retrieves an instance of EnergyContainer for the given level, position, state, entity, and direction. This method can be used to retrieve EnergyContainers from Botarium and any other mod that uses the modloader's Energy API.
      Parameters:
      level - The level of the EnergyContainer.
      pos - The position of the EnergyContainer.
      state - The block state of the EnergyContainer.
      entity - The block entity associated with the EnergyContainer (can be null).
      direction - The direction of the EnergyContainer (can be null).
      Returns:
      An instance of EnergyContainer. Returns null if the block does not hold energy.
    • of

      @Nullable static @Nullable EnergyContainer of(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.core.Direction direction)
      Retrieves an instance of EnergyContainer for the given level, position, and direction. This method can be used to retrieve EnergyContainers from Botarium and any other mod that uses the modloader's Energy API.
      Parameters:
      level - The level of the EnergyContainer.
      pos - The position of the EnergyContainer.
      direction - The direction of the EnergyContainer (can be null).
      Returns:
      An instance of EnergyContainer. Returns null if the block does not hold energy.
    • of

      @Nullable static @Nullable EnergyContainer of(net.minecraft.world.level.block.entity.BlockEntity block, @Nullable @Nullable net.minecraft.core.Direction direction)
      Retrieves an instance of EnergyContainer for the given block entity and direction. This method can be used to retrieve EnergyContainers from Botarium and any other mod that uses the modloader's Energy API.
      Parameters:
      block - The block entity associated with the EnergyContainer.
      direction - The direction of the EnergyContainer (can be null).
      Returns:
      An instance of EnergyContainer. Returns null if the block does not hold energy.
    • of

      @Nullable @ImplementedByExtension static @Nullable EnergyContainer of(ItemStackHolder holder)
      Retrieves an instance of EnergyContainer for the given item stack holder. On Fabric, the item stack holder's internal stack will be mutated, and you should replace the item stack inside the container inside with the stack from ItemStackHolder.getStack(). This method can be used to retrieve EnergyContainers from Botarium and any other mod that uses the modloader's Energy API.
      Parameters:
      holder - The item stack holder.
      Returns:
      An instance of EnergyContainer. Returns null if the item stack does not hold energy.
    • holdsEnergy

      @ImplementedByExtension static boolean holdsEnergy(net.minecraft.world.item.ItemStack stack)
      Checks if an ItemStack holds energy. This method can be used to check ItemStacks from Botarium and any other mod that uses the modloader's Energy API.
      Parameters:
      stack - The ItemStack to check.
      Returns:
      True if the ItemStack holds energy, false otherwise.
    • holdsEnergy

      @ImplementedByExtension static boolean holdsEnergy(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.world.level.block.state.BlockState state, @Nullable @Nullable net.minecraft.world.level.block.entity.BlockEntity entity, @Nullable @Nullable net.minecraft.core.Direction direction)
      Checks if the given block at the specified position and state holds energy. This method can be used to check blocks from Botarium and any other mod that uses the modloader's Energy API.

      NOTE: While Fabric and NeoForge support attaching energy to blocks, MinecraftForge does not. This means that while Botarium does support energy blocks on Fabric and NeoForge, it does not support them on Forge, and this method will always return false on a block without a block entity on MinecraftForge.

      Parameters:
      level - The level of the block.
      pos - The position of the block.
      state - The block state.
      entity - The block entity associated with the block (can be null).
      direction - The direction of the block (can be null).
      Returns:
      True if the block holds energy, false otherwise.
    • holdsEnergy

      static boolean holdsEnergy(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.core.Direction direction)
      Checks if the given block at the specified position and state holds energy. This method can be used to check blocks from Botarium and any other mod that uses the modloader's Energy API.

      NOTE: While Fabric and NeoForge support attaching energy to blocks, MinecraftForge does not. This means that while Botarium does support energy blocks on Fabric and NeoForge, it does not support them on Forge, and this method will always return false on a block without a block entity on MinecraftForge.

      Parameters:
      level - The level of the block.
      pos - The position of the block.
      direction - The direction of the block (can be null).
      Returns:
      True if the block holds energy, false otherwise.
    • holdsEnergy

      static boolean holdsEnergy(net.minecraft.world.level.block.entity.BlockEntity block, @Nullable @Nullable net.minecraft.core.Direction direction)
      Checks if the given block entity holds energy. This method can be used to check block entities from Botarium and any other mod that uses the modloader's Energy API.
      Parameters:
      block - The block entity to check.
      direction - The direction of the block entity (can be null).
      Returns:
      True if the block entity holds energy, false otherwise.
    • insertEnergy

      long insertEnergy(long maxAmount, boolean simulate)
      Inserts a given amount of energy into the container.
      Parameters:
      maxAmount - 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.
    • internalInsert

      default long internalInsert(long amount, boolean simulate)
      An internal version of 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 insertEnergy(long, boolean).

    • extractEnergy

      long extractEnergy(long maxAmount, boolean simulate)
      Extracts a given amount of energy into the container.
      Parameters:
      maxAmount - 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.
    • internalExtract

      default long internalExtract(long amount, boolean simulate)
      An internal version of 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 extractEnergy(long, boolean).

    • setEnergy

      void setEnergy(long energy)
      Sets a given amount of energy in the container.
      Parameters:
      energy - The amount of energy to set in the container.
    • getStoredEnergy

      long getStoredEnergy()
      Returns:
      The amount of energy in the container.
    • getMaxCapacity

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

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

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

      boolean allowsInsertion()
      Returns:
      Whether the container allows for energy to be inserted.
    • allowsExtraction

      boolean allowsExtraction()
      Returns:
      Whether the container allows for energy to be extracted.
    • createSnapshot

      EnergySnapshot createSnapshot()
      Returns:
      A EnergySnapshot of the given state of the EnergyContainer.
    • readSnapshot

      default void readSnapshot(EnergySnapshot snapshot)
      Sets the EnergyContainer with the given state of EnergySnapshot.
      Parameters:
      snapshot - The EnergySnapshot to set the EnergyContainer to.