Class EnergyHandlerUtil

java.lang.Object
net.neoforged.neoforge.transfer.energy.EnergyHandlerUtil

public final class EnergyHandlerUtil extends Object
Utility class for handling various EnergyHandler interactions
  • Constructor Details

    • EnergyHandlerUtil

      private EnergyHandlerUtil()
  • Method Details

    • isFull

      public static boolean isFull(EnergyHandler handler)
      Checks if an EnergyHandler is full.

      An energy handler is considered full if its amount is greater than or equal to its capacity.

      Parameters:
      handler - the EnergyHandler to check
      Returns:
      true if the EnergyHandler is full, false otherwise
    • getRedstoneSignalFromEnergyHandler

      public static int getRedstoneSignalFromEnergyHandler(EnergyHandler handler)
      Calculates the redstone signal strength based on the given energy handler's content. This value is between 0 and 15.

      This method is based on AbstractContainerMenu.getRedstoneSignalFromContainer(Container).

      Parameters:
      handler - the energy handler to calculate the signal from
      Returns:
      the redstone signal strength
    • move

      public static int move(@Nullable @Nullable EnergyHandler from, @Nullable @Nullable EnergyHandler to, int amount, @Nullable @Nullable TransactionContext transaction)
      Moves energy between two handlers, and return the amount that was successfully transferred.
      Parameters:
      from - The source handler. Will no-op if null.
      to - The target handler. Will no-op if null.
      amount - The maximum amount that will be transferred.
      transaction - The transaction this transfer is part of, or null if a transaction should be opened just for this transfer.
      Returns:
      The total amount of energy that was successfully transferred.
      Throws:
      IllegalStateException - If no transaction is passed.
      IllegalArgumentException - If amount is negative.