Interface IHeatExchangerLogic

All Superinterfaces:
net.minecraftforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
All Known Subinterfaces:
IHeatExchangerAdapter
All Known Implementing Classes:
HeatExchangerLogicAmbient, HeatExchangerLogicConstant, HeatExchangerLogicTicking, IHeatExchangerAdapter.Simple, Mek2PNCHeatProvider.Mek2PNCHeatAdapter

public interface IHeatExchangerLogic extends net.minecraftforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
Represents a heat exchanger owned by a block entity. Retrieve instances of this via capability lookup; you can use PNCCapabilities.HEAT_EXCHANGER_CAPABILITY or get your own instance with CapabilityManager.get(CapabilityToken).

If you are implementing a block entity with a heat exchanger, you should not implement this interface yourself; get an instance of it via IHeatRegistry.makeHeatExchangerLogic(), store it as field in your BE, and provide it via capability as described above. Your BE should also call tick() and initializeAsHull(Level, BlockPos, BiPredicate, Direction...) as documented in those methods.

If you want to attach this capability as an adapater to other mods' heat systems, see IHeatExchangerAdapter and IHeatExchangerAdapter.Simple which are convenience extensions and implementations of this interface.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final BiPredicate<net.minecraft.world.level.LevelAccessor,net.minecraft.core.BlockPos>
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    When called, this will create a thermal connection between this heat exchanger and the given one.
    default void
    addConnectedExchanger(IHeatExchangerLogic exchanger, boolean reciprocate)
     
    void
    addHeat(double amount)
    Adds heat (= deltaT * Thermal Capacity) to this exchanger.
    default void
    Register a listener which will be called if the temperature of this heat exchanger changes.
    default void
    deserializeNBT(net.minecraft.nbt.CompoundTag nbt)
     
    double
    Get the heat exchanger's ambient temperature, i.e.
    default <T extends HeatBehaviour>
    Optional<T>
    getHeatBehaviour(net.minecraft.core.BlockPos pos, Class<T> cls)
    Get the HeatBehaviour at the given position, which must be adjacent to this heat exchanger's owning tile entity, and in this heat exchanger's list of heat behaviours that it handles.
    double
    Get the heat exchanger's current (precise) temperature.
    int
    Get the heat exchanger's current temperature to the nearest integer.
    double
    Get this heat exchanger's thermal capacity.
    double
    Get this heat exchanger's thermal resistance.
    void
    initializeAmbientTemperature(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
    Initialize this heat exchanger's ambient temperature based on the given world & position.
    void
    initializeAsHull(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, BiPredicate<net.minecraft.world.level.LevelAccessor,net.minecraft.core.BlockPos> blockFilter, net.minecraft.core.Direction... validSides)
    Discovers all heat exchanging neighbor block entities (i.e.
    boolean
    isSideConnected(net.minecraft.core.Direction side)
    Check if this side of the heat exchanger has a thermal connection of any kind to the neighbouring block in the given direction; whether to another heat exchanger, a static heat source like air, or a custom handler such as a furnace or heat frame.
    default void
    Disconnect a connected heat exchanger which was connected via addConnectedExchanger(IHeatExchangerLogic)
    default void
    removeConnectedExchanger(IHeatExchangerLogic exchanger, boolean reciprocate)
     
    default void
    Removed a registered temperture listener.
    default net.minecraft.nbt.CompoundTag
     
    void
    setTemperature(double temperature)
    Set the temperature of this heat exchanger.
    void
    setThermalCapacity(double capacity)
    Set this heat exchanger's thermal capacity.
    void
    setThermalResistance(double thermalResistance)
    The higher the thermal resistance, the slower the heat disperses.
    void
    Call this to tick this logic, and make the heat disperse itself.
  • Field Details

    • ALL_BLOCKS

      static final BiPredicate<net.minecraft.world.level.LevelAccessor,net.minecraft.core.BlockPos> ALL_BLOCKS
  • Method Details

    • tick

      void tick()
      Call this to tick this logic, and make the heat disperse itself. In general this should be called each tick by the owning block entity's tick() method, on the server side only.
    • initializeAsHull

      void initializeAsHull(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, BiPredicate<net.minecraft.world.level.LevelAccessor,net.minecraft.core.BlockPos> blockFilter, net.minecraft.core.Direction... validSides)
      Discovers all heat exchanging neighbor block entities (i.e. block entities who provide the IHeatExchangerLogic capability on that side) and adds them as connected heat exchangers. It also accounts for neighbouring blocks with special heat properties, like Magma or Lava, and other special cases like Heat Frames (which are entities).

      This should be called by the owning block entity on first tick (IForgeBlockEntity.onLoad() is suitable) and when neighboring blocks update (BlockBehaviour.neighborChanged(BlockState, Level, BlockPos, Block, BlockPos, boolean).

      You don't need to call this method if this heat exchanger is not connected to the outside world (e.g. the internal connecting heat exchanger within a Vortex Tube).

      Parameters:
      world - the world
      pos - the blockpos of the owning block entity
      blockFilter - a whitelist check; can be used to exclude certain blocks, e.g. air or fluids. In most cases, ALL_BLOCKS can be passed here.
      validSides - an array of sides to check for heat exchanging neighbours
    • initializeAmbientTemperature

      void initializeAmbientTemperature(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
      Initialize this heat exchanger's ambient temperature based on the given world & position. You don't need to call this method if your heat exchanger is a hull exchanger (i.e. provides an IHeatExchangerLogic object via capability lookup), as such heat exchangers are automatically initialized by initializeAsHull(Level, BlockPos, BiPredicate, Direction...).
      Parameters:
      world - the world
      pos - the position
    • addConnectedExchanger

      default void addConnectedExchanger(IHeatExchangerLogic exchanger)
      When called, this will create a thermal connection between this heat exchanger and the given one. This should be used when your BE contains more than one heat exchanger and you need a thermal connection between them; an example is the hot and cold ends of the Vortex Tube.

      You don't need to call this method if your BE just has one heat exchanger to expose to the world; in that case initializeAsHull(Level, BlockPos, BiPredicate, Direction...) will handle connecting your BE's heat exchanger to neighbouring blocks.

      You should only call this method on one of the two heat exchangers being connected; a reciprocal connection on the target heat exchanger will automatically be added.

      Parameters:
      exchanger - the other heat exchanger
    • addConnectedExchanger

      default void addConnectedExchanger(IHeatExchangerLogic exchanger, boolean reciprocate)
      Parameters:
      exchanger - the other heat exchanger
      reciprocate - whether the other exchanger should also add this one
      API Note:
      non-api; don't call directly
    • removeConnectedExchanger

      default void removeConnectedExchanger(IHeatExchangerLogic exchanger)
      Disconnect a connected heat exchanger which was connected via addConnectedExchanger(IHeatExchangerLogic)
      Parameters:
      exchanger - the other heat exchanger
    • removeConnectedExchanger

      default void removeConnectedExchanger(IHeatExchangerLogic exchanger, boolean reciprocate)
      Parameters:
      exchanger - the other heat exchanger
      reciprocate - whether the other exchanger should also remove this one
      API Note:
      non-api; don't call directly
    • setTemperature

      void setTemperature(double temperature)
      Set the temperature of this heat exchanger. By default, heat exchangers start with a temperature equal to the ambient temperature (in the case of non-hull exchangers which have not been initialized, the default temperature is 300K, the Forge-defined temperature of water).
      Parameters:
      temperature - in degrees Kelvin
    • getTemperature

      double getTemperature()
      Get the heat exchanger's current (precise) temperature. This should only be used on the server where precise values are required; it isn't synced to clients by default for performance reasons. Use getTemperatureAsInt() there instead.
      Returns:
      the temperature
    • getTemperatureAsInt

      int getTemperatureAsInt()
      Get the heat exchanger's current temperature to the nearest integer. This is sync'd to clients rather than the precise floating-point temperature to avoid excessive network chatter.
      Returns:
      the temperature to the nearest integer
    • getAmbientTemperature

      double getAmbientTemperature()
      Get the heat exchanger's ambient temperature, i.e. the temperature at which it initially starts, dependent on its environment (biome and altitude).
      Returns:
      the ambient temperature
    • setThermalResistance

      void setThermalResistance(double thermalResistance)
      The higher the thermal resistance, the slower the heat disperses. The effective resistance is the sum of this resistance plus the neighbour's resistance; if both exchangers have a resistance of 1, heat will equalize in a single tick under normal circumstances.
      Parameters:
      thermalResistance - the thermal resistance; higher resistance means slower heat transfer
    • getThermalResistance

      double getThermalResistance()
      Get this heat exchanger's thermal resistance. See setThermalResistance(double) for more information on thermal resistance.
      Returns:
      the thermal resistance; higher resistance means slower heat transfer
    • setThermalCapacity

      void setThermalCapacity(double capacity)
      Set this heat exchanger's thermal capacity.

      The higher the capacity, the more heat can be 'stored'. E.g. an object with a heat capacity of double the heat capacity of another object will require twice as much heat gain or loss to adjust the temperature by the same amount.

      Parameters:
      capacity - the thermal capacity
    • getThermalCapacity

      double getThermalCapacity()
      Get this heat exchanger's thermal capacity. See setThermalCapacity(double) for more information.
      Returns:
      the thermal capacity.
    • addHeat

      void addHeat(double amount)
      Adds heat (= deltaT * Thermal Capacity) to this exchanger. Negative values will remove heat.
      Parameters:
      amount - the heat amount
    • isSideConnected

      boolean isSideConnected(net.minecraft.core.Direction side)
      Check if this side of the heat exchanger has a thermal connection of any kind to the neighbouring block in the given direction; whether to another heat exchanger, a static heat source like air, or a custom handler such as a furnace or heat frame. The connection data is initialized in initializeAsHull(Level, BlockPos, BiPredicate, Direction...).
      Parameters:
      side - the side to check
      Returns:
      true if this side has a thermal connection of any kind
    • addTemperatureListener

      default void addTemperatureListener(@NotNull @NotNull TemperatureListener listener)
      Register a listener which will be called if the temperature of this heat exchanger changes. This is ignored for heat exchangers with constant temperature (i.e. ambient temperatures or non-block-entity blocks).
      Parameters:
      listener - a listener which receives the new temperature
    • removeTemperatureListener

      default void removeTemperatureListener(@NotNull @NotNull TemperatureListener listener)
      Removed a registered temperture listener. This should be called when the listening object goes out of scope.
      Parameters:
      listener - the listener to remove
    • serializeNBT

      default net.minecraft.nbt.CompoundTag serializeNBT()
      Specified by:
      serializeNBT in interface net.minecraftforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
    • deserializeNBT

      default void deserializeNBT(net.minecraft.nbt.CompoundTag nbt)
      Specified by:
      deserializeNBT in interface net.minecraftforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
    • getHeatBehaviour

      default <T extends HeatBehaviour> Optional<T> getHeatBehaviour(net.minecraft.core.BlockPos pos, Class<T> cls)
      Get the HeatBehaviour at the given position, which must be adjacent to this heat exchanger's owning tile entity, and in this heat exchanger's list of heat behaviours that it handles.
      Type Parameters:
      T - the heat behaviour type
      Parameters:
      pos - position of the heat behaviour
      cls - required class of the heat behaviour (any heat behaviour which extends this class will match)
      Returns:
      an optional heat behaviour, or Optional.empty() if the position is invalid or there is no matching heat behaviour there