Skip to content

Commit

Permalink
Fix EUt usage of HPCA with custom higher tier Components (#2512)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4c1f89f)
  • Loading branch information
Synthitic authored and TechLord22 committed Jul 7, 2024
1 parent 809a581 commit 27a55e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected void updateFormedValid() {
}

private void consumeEnergy() {
int energyToConsume = hpcaHandler.getCurrentEUt();
long energyToConsume = hpcaHandler.getCurrentEUt();
boolean hasMaintenance = ConfigHolder.machines.enableMaintenance && hasMaintenanceMechanics();
if (hasMaintenance) {
// 10% more energy per maintenance problem
Expand Down Expand Up @@ -377,7 +377,7 @@ protected ModularUI.Builder createUITemplate(EntityPlayer entityPlayer) {
protected void addDisplayText(List<ITextComponent> textList) {
MultiblockDisplayText.builder(textList, isStructureFormed())
.setWorkingStatus(true, hpcaHandler.getAllocatedCWUt() > 0) // transform into two-state system for
// display
// display
.setWorkingStatusKeys(
"gregtech.multiblock.idling",
"gregtech.multiblock.idling",
Expand Down Expand Up @@ -580,7 +580,7 @@ public static class HPCAGridHandler {

// cached gui info
// holding these values past the computation clear because GUI is too "late" to read the state in time
private int cachedEUt;
private long cachedEUt;
private int cachedCWUt;

public HPCAGridHandler(@Nullable MetaTileEntityHPCA controller) {
Expand Down Expand Up @@ -760,10 +760,10 @@ public int getMaxCWUt() {
}

/** The current EU/t this HPCA should use, considering passive drain, current computation, etc.. */
public int getCurrentEUt() {
public long getCurrentEUt() {
int maximumCWUt = Math.max(1, getMaxCWUt()); // behavior is no different setting this to 1 if it is 0
int maximumEUt = getMaxEUt();
int upkeepEUt = getUpkeepEUt();
long maximumEUt = getMaxEUt();
long upkeepEUt = getUpkeepEUt();

if (maximumEUt == upkeepEUt) {
return maximumEUt;
Expand All @@ -775,17 +775,17 @@ public int getCurrentEUt() {
}

/** The amount of EU/t this HPCA uses just to stay on with 0 output computation. */
public int getUpkeepEUt() {
int upkeepEUt = 0;
public long getUpkeepEUt() {
long upkeepEUt = 0;
for (var component : components) {
upkeepEUt += component.getUpkeepEUt();
}
return upkeepEUt;
}

/** The maximum EU/t that this HPCA could ever use with the given configuration. */
public int getMaxEUt() {
int maximumEUt = 0;
public long getMaxEUt() {
long maximumEUt = 0;
for (var component : components) {
maximumEUt += component.getMaxEUt();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ public void Test_Edge_No_Computation() {
.coolingAmount(4)));

final int maxCWUt = handler.getMaxCWUt();
final int upkeepEUt = handler.getUpkeepEUt();
final int maxEUt = handler.getMaxEUt();
final long upkeepEUt = handler.getUpkeepEUt();
final long maxEUt = handler.getMaxEUt();
final int maxCoolingDemand = handler.getMaxCoolantDemand();
final int maxCoolingAmount = handler.getMaxCoolingAmount();
int allocated;
double temperatureChange;

assertThat(maxCWUt, is(0));
assertThat(upkeepEUt, is(32 * 4));
assertThat(maxEUt, is(128 * 4));
assertThat(upkeepEUt, is(32L * 4L));
assertThat(maxEUt, is(128L * 4L));
assertThat(maxCoolingDemand, is(0));
assertThat(maxCoolingAmount, is(4 * 4));

Expand Down Expand Up @@ -69,14 +69,14 @@ public void Test_Edge_Equal_Upkeep_Max_EUt() {
.coolingAmount(2)));

final int maxCWUt = handler.getMaxCWUt();
final int upkeepEUt = handler.getUpkeepEUt();
final int maxEUt = handler.getMaxEUt();
final long upkeepEUt = handler.getUpkeepEUt();
final long maxEUt = handler.getMaxEUt();
final int maxCoolingDemand = handler.getMaxCoolingDemand();
final int maxCoolingAmount = handler.getMaxCoolingAmount();
int allocated, requested;
double temperatureChange;

final int FIXED_EUT = 32 * 8;
final long FIXED_EUT = 32 * 8;
assertThat(maxCWUt, is(4 * 4));
assertThat(upkeepEUt, is(FIXED_EUT));
assertThat(maxEUt, is(FIXED_EUT));
Expand Down Expand Up @@ -115,12 +115,13 @@ public void Test_Random() {
.EUt(() -> r.nextInt(128))
.coolingAmount(() -> r.nextInt(128))));

final int maxEUt = handler.getMaxEUt();
final int upkeepEUt = handler.getUpkeepEUt();
final long maxEUt = handler.getMaxEUt();
final long upkeepEUt = handler.getUpkeepEUt();
final int maxCWUt = handler.getMaxCWUt();
final int maxCoolingDemand = handler.getMaxCoolingDemand();
final int maxCoolingAmount = handler.getMaxCoolingAmount();
int allocated, requested, currentEUt;
int allocated, requested;
long currentEUt;
double temperatureChange;

// exit, we unit test these edge cases elsewhere
Expand Down

0 comments on commit 27a55e0

Please sign in to comment.