Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hasEnoughPower() check in ARL #2365

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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);
}
}
Loading