Class AbstractEnergyNode

java.lang.Object
com.github.darksoulq.abyssallib.common.energy.AbstractEnergyNode
All Implemented Interfaces:
EnergyNode

public abstract class AbstractEnergyNode extends Object implements 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.

  • 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 capacity
      maxInsert - maximum energy insertion rate per operation
      maxExtract - maximum energy extraction rate per operation
      initial - initial stored energy (clamped between 0 and capacity)
      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 unit EnergyUnits.PE.
      Parameters:
      capacity - maximum energy storage capacity
      maxInsert - maximum energy insertion rate per operation
      maxExtract - maximum energy extraction rate per operation
      initial - initial stored energy
  • Method Details

    • getUnit

      public EnergyUnit getUnit()
      Specified by:
      getUnit in interface EnergyNode
      Returns:
      unit used by this node
    • getConnections

      public Map<org.bukkit.block.BlockFace, EnergyNode> getConnections()
      Specified by:
      getConnections in interface EnergyNode
      Returns:
      map of connected nodes by face
    • getEnergy

      public double getEnergy()
      Specified by:
      getEnergy in interface EnergyNode
      Returns:
      current stored energy
    • getCapacity

      public double getCapacity()
      Specified by:
      getCapacity in interface EnergyNode
      Returns:
      maximum energy capacity
    • getMaxInsert

      public double getMaxInsert()
      Specified by:
      getMaxInsert in interface EnergyNode
      Returns:
      max energy accepted per tick
    • getMaxExtract

      public double getMaxExtract()
      Specified by:
      getMaxExtract in interface EnergyNode
      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:
      insert in interface EnergyNode
      Parameters:
      side - the side the energy is inserted from, or null
      amount - the amount of energy to insert
      action - 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:
      extract in interface EnergyNode
      Parameters:
      side - the side the energy is extracted from, or null
      amount - the amount of energy to extract
      action - 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