Class EnergyHandlerUtil
java.lang.Object
net.neoforged.neoforge.transfer.energy.EnergyHandlerUtil
Utility class for handling various
EnergyHandler interactions-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intCalculates the redstone signal strength based on the given energy handler's content.static booleanisFull(EnergyHandler handler) Checks if anEnergyHandleris full.static intmove(@Nullable EnergyHandler from, @Nullable EnergyHandler to, int amount, @Nullable TransactionContext transaction) Moves energy between two handlers, and return the amount that was successfully transferred.
-
Constructor Details
-
EnergyHandlerUtil
private EnergyHandlerUtil()
-
-
Method Details
-
isFull
Checks if anEnergyHandleris full.An energy handler is considered full if its amount is greater than or equal to its capacity.
- Parameters:
handler- theEnergyHandlerto check- Returns:
trueif theEnergyHandleris full,falseotherwise
-
getRedstoneSignalFromEnergyHandler
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, ornullif 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.
-