Class LimitingEnergyHandler
java.lang.Object
net.neoforged.neoforge.transfer.energy.DelegatingEnergyHandler
net.neoforged.neoforge.transfer.energy.LimitingEnergyHandler
- All Implemented Interfaces:
EnergyHandler
An energy handler that will apply additional per-insert and per-extract limits to another handler.
-
Field Summary
FieldsFields inherited from class net.neoforged.neoforge.transfer.energy.DelegatingEnergyHandler
delegate -
Constructor Summary
ConstructorsConstructorDescriptionLimitingEnergyHandler(Supplier<EnergyHandler> delegate, int maxInsert, int maxExtract) Creates a new limiting energy handler.LimitingEnergyHandler(EnergyHandler delegate, int maxInsert, int maxExtract) Creates a new limiting energy handler. -
Method Summary
Modifier and TypeMethodDescriptionintextract(int amount, TransactionContext transaction) Extracts up to the given amount of energy from the handler.intinsert(int amount, TransactionContext transaction) Inserts up to the given amount of energy into the handler.Methods inherited from class net.neoforged.neoforge.transfer.energy.DelegatingEnergyHandler
getAmountAsLong, getCapacityAsLong, getDelegateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.neoforged.neoforge.transfer.energy.EnergyHandler
getAmountAsInt, getCapacityAsInt
-
Field Details
-
maxInsert
protected int maxInsert -
maxExtract
protected int maxExtract
-
-
Constructor Details
-
LimitingEnergyHandler
Creates a new limiting energy handler.- See Also:
-
LimitingEnergyHandler
Creates a new limiting energy handler.- Parameters:
delegate- energy handler to wrapmaxInsert- maximum amount of energy that can be inserted in one operation. Can be 0 to disallow insertion entirely.maxExtract- maximum amount of energy that can be extracted in one operation. Can be 0 to disallow extraction entirely.
-
-
Method Details
-
insert
Description copied from interface:EnergyHandlerInserts up to the given amount of energy into the handler.Changes to the handler are made in the context of a transaction.
- Specified by:
insertin interfaceEnergyHandler- Overrides:
insertin classDelegatingEnergyHandler- Parameters:
amount- The maximum amount of energy to insert. Must be non-negative.transaction- The transaction that this operation is part of.- Returns:
- The amount that was inserted. Between
0(inclusive, nothing was inserted) andamount(inclusive, everything was inserted).
-
extract
Description copied from interface:EnergyHandlerExtracts up to the given amount of energy from the handler.Changes to the handler are made in the context of a transaction.
- Specified by:
extractin interfaceEnergyHandler- Overrides:
extractin classDelegatingEnergyHandler- Parameters:
amount- The maximum amount of energy to extract. Must be non-negative.transaction- The transaction that this operation is part of.- Returns:
- The amount that was extracted. Between
0(inclusive, nothing was extracted) andamount(inclusive, everything was extracted).
-