Skip to content

Commit

Permalink
Implement some epsilon related checks for heat so that fusion reactor…
Browse files Browse the repository at this point in the history
…s don't occasionally just get marked as dirty all the time when inactive
  • Loading branch information
pupnewfster committed Aug 1, 2023
1 parent 6fc8754 commit 0071ff4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/api/java/mekanism/api/heat/HeatAPI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mekanism.api.heat;

import com.mojang.math.Constants;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.level.LevelReader;
Expand Down Expand Up @@ -33,6 +34,12 @@ private HeatAPI() {
* Default inverse insulation coefficient
*/
public static final double DEFAULT_INVERSE_INSULATION = 0;
/**
* Represents the value at which changes to heat below this amount will not be taken into account by Mekanism.
*
* @since 10.4.0
*/
public static final double EPSILON = Constants.EPSILON;

/**
* Gets the atmospheric temperature at a given spot in the specified world based on the biome's temperature modifier at that position. The baseline temperature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,22 @@ private long burnFuel() {
private void transferHeat() {
//Transfer from plasma to casing
double plasmaCaseHeat = plasmaCaseConductivity * (lastPlasmaTemperature - lastCaseTemperature);
setPlasmaTemp(getPlasmaTemp() - plasmaCaseHeat / plasmaHeatCapacity);
heatCapacitor.handleHeat(plasmaCaseHeat);
if (Math.abs(plasmaCaseHeat) > HeatAPI.EPSILON) {
setPlasmaTemp(getPlasmaTemp() - plasmaCaseHeat / plasmaHeatCapacity);
heatCapacitor.handleHeat(plasmaCaseHeat);
}

//Transfer from casing to water if necessary
double caseWaterHeat = MekanismGeneratorsConfig.generators.fusionWaterHeatingRatio.get() * (lastCaseTemperature - biomeAmbientTemp);
int waterToVaporize = (int) (HeatUtils.getSteamEnergyEfficiency() * caseWaterHeat / HeatUtils.getWaterThermalEnthalpy());
waterToVaporize = Math.min(waterToVaporize, Math.min(waterTank.getFluidAmount(), MathUtils.clampToInt(steamTank.getNeeded())));
if (waterToVaporize > 0) {
MekanismUtils.logMismatchedStackSize(waterTank.shrinkStack(waterToVaporize, Action.EXECUTE), waterToVaporize);
steamTank.insert(MekanismGases.STEAM.getStack(waterToVaporize), Action.EXECUTE, AutomationType.INTERNAL);
caseWaterHeat = waterToVaporize * HeatUtils.getWaterThermalEnthalpy() / HeatUtils.getSteamEnergyEfficiency();
heatCapacitor.handleHeat(-caseWaterHeat);
if (Math.abs(caseWaterHeat) > HeatAPI.EPSILON) {
int waterToVaporize = (int) (HeatUtils.getSteamEnergyEfficiency() * caseWaterHeat / HeatUtils.getWaterThermalEnthalpy());
waterToVaporize = Math.min(waterToVaporize, Math.min(waterTank.getFluidAmount(), MathUtils.clampToInt(steamTank.getNeeded())));
if (waterToVaporize > 0) {
MekanismUtils.logMismatchedStackSize(waterTank.shrinkStack(waterToVaporize, Action.EXECUTE), waterToVaporize);
steamTank.insert(MekanismGases.STEAM.getStack(waterToVaporize), Action.EXECUTE, AutomationType.INTERNAL);
caseWaterHeat = waterToVaporize * HeatUtils.getWaterThermalEnthalpy() / HeatUtils.getSteamEnergyEfficiency();
heatCapacitor.handleHeat(-caseWaterHeat);
}
}

HeatTransfer heatTransfer = simulate();
Expand All @@ -318,8 +322,10 @@ private void transferHeat() {

//Passive energy generation
double caseAirHeat = MekanismGeneratorsConfig.generators.fusionCasingThermalConductivity.get() * (lastCaseTemperature - biomeAmbientTemp);
heatCapacitor.handleHeat(-caseAirHeat);
energyContainer.insert(FloatingLong.create(caseAirHeat * MekanismGeneratorsConfig.generators.fusionThermocoupleEfficiency.get()), Action.EXECUTE, AutomationType.INTERNAL);
if (Math.abs(caseAirHeat) > HeatAPI.EPSILON) {
heatCapacitor.handleHeat(-caseAirHeat);
energyContainer.insert(FloatingLong.create(caseAirHeat * MekanismGeneratorsConfig.generators.fusionThermocoupleEfficiency.get()), Action.EXECUTE, AutomationType.INTERNAL);
}
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void handleHeat(double transfer) {
}

public void update() {
if (heatToHandle != 0) {
if (heatToHandle != 0 && Math.abs(heatToHandle) > HeatAPI.EPSILON) {
initStoredHeat();
storedHeat += heatToHandle;
//notify listeners
Expand Down

0 comments on commit 0071ff4

Please sign in to comment.