aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/tileentities
diff options
context:
space:
mode:
authorMaxim <maxim235@gmx.de>2023-07-19 16:28:02 +0200
committerGitHub <noreply@github.com>2023-07-19 16:28:02 +0200
commit0275ea72b964afbd4281a759dd7f23975a20d100 (patch)
treeee7c8cf2e98bfd69d929cb95ccb06115cb3dec19 /src/main/java/gregtech/common/tileentities
parent6656848378abe5e9bfb66e3f7b06a9f55789e9b6 (diff)
downloadGT5-Unofficial-0275ea72b964afbd4281a759dd7f23975a20d100.tar.gz
GT5-Unofficial-0275ea72b964afbd4281a759dd7f23975a20d100.tar.bz2
GT5-Unofficial-0275ea72b964afbd4281a759dd7f23975a20d100.zip
Migrate fusion reactor to proper generic processing logic (#2145)
* Migrate fusion to generic processing logic * Adjusted OC calculator to allow max number of OCs * Fixed typo * Fix buffer consumption logic * Fix oversight * Addressed reviews
Diffstat (limited to 'src/main/java/gregtech/common/tileentities')
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java143
1 files changed, 71 insertions, 72 deletions
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java
index fd77caa201..9f839ccdda 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java
@@ -12,8 +12,6 @@ import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
import static gregtech.api.util.GT_StructureUtility.filterByMTETier;
-import java.util.ArrayList;
-
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -48,6 +46,7 @@ import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.modularui.IAddUIWidgets;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.logic.ProcessingLogic;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy;
@@ -58,6 +57,8 @@ import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
+import gregtech.api.util.GT_OverclockCalculator;
+import gregtech.api.util.GT_ParallelHelper;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import gregtech.common.power.FusionPower;
@@ -170,13 +171,11 @@ public abstract class GT_MetaTileEntity_FusionComputer
}
@Override
- public void saveNBTData(NBTTagCompound aNBT) {
- super.saveNBTData(aNBT);
- }
-
- @Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
+ if (mEUt > 0) {
+ mEUt = -mEUt;
+ }
}
@Override
@@ -276,65 +275,82 @@ public abstract class GT_MetaTileEntity_FusionComputer
public int overclock(int mStartEnergy) {
if (tierOverclock() == 1) {
- return 1;
+ return 0;
}
if (tierOverclock() == 2) {
- return mStartEnergy < 160000000 ? 2 : 1;
+ return mStartEnergy <= 160000000 ? 1 : 0;
}
if (this.tierOverclock() == 4) {
- return (mStartEnergy < 160000000 ? 4 : (mStartEnergy < 320000000 ? 2 : 1));
+ return (mStartEnergy <= 160000000 ? 2 : (mStartEnergy <= 320000000 ? 1 : 0));
}
- return (mStartEnergy < 160000000) ? 8 : ((mStartEnergy < 320000000) ? 4 : (mStartEnergy < 640000000) ? 2 : 1);
+ return (mStartEnergy <= 160000000) ? 3
+ : ((mStartEnergy <= 320000000) ? 2 : (mStartEnergy <= 640000000) ? 1 : 0);
}
@Override
- @NotNull
- public CheckRecipeResult checkProcessing() {
- ArrayList<FluidStack> tFluidList = getStoredFluids();
- int tFluidList_sS = tFluidList.size();
- for (int i = 0; i < tFluidList_sS - 1; i++) {
- for (int j = i + 1; j < tFluidList_sS; j++) {
- if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) {
- if (tFluidList.get(i).amount >= tFluidList.get(j).amount) {
- tFluidList.remove(j--);
- tFluidList_sS = tFluidList.size();
- } else {
- tFluidList.remove(i--);
- tFluidList_sS = tFluidList.size();
- break;
- }
+ public GT_Recipe.GT_Recipe_Map getRecipeMap() {
+ return GT_Recipe.GT_Recipe_Map.sFusionRecipes;
+ }
+
+ @Override
+ protected ProcessingLogic createProcessingLogic() {
+ return new ProcessingLogic() {
+
+ @NotNull
+ @Override
+ protected GT_ParallelHelper createParallelHelper(@NotNull GT_Recipe recipe) {
+ // When the fusion first loads and is still processing, it does the recipe check without consuming.
+ if (mRunningOnLoad) {
+ return new GT_ParallelHelper().setRecipe(recipe)
+ .setItemInputs(inputItems)
+ .setFluidInputs(inputFluids)
+ .setAvailableEUt(availableVoltage * availableAmperage)
+ .setMachine(machine, protectItems, protectFluids)
+ .setRecipeLocked(recipeLockableMachine, isRecipeLocked)
+ .setMaxParallel(maxParallel)
+ .enableBatchMode(batchSize)
+ .enableOutputCalculation();
}
- }
- }
- if (tFluidList.size() > 1) {
- FluidStack[] tFluids = tFluidList.toArray(new FluidStack[0]);
- GT_Recipe tRecipe;
-
- tRecipe = GT_Recipe.GT_Recipe_Map.sFusionRecipes
- .findRecipe(this.getBaseMetaTileEntity(), this.mLastRecipe, false, GT_Values.V[tier()], tFluids);
- if (tRecipe == null) {
- tRecipe = GT_Recipe.GT_Recipe_Map.sComplexFusionRecipes
- .findRecipe(this.getBaseMetaTileEntity(), this.mLastRecipe, false, GT_Values.V[tier()], tFluids);
+ return super.createParallelHelper(recipe);
}
- if ((tRecipe == null && !mRunningOnLoad) || (maxEUStore() < tRecipe.mSpecialValue)) {
- turnCasingActive(false);
- this.mLastRecipe = null;
- return CheckRecipeResultRegistry.NO_RECIPE;
+ @NotNull
+ @Override
+ protected GT_OverclockCalculator createOverclockCalculator(@NotNull GT_Recipe recipe,
+ @NotNull GT_ParallelHelper helper) {
+ return super.createOverclockCalculator(recipe, helper)
+ .limitOverclockCount(overclock(recipe.mSpecialValue));
}
- if (!canOutputAll(tRecipe)) return CheckRecipeResultRegistry.OUTPUT_FULL;
- if (mRunningOnLoad || tRecipe.isRecipeInputEqual(true, tFluids)) {
- this.mLastRecipe = tRecipe;
- this.mEUt = (this.mLastRecipe.mEUt * overclock(this.mLastRecipe.mSpecialValue));
- this.mMaxProgresstime = this.mLastRecipe.mDuration / overclock(this.mLastRecipe.mSpecialValue);
- this.mEfficiencyIncrease = 10000;
- this.mOutputFluids = this.mLastRecipe.mFluidOutputs;
- turnCasingActive(true);
- mRunningOnLoad = false;
+
+ @NotNull
+ @Override
+ protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) {
+ if (!mRunningOnLoad && recipe.mSpecialValue > maxEUStore()) {
+ return CheckRecipeResultRegistry.insufficientStartupPower(recipe.mSpecialValue);
+ }
return CheckRecipeResultRegistry.SUCCESSFUL;
}
- }
- return CheckRecipeResultRegistry.NO_RECIPE;
+
+ @NotNull
+ @Override
+ public CheckRecipeResult process() {
+ CheckRecipeResult result = super.process();
+ if (mRunningOnLoad) mRunningOnLoad = false;
+ turnCasingActive(result.wasSuccessful());
+ if (result.wasSuccessful()) {
+ mLastRecipe = lastRecipe;
+ } else {
+ mLastRecipe = null;
+ }
+ return result;
+ }
+ }.setOverclock(1, 1);
+ }
+
+ @Override
+ protected void setProcessingLogicPower(ProcessingLogic logic) {
+ logic.setAvailableVoltage(GT_Values.V[tier()]);
+ logic.setAvailableAmperage(1);
}
public abstract int tierOverclock();
@@ -392,7 +408,7 @@ public abstract class GT_MetaTileEntity_FusionComputer
}
if (mMaxProgresstime > 0) {
this.getBaseMetaTileEntity()
- .decreaseStoredEnergyUnits(mEUt, true);
+ .decreaseStoredEnergyUnits(-mEUt, true);
if (mMaxProgresstime > 0 && ++mProgresstime >= mMaxProgresstime) {
if (mOutputItems != null)
for (ItemStack tStack : mOutputItems) if (tStack != null) addOutput(tStack);
@@ -422,11 +438,11 @@ public abstract class GT_MetaTileEntity_FusionComputer
if (aBaseMetaTileEntity.isAllowedToWork()) {
this.mEUStore = aBaseMetaTileEntity.getStoredEU();
if (checkRecipe()) {
- if (this.mEUStore < this.mLastRecipe.mSpecialValue - this.mEUt) {
+ if (this.mEUStore < this.mLastRecipe.mSpecialValue + this.mEUt) {
criticalStopMachine();
}
aBaseMetaTileEntity
- .decreaseStoredEnergyUnits(this.mLastRecipe.mSpecialValue - this.mEUt, true);
+ .decreaseStoredEnergyUnits(this.mLastRecipe.mSpecialValue + this.mEUt, true);
}
}
if (mMaxProgresstime <= 0) mEfficiency = Math.max(0, mEfficiency - 1000);
@@ -444,23 +460,6 @@ public abstract class GT_MetaTileEntity_FusionComputer
}
@Override
- public boolean onRunningTick(ItemStack aStack) {
- if (mEUt < 0) {
- if (!drainEnergyInput(((long) -mEUt * 10000) / Math.max(1000, mEfficiency))) {
- this.mLastRecipe = null;
- criticalStopMachine();
- return false;
- }
- }
- if (this.mEUStore <= 0) {
- this.mLastRecipe = null;
- criticalStopMachine();
- return false;
- }
- return true;
- }
-
- @Override
public boolean drainEnergyInput(long aEU) {
return false;
}