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 Negative EUt in TOP #2666

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 @@ -3,6 +3,7 @@
import gregtech.api.GTValues;
import gregtech.api.capability.GregtechDataCodes;
import gregtech.api.capability.GregtechTileCapabilities;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.IMultiblockController;
import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.capability.IWorkable;
Expand Down Expand Up @@ -101,17 +102,25 @@ public AbstractRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap, bo
/**
* @return the energy container's energy input per second
*/
protected abstract long getEnergyInputPerSecond();
protected long getEnergyInputPerSecond() {
return getEnergyContainer().getInputPerSec();
}

/**
* @return the energy container's current stored energy
*/
protected abstract long getEnergyStored();
protected long getEnergyStored() {
return getEnergyContainer().getEnergyStored();
}

/**
* @return the energy container's maximum energy capacity
*/
protected abstract long getEnergyCapacity();
protected long getEnergyCapacity() {
return getEnergyContainer().getEnergyCapacity();
}

protected abstract IEnergyContainer getEnergyContainer();

/**
* Draw energy from the energy container
Expand All @@ -120,12 +129,22 @@ public AbstractRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap, bo
* @param simulate whether to simulate energy extraction or not
* @return true if the energy can/was drained, otherwise false
*/
protected abstract boolean drawEnergy(long recipeEUt, boolean simulate);
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
// this should be the ONLY time eut is negative!
if (consumesEnergy()) recipeEUt = -recipeEUt;
long resultEnergy = getEnergyStored() + recipeEUt;
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
if (!simulate) getEnergyContainer().changeEnergy(recipeEUt);
return true;
} else return false;
}

/**
* @return the maximum voltage the machine can use/handle for recipe searching
*/
public abstract long getMaxVoltage();
public long getMaxVoltage() {
return Math.max(getEnergyContainer().getInputVoltage(), getEnergyContainer().getOutputVoltage());
}

/**
*
Expand Down Expand Up @@ -941,7 +960,7 @@ public String[] getAvailableOverclockingTiers() {
protected void setupRecipe(@NotNull Recipe recipe) {
this.progressTime = 1;
setMaxProgress(ocResult.duration());
this.recipeEUt = consumesEnergy() ? ocResult.eut() : -ocResult.eut();
this.recipeEUt = ocResult.eut();

int recipeTier = GTUtility.getTierByVoltage(recipe.getEUt());
int machineTier = getOverclockForTier(getMaximumOverclockVoltage());
Expand Down Expand Up @@ -1226,7 +1245,7 @@ public void deserializeNBT(@NotNull NBTTagCompound compound) {
if (progressTime > 0) {
this.isActive = true;
this.maxProgressTime = compound.getInteger("MaxProgress");
this.recipeEUt = compound.getLong("RecipeEUt");
this.recipeEUt = Math.abs(compound.getLong("RecipeEUt"));
NBTTagList itemOutputsList = compound.getTagList("ItemOutputs", Constants.NBT.TAG_COMPOUND);
this.itemOutputs = new ArrayList<>(itemOutputsList.tagCount());
for (int i = 0; i < itemOutputsList.tagCount(); i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gregtech.api.capability.impl;

import gregtech.api.GTValues;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.IMultiblockController;
import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.recipes.Recipe;
Expand Down Expand Up @@ -330,6 +331,12 @@ public long getMaxVoltage() {
return 0;
}

@Override
protected IEnergyContainer getEnergyContainer() {
GTLog.logger.error("Large Boiler called getEnergyContainer(), this should not be possible!");
return IEnergyContainer.DEFAULT;
}

/**
* @param fluidHandler the handler to drain from
* @param amount the amount to drain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,9 @@ protected long boostProduction(long production) {
}

@Override
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
long euToDraw = boostProduction(recipeEUt);
long resultEnergy = getEnergyStored() - euToDraw;
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
if (!simulate) getEnergyContainer().changeEnergy(-euToDraw);
return true;
}
return false;
}

@Override
public long getInfoProviderEUt() {
return boostProduction(super.getInfoProviderEUt());
protected void setupRecipe(@NotNull Recipe recipe) {
super.setupRecipe(recipe);
this.recipeEUt = boostProduction(this.recipeEUt);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,35 +384,11 @@ protected void performMufflerOperations() {
}
}

@Override
protected long getEnergyInputPerSecond() {
return getEnergyContainer().getInputPerSec();
}

@Override
protected long getEnergyStored() {
return getEnergyContainer().getEnergyStored();
}

@Override
protected long getEnergyCapacity() {
return getEnergyContainer().getEnergyCapacity();
}

@Override
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
long resultEnergy = getEnergyStored() - recipeEUt;
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
if (!simulate) getEnergyContainer().changeEnergy(-recipeEUt);
return true;
} else return false;
}

@Override
public long getMaxVoltage() {
IEnergyContainer energyContainer = getEnergyContainer();
if (!consumesEnergy()) {
// Generators
// Generator Multiblocks
long voltage = energyContainer.getOutputVoltage();
long amperage = energyContainer.getOutputAmperage();
if (energyContainer instanceof EnergyContainerList && amperage == 1) {
Expand All @@ -424,7 +400,7 @@ public long getMaxVoltage() {
}
return voltage;
} else {
// Machines
// Machine Multiblocks
if (energyContainer instanceof EnergyContainerList energyList) {
long highestVoltage = energyList.getHighestInputVoltage();
if (energyList.getNumHighestInputContainers() > 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gregtech.api.capability.impl;

import gregtech.api.GTValues;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.metatileentity.multiblock.RecipeMapPrimitiveMultiblockController;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.recipes.logic.OCParams;
Expand Down Expand Up @@ -33,6 +34,11 @@ protected long getEnergyCapacity() {
return Integer.MAX_VALUE;
}

@Override
protected IEnergyContainer getEnergyContainer() {
return IEnergyContainer.DEFAULT;
}

@Override
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
return true; // spoof energy being drawn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,8 @@ public RecipeLogicEnergy(MetaTileEntity tileEntity, RecipeMap<?> recipeMap,
}

@Override
protected long getEnergyInputPerSecond() {
return energyContainer.get().getInputPerSec();
}

@Override
protected long getEnergyStored() {
return energyContainer.get().getEnergyStored();
}

@Override
protected long getEnergyCapacity() {
return energyContainer.get().getEnergyCapacity();
}

@Override
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
long resultEnergy = getEnergyStored() - recipeEUt;
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
if (!simulate) energyContainer.get().changeEnergy(-recipeEUt);
return true;
}
return false;
}

@Override
public long getMaxVoltage() {
return Math.max(energyContainer.get().getInputVoltage(), energyContainer.get().getOutputVoltage());
protected IEnergyContainer getEnergyContainer() {
return energyContainer.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gregtech.api.GTValues;
import gregtech.api.capability.GregtechDataCodes;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.IVentable;
import gregtech.api.damagesources.DamageSources;
import gregtech.api.metatileentity.MetaTileEntity;
Expand Down Expand Up @@ -215,6 +216,11 @@ protected long getEnergyCapacity() {
return (long) Math.floor(steamFluidTank.getCapacity() * conversionRate);
}

@Override
protected IEnergyContainer getEnergyContainer() {
return IEnergyContainer.DEFAULT;
}

@Override
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
int resultDraw = GTUtility.safeCastLongToInt((long) Math.ceil(recipeEUt / conversionRate));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gregtech.api.capability.impl;

import gregtech.api.GTValues;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.metatileentity.multiblock.RecipeMapSteamMultiblockController;
import gregtech.api.recipes.Recipe;
Expand Down Expand Up @@ -47,6 +48,11 @@ public IFluidTank getSteamFluidTankCombined() {
return steamFluidTankCombined;
}

@Override
protected IEnergyContainer getEnergyContainer() {
return IEnergyContainer.DEFAULT;
}

@Override
protected IItemHandlerModifiable getInputInventory() {
RecipeMapSteamMultiblockController controller = (RecipeMapSteamMultiblockController) metaTileEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected boolean isDynamoTierTooLow() {
IEnergyContainer energyContainer = recipeMapWorkable.getEnergyContainer();
if (energyContainer != null && energyContainer.getEnergyCapacity() > 0) {
long maxVoltage = Math.max(energyContainer.getInputVoltage(), energyContainer.getOutputVoltage());
return maxVoltage < -recipeMapWorkable.getRecipeEUt();
return maxVoltage < recipeMapWorkable.getRecipeEUt();
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public Builder addEnergyUsageExactLine(long energyUsage) {
*/
public Builder addEnergyProductionLine(long maxVoltage, long recipeEUt) {
if (!isStructureFormed) return this;
if (maxVoltage != 0 && maxVoltage >= -recipeEUt) {
if (maxVoltage != 0 && maxVoltage >= recipeEUt) {
String energyFormatted = TextFormattingUtil.formatNumbers(maxVoltage);
// wrap in text component to keep it from being formatted
ITextComponent voltageName = new TextComponentString(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gregtech.api.capability.impl;

import gregtech.Bootstrap;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.metatileentity.SimpleMachineMetaTileEntity;
Expand Down Expand Up @@ -162,6 +163,11 @@ protected boolean drawEnergy(long recipeEUt, boolean simulate) {
return true;
}

@Override
protected IEnergyContainer getEnergyContainer() {
return IEnergyContainer.DEFAULT;
}

@Override
public long getMaxVoltage() {
return 32;
Expand Down