diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 455ae3afd47..2dd5455d460 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -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; @@ -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 @@ -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()); + } /** * @@ -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()); @@ -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++) { diff --git a/src/main/java/gregtech/api/capability/impl/BoilerRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/BoilerRecipeLogic.java index 28b2ee7afd0..7185f2253e2 100644 --- a/src/main/java/gregtech/api/capability/impl/BoilerRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/BoilerRecipeLogic.java @@ -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; @@ -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 diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockFuelRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockFuelRecipeLogic.java index 30c5e5410e3..4c374985014 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockFuelRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockFuelRecipeLogic.java @@ -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 diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index ff95f0fbb0c..728ed138cc9 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -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) { @@ -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) { diff --git a/src/main/java/gregtech/api/capability/impl/PrimitiveRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/PrimitiveRecipeLogic.java index 40e4f13ca43..d0645cca3dd 100644 --- a/src/main/java/gregtech/api/capability/impl/PrimitiveRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/PrimitiveRecipeLogic.java @@ -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; @@ -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 diff --git a/src/main/java/gregtech/api/capability/impl/RecipeLogicEnergy.java b/src/main/java/gregtech/api/capability/impl/RecipeLogicEnergy.java index 8460b2a7aa7..f94b239ecc6 100644 --- a/src/main/java/gregtech/api/capability/impl/RecipeLogicEnergy.java +++ b/src/main/java/gregtech/api/capability/impl/RecipeLogicEnergy.java @@ -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 diff --git a/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java b/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java index 3336b022760..55fc77770ac 100644 --- a/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java +++ b/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java @@ -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; @@ -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)); diff --git a/src/main/java/gregtech/api/capability/impl/SteamMultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/SteamMultiblockRecipeLogic.java index 2c05b255d40..4d6bb83257c 100644 --- a/src/main/java/gregtech/api/capability/impl/SteamMultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/SteamMultiblockRecipeLogic.java @@ -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; @@ -47,6 +48,11 @@ public IFluidTank getSteamFluidTankCombined() { return steamFluidTankCombined; } + @Override + protected IEnergyContainer getEnergyContainer() { + return IEnergyContainer.DEFAULT; + } + @Override protected IItemHandlerModifiable getInputInventory() { RecipeMapSteamMultiblockController controller = (RecipeMapSteamMultiblockController) metaTileEntity; diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/FuelMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/FuelMultiblockController.java index 790a150ec0c..fb3a1993fc2 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/FuelMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/FuelMultiblockController.java @@ -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; diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockDisplayText.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockDisplayText.java index 9127d5ca68c..e7b5d68e6d2 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockDisplayText.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockDisplayText.java @@ -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( diff --git a/src/test/java/gregtech/api/capability/impl/AbstractRecipeLogicTest.java b/src/test/java/gregtech/api/capability/impl/AbstractRecipeLogicTest.java index 5949918f337..ba197c4a2d6 100644 --- a/src/test/java/gregtech/api/capability/impl/AbstractRecipeLogicTest.java +++ b/src/test/java/gregtech/api/capability/impl/AbstractRecipeLogicTest.java @@ -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; @@ -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;