Skip to content

Commit 32d2c2d

Browse files
authored
Fix Negative EUt in TOP (#2666)
1 parent 225a53f commit 32d2c2d

File tree

7 files changed

+44
-75
lines changed

7 files changed

+44
-75
lines changed

src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import gregtech.api.GTValues;
44
import gregtech.api.capability.GregtechDataCodes;
55
import gregtech.api.capability.GregtechTileCapabilities;
6+
import gregtech.api.capability.IEnergyContainer;
67
import gregtech.api.capability.IMultiblockController;
78
import gregtech.api.capability.IMultipleTankHandler;
89
import gregtech.api.capability.IWorkable;
@@ -101,17 +102,27 @@ public AbstractRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap, bo
101102
/**
102103
* @return the energy container's energy input per second
103104
*/
104-
protected abstract long getEnergyInputPerSecond();
105+
protected long getEnergyInputPerSecond() {
106+
return getEnergyContainer().getInputPerSec();
107+
}
105108

106109
/**
107110
* @return the energy container's current stored energy
108111
*/
109-
protected abstract long getEnergyStored();
112+
protected long getEnergyStored() {
113+
return getEnergyContainer().getEnergyStored();
114+
}
110115

111116
/**
112117
* @return the energy container's maximum energy capacity
113118
*/
114-
protected abstract long getEnergyCapacity();
119+
protected long getEnergyCapacity() {
120+
return getEnergyContainer().getEnergyCapacity();
121+
}
122+
123+
protected IEnergyContainer getEnergyContainer() {
124+
return IEnergyContainer.DEFAULT;
125+
}
115126

116127
/**
117128
* Draw energy from the energy container
@@ -120,12 +131,22 @@ public AbstractRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap, bo
120131
* @param simulate whether to simulate energy extraction or not
121132
* @return true if the energy can/was drained, otherwise false
122133
*/
123-
protected abstract boolean drawEnergy(long recipeEUt, boolean simulate);
134+
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
135+
// this should be the ONLY time eut is negative!
136+
if (consumesEnergy()) recipeEUt = -recipeEUt;
137+
long resultEnergy = getEnergyStored() + recipeEUt;
138+
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
139+
if (!simulate) getEnergyContainer().changeEnergy(recipeEUt);
140+
return true;
141+
} else return false;
142+
}
124143

125144
/**
126145
* @return the maximum voltage the machine can use/handle for recipe searching
127146
*/
128-
public abstract long getMaxVoltage();
147+
public long getMaxVoltage() {
148+
return Math.max(getEnergyContainer().getInputVoltage(), getEnergyContainer().getOutputVoltage());
149+
}
129150

130151
/**
131152
*
@@ -941,7 +962,7 @@ public String[] getAvailableOverclockingTiers() {
941962
protected void setupRecipe(@NotNull Recipe recipe) {
942963
this.progressTime = 1;
943964
setMaxProgress(ocResult.duration());
944-
this.recipeEUt = consumesEnergy() ? ocResult.eut() : -ocResult.eut();
965+
this.recipeEUt = ocResult.eut();
945966

946967
int recipeTier = GTUtility.getTierByVoltage(recipe.getEUt());
947968
int machineTier = getOverclockForTier(getMaximumOverclockVoltage());
@@ -1226,7 +1247,7 @@ public void deserializeNBT(@NotNull NBTTagCompound compound) {
12261247
if (progressTime > 0) {
12271248
this.isActive = true;
12281249
this.maxProgressTime = compound.getInteger("MaxProgress");
1229-
this.recipeEUt = compound.getLong("RecipeEUt");
1250+
this.recipeEUt = Math.abs(compound.getLong("RecipeEUt"));
12301251
NBTTagList itemOutputsList = compound.getTagList("ItemOutputs", Constants.NBT.TAG_COMPOUND);
12311252
this.itemOutputs = new ArrayList<>(itemOutputsList.tagCount());
12321253
for (int i = 0; i < itemOutputsList.tagCount(); i++) {

src/main/java/gregtech/api/capability/impl/BoilerRecipeLogic.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gregtech.api.capability.impl;
22

33
import gregtech.api.GTValues;
4+
import gregtech.api.capability.IEnergyContainer;
45
import gregtech.api.capability.IMultiblockController;
56
import gregtech.api.capability.IMultipleTankHandler;
67
import gregtech.api.recipes.Recipe;
@@ -330,6 +331,12 @@ public long getMaxVoltage() {
330331
return 0;
331332
}
332333

334+
@Override
335+
protected IEnergyContainer getEnergyContainer() {
336+
GTLog.logger.error("Large Boiler called getEnergyContainer(), this should not be possible!");
337+
return super.getEnergyContainer();
338+
}
339+
333340
/**
334341
* @param fluidHandler the handler to drain from
335342
* @param amount the amount to drain

src/main/java/gregtech/api/capability/impl/MultiblockFuelRecipeLogic.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,9 @@ protected long boostProduction(long production) {
9595
}
9696

9797
@Override
98-
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
99-
long euToDraw = boostProduction(recipeEUt);
100-
long resultEnergy = getEnergyStored() - euToDraw;
101-
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
102-
if (!simulate) getEnergyContainer().changeEnergy(-euToDraw);
103-
return true;
104-
}
105-
return false;
106-
}
107-
108-
@Override
109-
public long getInfoProviderEUt() {
110-
return boostProduction(super.getInfoProviderEUt());
98+
protected void setupRecipe(@NotNull Recipe recipe) {
99+
super.setupRecipe(recipe);
100+
this.recipeEUt = boostProduction(this.recipeEUt);
111101
}
112102

113103
@Override

src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -384,35 +384,11 @@ protected void performMufflerOperations() {
384384
}
385385
}
386386

387-
@Override
388-
protected long getEnergyInputPerSecond() {
389-
return getEnergyContainer().getInputPerSec();
390-
}
391-
392-
@Override
393-
protected long getEnergyStored() {
394-
return getEnergyContainer().getEnergyStored();
395-
}
396-
397-
@Override
398-
protected long getEnergyCapacity() {
399-
return getEnergyContainer().getEnergyCapacity();
400-
}
401-
402-
@Override
403-
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
404-
long resultEnergy = getEnergyStored() - recipeEUt;
405-
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
406-
if (!simulate) getEnergyContainer().changeEnergy(-recipeEUt);
407-
return true;
408-
} else return false;
409-
}
410-
411387
@Override
412388
public long getMaxVoltage() {
413389
IEnergyContainer energyContainer = getEnergyContainer();
414390
if (!consumesEnergy()) {
415-
// Generators
391+
// Generator Multiblocks
416392
long voltage = energyContainer.getOutputVoltage();
417393
long amperage = energyContainer.getOutputAmperage();
418394
if (energyContainer instanceof EnergyContainerList && amperage == 1) {
@@ -424,7 +400,7 @@ public long getMaxVoltage() {
424400
}
425401
return voltage;
426402
} else {
427-
// Machines
403+
// Machine Multiblocks
428404
if (energyContainer instanceof EnergyContainerList energyList) {
429405
long highestVoltage = energyList.getHighestInputVoltage();
430406
if (energyList.getNumHighestInputContainers() > 1) {

src/main/java/gregtech/api/capability/impl/RecipeLogicEnergy.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,8 @@ public RecipeLogicEnergy(MetaTileEntity tileEntity, RecipeMap<?> recipeMap,
2525
}
2626

2727
@Override
28-
protected long getEnergyInputPerSecond() {
29-
return energyContainer.get().getInputPerSec();
30-
}
31-
32-
@Override
33-
protected long getEnergyStored() {
34-
return energyContainer.get().getEnergyStored();
35-
}
36-
37-
@Override
38-
protected long getEnergyCapacity() {
39-
return energyContainer.get().getEnergyCapacity();
40-
}
41-
42-
@Override
43-
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
44-
long resultEnergy = getEnergyStored() - recipeEUt;
45-
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
46-
if (!simulate) energyContainer.get().changeEnergy(-recipeEUt);
47-
return true;
48-
}
49-
return false;
50-
}
51-
52-
@Override
53-
public long getMaxVoltage() {
54-
return Math.max(energyContainer.get().getInputVoltage(), energyContainer.get().getOutputVoltage());
28+
protected IEnergyContainer getEnergyContainer() {
29+
return energyContainer.get();
5530
}
5631

5732
@Override

src/main/java/gregtech/api/metatileentity/multiblock/FuelMultiblockController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected boolean isDynamoTierTooLow() {
7272
IEnergyContainer energyContainer = recipeMapWorkable.getEnergyContainer();
7373
if (energyContainer != null && energyContainer.getEnergyCapacity() > 0) {
7474
long maxVoltage = Math.max(energyContainer.getInputVoltage(), energyContainer.getOutputVoltage());
75-
return maxVoltage < -recipeMapWorkable.getRecipeEUt();
75+
return maxVoltage < recipeMapWorkable.getRecipeEUt();
7676
}
7777
}
7878
return false;

src/main/java/gregtech/api/metatileentity/multiblock/MultiblockDisplayText.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public Builder addEnergyUsageExactLine(long energyUsage) {
155155
*/
156156
public Builder addEnergyProductionLine(long maxVoltage, long recipeEUt) {
157157
if (!isStructureFormed) return this;
158-
if (maxVoltage != 0 && maxVoltage >= -recipeEUt) {
158+
if (maxVoltage != 0 && maxVoltage >= recipeEUt) {
159159
String energyFormatted = TextFormattingUtil.formatNumbers(maxVoltage);
160160
// wrap in text component to keep it from being formatted
161161
ITextComponent voltageName = new TextComponentString(

0 commit comments

Comments
 (0)