Class AbstractEnergyNode
java.lang.Object
com.github.darksoulq.abyssallib.common.energy.AbstractEnergyNode
- All Implemented Interfaces:
EnergyNode
Base implementation of
EnergyNode providing standard storage, transfer,
and connection handling without automatic registration into EnergyNetwork.
This class manages internal energy storage, directional transfer limits, and connection mappings. Subclasses are responsible for defining behavior such as type identification and optional external registration.
-
Field Summary
Fields inherited from interface EnergyNode
CODEC -
Constructor Summary
ConstructorsConstructorDescriptionAbstractEnergyNode(double capacity, double maxInsert, double maxExtract, double initial) Creates a new energy node using the default unitEnergyUnits.PE.AbstractEnergyNode(double capacity, double maxInsert, double maxExtract, double initial, EnergyUnit unit) Creates a new energy node with explicit configuration. -
Method Summary
Modifier and TypeMethodDescriptiondoubleAttempts to extract energy from this node.doubleMap<org.bukkit.block.BlockFace, EnergyNode> doubledoubledoublegetUnit()doubleAttempts to insert energy into this node.voidsetCapacity(double cap) Updates the maximum capacity of this node.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EnergyNode
canProvide, canReceive, connect, disconnect, getLocation, getType
-
Constructor Details
-
AbstractEnergyNode
public AbstractEnergyNode(double capacity, double maxInsert, double maxExtract, double initial, EnergyUnit unit) Creates a new energy node with explicit configuration.- Parameters:
capacity- maximum energy storage capacitymaxInsert- maximum energy insertion rate per operationmaxExtract- maximum energy extraction rate per operationinitial- initial stored energy (clamped between0andcapacity)unit- energy unit used for this node
-
AbstractEnergyNode
public AbstractEnergyNode(double capacity, double maxInsert, double maxExtract, double initial) Creates a new energy node using the default unitEnergyUnits.PE.- Parameters:
capacity- maximum energy storage capacitymaxInsert- maximum energy insertion rate per operationmaxExtract- maximum energy extraction rate per operationinitial- initial stored energy
-
-
Method Details
-
getUnit
- Specified by:
getUnitin interfaceEnergyNode- Returns:
- unit used by this node
-
getConnections
- Specified by:
getConnectionsin interfaceEnergyNode- Returns:
- map of connected nodes by face
-
getEnergy
public double getEnergy()- Specified by:
getEnergyin interfaceEnergyNode- Returns:
- current stored energy
-
getCapacity
public double getCapacity()- Specified by:
getCapacityin interfaceEnergyNode- Returns:
- maximum energy capacity
-
getMaxInsert
public double getMaxInsert()- Specified by:
getMaxInsertin interfaceEnergyNode- Returns:
- max energy accepted per tick
-
getMaxExtract
public double getMaxExtract()- Specified by:
getMaxExtractin interfaceEnergyNode- Returns:
- max energy extracted per tick
-
insert
public double insert(@Nullable @Nullable org.bukkit.block.BlockFace side, double amount, Action action) Attempts to insert energy into this node.- Specified by:
insertin interfaceEnergyNode- Parameters:
side- the side the energy is inserted from, ornullamount- the amount of energy to insertaction- whether to execute or simulate- Returns:
- the amount of energy accepted
-
extract
public double extract(@Nullable @Nullable org.bukkit.block.BlockFace side, double amount, Action action) Attempts to extract energy from this node.- Specified by:
extractin interfaceEnergyNode- Parameters:
side- the side the energy is extracted from, ornullamount- the amount of energy to extractaction- whether to execute or simulate- Returns:
- the amount of energy extracted
-
setCapacity
public void setCapacity(double cap) Updates the maximum capacity of this node.If the current energy exceeds the new capacity, it will be clamped and a change event will be fired.
- Parameters:
cap- the new capacity value
-