Skip to content

Commit

Permalink
Fix hasEnoughPower() check in ARL (#2365)
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Feb 19, 2024
1 parent 3865f22 commit e5f0194
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -636,33 +636,20 @@ protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe,
* @param resultOverclock the overclock data to use. Format: {@code [EUt, duration]}.
* @return true if there is enough energy to continue recipe progress
*/
protected boolean hasEnoughPower(@NotNull int[] resultOverclock) {
protected boolean hasEnoughPower(int @NotNull [] resultOverclock) {
// Format of resultOverclock: EU/t, duration
int totalEUt = resultOverclock[0] * resultOverclock[1];
int recipeEUt = resultOverclock[0];

// RIP Ternary
// Power Consumption case
if (totalEUt >= 0) {
int capacity;
// If the total consumed power is greater than half the internal capacity
if (totalEUt > getEnergyCapacity() / 2) {
// Only draw 1A of power from the internal buffer to allow for recharging of the internal buffer from
// external sources
capacity = resultOverclock[0];
} else {
// If the total consumed power is less than half the capacity, just drain the whole thing
capacity = totalEUt;
}

// Return true if we have enough energy stored to progress the recipe, either 1A or the whole amount
return getEnergyStored() >= capacity;
if (recipeEUt >= 0) {
// ensure it can run for at least 8 ticks. Arbitrary value, but should prevent instant failures
return getEnergyStored() >= ((long) recipeEUt << 3);
}
// Power Generation case
else {
// This is the EU/t generated by the generator
int power = resultOverclock[0];
// Return true if we can fit at least 1A of energy into the energy output
return getEnergyStored() - (long) power <= getEnergyCapacity();
return getEnergyStored() - (long) recipeEUt <= getEnergyCapacity();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ protected boolean drawEnergy(int recipeEUt, boolean simulate) {
return true; // spoof energy being drawn
}

@Override
protected boolean hasEnoughPower(int @NotNull [] resultOverclock) {
return true;
}

@Override
public long getMaxVoltage() {
return GTValues.LV;
}

@NotNull
@Override
protected int[] runOverclockingLogic(@NotNull IRecipePropertyStorage propertyStorage, int recipeEUt,
long maxVoltage, int recipeDuration, int amountOC) {
protected int @NotNull [] runOverclockingLogic(@NotNull IRecipePropertyStorage propertyStorage, int recipeEUt,
long maxVoltage, int recipeDuration, int amountOC) {
return standardOverclockingLogic(
1,
getMaxVoltage(),
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,23 @@ public long getMaxVoltage() {
return GTValues.V[GTValues.LV];
}

@Override
protected boolean hasEnoughPower(int @NotNull [] resultOverclock) {
int totalSteam = (int) (resultOverclock[0] * resultOverclock[1] / conversionRate);
if (totalSteam > 0) {
long steamStored = getEnergyStored();
long steamCapacity = getEnergyCapacity();
// if the required steam is larger than the full buffer, just require the full buffer
if (steamCapacity < totalSteam) {
return steamCapacity == steamStored;
}
// otherwise require the full amount of steam for the recipe
return steamStored >= totalSteam;
}
// generation case unchanged
return super.hasEnoughPower(resultOverclock);
}

@NotNull
@Override
public NBTTagCompound serializeNBT() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,21 @@ private void performVentingAnimation(BlockPos machinePos, EnumFacing ventingSide
1.0f);
}
}

@Override
protected boolean hasEnoughPower(int @NotNull [] resultOverclock) {
int totalSteam = (int) (resultOverclock[0] * resultOverclock[1] / conversionRate);
if (totalSteam > 0) {
long steamStored = getEnergyStored();
long steamCapacity = getEnergyCapacity();
// if the required steam is larger than the full buffer, just require the full buffer
if (steamCapacity < totalSteam) {
return steamCapacity == steamStored;
}
// otherwise require the full amount of steam for the recipe
return steamStored >= totalSteam;
}
// generation case unchanged
return super.hasEnoughPower(resultOverclock);
}
}

0 comments on commit e5f0194

Please sign in to comment.