aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common
diff options
context:
space:
mode:
authorBlueWeabo <76872108+BlueWeabo@users.noreply.github.com>2023-01-20 10:23:04 +0200
committerGitHub <noreply@github.com>2023-01-20 09:23:04 +0100
commitc7f1646f4b473359d270d55e4dc54cb1f4e7a64b (patch)
tree146eda529ef20e411b2459cee95ef4909c80bd33 /src/main/java/gregtech/common
parent54ce736cf86ba256596588a6e2833711ff36bbd9 (diff)
downloadGT5-Unofficial-c7f1646f4b473359d270d55e4dc54cb1f4e7a64b.tar.gz
GT5-Unofficial-c7f1646f4b473359d270d55e4dc54cb1f4e7a64b.tar.bz2
GT5-Unofficial-c7f1646f4b473359d270d55e4dc54cb1f4e7a64b.zip
Parallel helper for all addons to use. (#1657)
* work on parallel helper * spotless hell * working? parallel * spotless * documentation * spotless * revert useless addition * fixes * spotless bs * remove commented code * remove outer if and make batchmode void protected
Diffstat (limited to 'src/main/java/gregtech/common')
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PCBFactory.java37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PCBFactory.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PCBFactory.java
index 94f03f7fe5..abb3cbcac6 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PCBFactory.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PCBFactory.java
@@ -49,6 +49,7 @@ import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_OreDictUnificator;
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.blocks.GT_Block_Casings8;
@@ -499,6 +500,7 @@ public class GT_MetaTileEntity_PCBFactory
@Override
public boolean checkRecipe(ItemStack aStack) {
+ mCurrentParallel = 0;
GT_Recipe.GT_Recipe_Map aMap = getRecipeMap();
FluidStack[] tFluidInputs = getStoredFluids().toArray(new FluidStack[0]);
if (mSeparate) {
@@ -520,10 +522,10 @@ public class GT_MetaTileEntity_PCBFactory
}
private boolean processRecipe(
- ItemStack aStack, ItemStack[] tItemInputs, FluidStack[] aFluidInputs, GT_Recipe.GT_Recipe_Map aMap) {
+ ItemStack aStack, ItemStack[] aItemInputs, FluidStack[] aFluidInputs, GT_Recipe.GT_Recipe_Map aMap) {
mOutputItems = null;
mOutputFluids = null;
- if (tItemInputs == null || aFluidInputs == null) {
+ if (aItemInputs == null || aFluidInputs == null) {
return false;
}
@@ -532,7 +534,7 @@ public class GT_MetaTileEntity_PCBFactory
int tier = GT_Utility.getTier(voltage);
GT_Recipe tRecipe =
- aMap.findRecipe(getBaseMetaTileEntity(), null, true, false, V[tier], aFluidInputs, aStack, tItemInputs);
+ aMap.findRecipe(getBaseMetaTileEntity(), null, true, false, V[tier], aFluidInputs, aStack, aItemInputs);
if (tRecipe == null) {
return false;
@@ -544,7 +546,7 @@ public class GT_MetaTileEntity_PCBFactory
ItemStack aNanite = tRecipe.getRepresentativeInput(1);
if (GT_OreDictUnificator.getAssociation(aNanite).mPrefix.equals(OrePrefixes.nanite)) {
- for (ItemStack aItem : tItemInputs) {
+ for (ItemStack aItem : aItemInputs) {
if (aItem.isItemEqual(aNanite)) {
aNanitesOfRecipe += aItem.stackSize;
}
@@ -565,22 +567,21 @@ public class GT_MetaTileEntity_PCBFactory
&& ((recipeBitMap & mBioBitMap) == 0 || ((recipeBitMap & mBioBitMap) == mBioBitMap && mBioUpgrade));
if (recipeAllowed) {
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setMaxParallel(aMaxParallel)
+ .setAvailableEUt(getMaxInputEu())
+ .setEUtModifier(aExtraPower)
+ .enableConsumption()
+ .build();
+ mCurrentParallel = helper.getCurrentParallel();
- int aCurrentParallel = 0;
- for (int i = 0; i < aMaxParallel; i++) {
- if (tRecipe.isRecipeInputEqual(true, aFluidInputs, tItemInputs)) {
- aCurrentParallel++;
- } else {
- break;
- }
- }
-
- mCurrentParallel = aCurrentParallel;
-
- if (aCurrentParallel > 0) {
+ if (mCurrentParallel > 0) {
this.mEfficiency = (getMaxEfficiency(aStack) - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = getMaxEfficiency(aStack);
- this.lEUt = -(long) Math.ceil(tRecipe.mEUt * aCurrentParallel * aExtraPower);
+ this.lEUt = -(long) Math.ceil(tRecipe.mEUt * mCurrentParallel * aExtraPower);
this.mMaxProgresstime = (int) Math.ceil(tRecipe.mDuration * Math.pow(mRoughnessMultiplier, 2));
if (mOCTier1 || mOCTier2) {
@@ -612,7 +613,7 @@ public class GT_MetaTileEntity_PCBFactory
mOutputItems = new ItemStack[tRecipe.mOutputs.length];
ArrayList<ItemStack> tOutputs = new ArrayList<ItemStack>();
int repeats = (int) Math.ceil(getMaxEfficiency(aStack) / 10000);
- for (int k = 0; k < aCurrentParallel; k++) {
+ for (int k = 0; k < mCurrentParallel; k++) {
int remainingEfficiency = getMaxEfficiency(aStack) < 10000 ? 10000 : getMaxEfficiency(aStack);
for (int j = 0; j < repeats; j++) {
int chanced = getBaseMetaTileEntity().getRandomNumber(10000);