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
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
FieldsModifier and TypeFieldDescriptionstatic final BiPredicate<net.minecraft.world.level.LevelAccessor,net.minecraft.core.BlockPos> -
Method Summary
Modifier and TypeMethodDescriptiondefault voidaddConnectedExchanger(IHeatExchangerLogic exchanger) When called, this will create a thermal connection between this heat exchanger and the given one.default voidaddConnectedExchanger(IHeatExchangerLogic exchanger, boolean reciprocate) voidaddHeat(double amount) Adds heat (= deltaT * Thermal Capacity) to this exchanger.default voidaddTemperatureListener(@NotNull TemperatureListener listener) Register a listener which will be called if the temperature of this heat exchanger changes.default voiddeserializeNBT(net.minecraft.nbt.CompoundTag nbt) doubleGet the heat exchanger's ambient temperature, i.e.default <T extends HeatBehaviour>
Optional<T>getHeatBehaviour(net.minecraft.core.BlockPos pos, Class<T> cls) Get theHeatBehaviourat 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.doubleGet the heat exchanger's current (precise) temperature.intGet the heat exchanger's current temperature to the nearest integer.doubleGet this heat exchanger's thermal capacity.doubleGet this heat exchanger's thermal resistance.voidinitializeAmbientTemperature(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos) Initialize this heat exchanger's ambient temperature based on the given world & position.voidinitializeAsHull(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.booleanisSideConnected(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 voidremoveConnectedExchanger(IHeatExchangerLogic exchanger) Disconnect a connected heat exchanger which was connected viaaddConnectedExchanger(IHeatExchangerLogic)default voidremoveConnectedExchanger(IHeatExchangerLogic exchanger, boolean reciprocate) default voidremoveTemperatureListener(@NotNull TemperatureListener listener) Removed a registered temperture listener.default net.minecraft.nbt.CompoundTagvoidsetTemperature(double temperature) Set the temperature of this heat exchanger.voidsetThermalCapacity(double capacity) Set this heat exchanger's thermal capacity.voidsetThermalResistance(double thermalResistance) The higher the thermal resistance, the slower the heat disperses.voidtick()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'stick()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 theIHeatExchangerLogiccapability 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 worldpos- the blockpos of the owning block entityblockFilter- a whitelist check; can be used to exclude certain blocks, e.g. air or fluids. In most cases,ALL_BLOCKScan 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 anIHeatExchangerLogicobject via capability lookup), as such heat exchangers are automatically initialized byinitializeAsHull(Level, BlockPos, BiPredicate, Direction...).- Parameters:
world- the worldpos- the position
-
addConnectedExchanger
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
- Parameters:
exchanger- the other heat exchangerreciprocate- whether the other exchanger should also add this one- API Note:
- non-api; don't call directly
-
removeConnectedExchanger
Disconnect a connected heat exchanger which was connected viaaddConnectedExchanger(IHeatExchangerLogic)- Parameters:
exchanger- the other heat exchanger
-
removeConnectedExchanger
- Parameters:
exchanger- the other heat exchangerreciprocate- 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. UsegetTemperatureAsInt()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. SeesetThermalResistance(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. SeesetThermalCapacity(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 ininitializeAsHull(Level, BlockPos, BiPredicate, Direction...).- Parameters:
side- the side to check- Returns:
- true if this side has a thermal connection of any kind
-
addTemperatureListener
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
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:
serializeNBTin interfacenet.minecraftforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
-
deserializeNBT
default void deserializeNBT(net.minecraft.nbt.CompoundTag nbt) - Specified by:
deserializeNBTin interfacenet.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 theHeatBehaviourat 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 behaviourcls- 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
-