aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlueWeabo <76872108+BlueWeabo@users.noreply.github.com>2023-01-23 22:23:01 +0200
committerGitHub <noreply@github.com>2023-01-23 21:23:01 +0100
commit7366deae4a0e4404799ab17dfde0a7ba7d4cb54f (patch)
treeaf5fe5b69b75b0ab554603f75d2e9005b4fd3549
parent4c31639896b6360056af7fa8810a581d17cc97b1 (diff)
downloadGT5-Unofficial-7366deae4a0e4404799ab17dfde0a7ba7d4cb54f.tar.gz
GT5-Unofficial-7366deae4a0e4404799ab17dfde0a7ba7d4cb54f.tar.bz2
GT5-Unofficial-7366deae4a0e4404799ab17dfde0a7ba7d4cb54f.zip
Use GT_ParallelHelper for GT++ (#511)
* everything * remove more useless code * spotless * fix missed multis * actually put efficiency oop * late night coding * missed one * last one * fix tgs * remove useless code, which was used for debugging * spotless
-rw-r--r--dependencies.gradle2
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java552
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java188
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java147
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java153
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java157
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java168
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java147
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java38
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java175
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java180
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java150
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java16
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java110
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java158
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java316
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java110
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java99
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java164
19 files changed, 482 insertions, 2548 deletions
diff --git a/dependencies.gradle b/dependencies.gradle
index 879d17f5f8..08b9fb200c 100644
--- a/dependencies.gradle
+++ b/dependencies.gradle
@@ -1,5 +1,5 @@
dependencies {
- compile('com.github.GTNewHorizons:GT5-Unofficial:5.09.41.218:dev')
+ compile('com.github.GTNewHorizons:GT5-Unofficial:5.09.41.232:dev')
compile("com.github.GTNewHorizons:StructureLib:1.2.0-beta.2:dev")
compile("com.github.GTNewHorizons:ModularUI:1.0.46:dev") {transitive=false}
compile("com.github.GTNewHorizons:NotEnoughItems:2.3.20-GTNH:dev")
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java
index b37d042ff9..5f13bbaf09 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java
@@ -1,8 +1,5 @@
package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
-
-import com.gtnewhorizon.gtnhlib.util.map.ItemStackMap;
import com.gtnewhorizon.structurelib.StructureLibAPI;
import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
@@ -30,8 +27,9 @@ import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.*;
import gregtech.api.objects.GT_ItemStack;
import gregtech.api.render.TextureFactory;
-import gregtech.api.util.GT_ModHandler;
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_Recipe.GT_Recipe_Map;
import gregtech.api.util.GT_Utility;
@@ -67,7 +65,6 @@ import java.util.stream.Collectors;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -77,7 +74,6 @@ import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
-import org.apache.commons.lang3.ArrayUtils;
// Glee8e - 11/12/21 - 2:15pm
// Yeah, now I see what's wrong. Someone inherited from GregtechMeta_MultiBlockBase instead of
@@ -392,243 +388,6 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex
return "";
}
- public int canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes) {
- return canBufferOutputs(aRecipe, aParallelRecipes, true);
- }
-
- public int canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes, boolean aAllow16SlotWithoutCheck) {
- // Null recipe or a recipe with lots of outputs?
- // E.G. Gendustry custom comb with a billion centrifuge outputs?
- // Do it anyway, provided the multi allows it. Default behaviour is aAllow16SlotWithoutCheck = true.
- if (aRecipe == null || aRecipe.mOutputs.length > 16) {
- if (aRecipe == null) {
- return 0;
- } else if (aRecipe.mOutputs.length > 16) {
- if (aAllow16SlotWithoutCheck) {
- return aParallelRecipes;
- } else {
- // Do nothing, we want to check this recipe properly.
- }
- }
- }
- return canBufferOutputs(aRecipe.mOutputs, aRecipe.mFluidOutputs, aParallelRecipes);
- }
-
- public int canBufferOutputs(ItemStack[] aItemOutputs, FluidStack[] aFluidOutputs, int aParallelRecipes) {
- if (mVoidExcess) return aParallelRecipes;
- log("Determining if we have space to buffer outputs. Parallel: " + aParallelRecipes);
-
- // Do we even need to check for item outputs?
- boolean aDoesOutputItems = aItemOutputs.length > 0;
- // Do we even need to check for fluid outputs?
- boolean aDoesOutputFluids = aFluidOutputs.length > 0;
-
- /* ========================================
- * Item Management
- * ========================================
- */
-
- if (aDoesOutputItems) {
- aParallelRecipes = canBufferOutputs(aItemOutputs, aParallelRecipes);
- if (aParallelRecipes == 0) {
- log("Failed to find enough space for all item outputs.");
- return 0;
- }
- }
-
- /* ========================================
- * Fluid Management
- * ========================================
- */
-
- if (aDoesOutputFluids) {
- aParallelRecipes = canBufferOutputs(aFluidOutputs, aParallelRecipes);
- }
-
- return aParallelRecipes;
- }
-
- private int canBufferOutputs(ItemStack[] aItemOutputs, int aParallelRecipes) {
- // the basic idea is to merge stacks as much as we can, and see how many vacant slots do we have left compared
- // with the count of stacks to put.
- // How many slots are free across all the output buses?
- int aInputBusSlotsFree = 0;
-
- // A map to hold the items we will be 'inputting' into the output buses. These itemstacks are actually the
- // recipe outputs.
- Map<ItemStack, Integer> aInputMap = new ItemStackMap<>();
-
- // Iterate over the outputs, calculating require stack spacing they will require.
- for (ItemStack aY : aItemOutputs) {
- if (GT_Utility.isStackInvalid(aY)) {
- continue;
- }
- aInputMap.merge(aY, aY.stackSize * aParallelRecipes, Integer::sum);
- }
-
- if (aInputMap.isEmpty()) {
- // nothing to output, bail early
- return aParallelRecipes;
- }
-
- log("We have items to output.");
-
- for (final GT_MetaTileEntity_Hatch_OutputBus tBus : this.mOutputBusses) {
- if (!isValidMetaTileEntity(tBus)) {
- continue;
- }
- final IInventory tBusInv = tBus.getBaseMetaTileEntity();
- for (int i = 0; i < tBusInv.getSizeInventory(); i++) {
- ItemStack tBusStack = tBus.getStackInSlot(i);
- if (tBusStack == null) {
- aInputBusSlotsFree++;
- } else {
- // get the real stack size
- // we ignore the bus inventory stack limit here as no one set it to anything other than 64
- int tMaxBusStackSize = tBusStack.getMaxStackSize();
- if (tBusStack.stackSize >= tMaxBusStackSize)
- // this bus stack is full. no checking
- continue;
- int tSpaceLeft = tMaxBusStackSize - tBusStack.stackSize;
- Integer tOutputCountBoxed = aInputMap.get(tBusStack);
- if (tOutputCountBoxed == null)
- // we don't have a matching stack to output, ignore this bus stack
- continue;
- int tOutputCount = tOutputCountBoxed;
- if (tOutputCount <= tSpaceLeft) {
- // completely fits in this bus stack, remove this input stack
- aInputMap.remove(tBusStack);
- } else {
- // have left over
- aInputMap.put(tBusStack, tOutputCount - tSpaceLeft);
- }
- }
- }
- }
-
- // We have stacks that did not merge, do we have space for them?
- if (aInputMap.size() > 0) {
- int tTotalLeftStacks = aInputMap.entrySet().stream()
- .mapToInt(GregtechMeta_MultiBlockBase::toStackCount)
- .sum();
- if (tTotalLeftStacks > aInputBusSlotsFree) {
- aParallelRecipes = (int) Math.floor((double) aInputBusSlotsFree / tTotalLeftStacks * aParallelRecipes);
- // We do not have enough free slots in total to accommodate the remaining managed stacks.
- log(" Free: " + aInputBusSlotsFree + ", Required: " + aInputMap.size());
- }
- }
- return aParallelRecipes;
- }
-
- private int canBufferOutputs(FluidStack[] aFluidOutputs, int aParallelRecipes) {
- // the basic idea is to iterate over each output hatch one by one, prioritizing the locked hatches,
- // and try to fill them with each of the fluid we have.
-
- // this algorithm can only determine if it works under current parallel
- // it cannot figure out if a reduced parallel will not overflow
-
- // make a copy of fluid left to output, since we cannot modify the original FluidStack[]
- // use ArrayList as we will usually have less than 12 fluid to output (hopefully)
- List<FluidStack> tFluidsLeft = new ArrayList<>(aFluidOutputs.length);
- for (FluidStack aFluidOutput : aFluidOutputs) {
- if (aFluidOutput == null) continue;
- FluidStack copy = aFluidOutput.copy();
- copy.amount *= aParallelRecipes;
- tFluidsLeft.add(copy);
- }
- if (tFluidsLeft.isEmpty()) return aParallelRecipes;
-
- log("We have Fluids to output.");
-
- // go over restrictive hatches first
- for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) {
- int tSpaceLeft = tHatch.getCapacity() - tHatch.getFluidAmount();
-
- // check if hatch filled
- if (tSpaceLeft <= 0) continue;
-
- String tLockedFluidName = tHatch.getLockedFluidName();
- // not restrictive hatch. leave for next pass
- if (tHatch.mMode == 0) continue;
-
- for (Iterator<FluidStack> iterator = tFluidsLeft.iterator(); iterator.hasNext(); ) {
- FluidStack tFluidOutput = iterator.next();
- if (GT_ModHandler.isSteam(tFluidOutput)) {
- if (!tHatch.outputsSteam()) {
- continue;
- }
- } else {
- if (!tHatch.outputsLiquids()) {
- continue;
- }
- if (tHatch.isFluidLocked()
- && tLockedFluidName != null
- && !tLockedFluidName.equals(tFluidOutput.getFluid().getName())) {
- continue;
- }
- }
- // this fluid is not prevented by restrictions on output hatch
- if (tHatch.getFluidAmount() == 0 || GT_Utility.areFluidsEqual(tHatch.getFluid(), tFluidOutput)) {
- // empty or same fluid - in any case, can accept
- if (tSpaceLeft >= tFluidOutput.amount) {
- // enough to hold all fluid
- tSpaceLeft -= tFluidOutput.amount;
- iterator.remove();
- } else {
- tFluidOutput.amount -= tSpaceLeft;
- break;
- }
- }
- }
- // at this point we have either visited all output or is completed empty, so we can go over to next
- // before that, check if we have handled all fluid, if yes, bail out for early exit.
- if (tFluidsLeft.isEmpty()) break;
- }
-
- // check non-restrictive hatches
- for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) {
- int tSpaceLeft = tHatch.getCapacity() - tHatch.getFluidAmount();
-
- // check if hatch filled
- if (tSpaceLeft <= 0) continue;
-
- // restrictive hatch. done in last pass
- if (tHatch.mMode != 0) continue;
-
- for (Iterator<FluidStack> iterator = tFluidsLeft.iterator(); iterator.hasNext(); ) {
- FluidStack tFluidOutput = iterator.next();
- // these are not restrictive hatches, so no need to check other stuff
- if (tHatch.getFluidAmount() == 0 || GT_Utility.areFluidsEqual(tHatch.getFluid(), tFluidOutput)) {
- // empty or same fluid - in any case, can accept
- if (tSpaceLeft >= tFluidOutput.amount) {
- // enough to hold all fluid
- tSpaceLeft -= tFluidOutput.amount;
- iterator.remove();
- } else {
- tFluidOutput.amount -= tSpaceLeft;
- break;
- }
- }
- }
- // at this point we have either visited all output or is completed empty, so go over to next
- // before that, check if we have handled all fluid, if yes, bail out for early exit.
- if (tFluidsLeft.isEmpty()) break;
- }
-
- // We have Fluid Stacks we did not merge. Do we have space?
- log("fluids to output " + tFluidsLeft.size());
- if (!tFluidsLeft.isEmpty()) {
- // Not enough space to add fluids.
- log("Failed to find enough space for all fluid outputs. Fluids left: " + tFluidsLeft.size());
- return 0;
- }
-
- /*
- * End Fluid Management
- */
- return aParallelRecipes;
- }
-
/**
* A Static {@link Method} object which holds the current status of logging.
*/
@@ -875,7 +634,6 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
long tEnergy = getMaxInputEnergy();
- log("Running checkRecipeGeneric(0)");
GT_Recipe tRecipe = findRecipe(
getBaseMetaTileEntity(),
@@ -886,12 +644,10 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex
aFluidInputs,
aItemInputs);
- log("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
if (tRecipe == null) {
- log("BAD RETURN - 1");
return false;
}
@@ -938,153 +694,48 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex
}
}
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("BAD RETURN - 2");
- return false;
- }
-
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
-
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + aMaxParallelRecipes);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tRecipeEUt: " + tRecipeEUt);
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- log("Broke at " + parallelRecipes + ".");
- break;
- }
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
-
- if (parallelRecipes == 0) {
- log("BAD RETURN - 3");
- return false;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
if (mUseMultiparallelMode) {
- int extraParallelRecipes = 0;
- for (;
- extraParallelRecipes + parallelRecipes < aMaxParallelRecipes * MAX_BATCH_SIZE;
- extraParallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- break;
- }
- }
- batchMultiplier = 1.0f + (float) extraParallelRecipes / aMaxParallelRecipes;
- parallelRecipes += extraParallelRecipes;
+ helper.enableBatchMode(128);
}
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
+ helper.build();
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
-
- this.lEUt = (long) Math.ceil(tTotalEUt);
+ if (helper.getCurrentParallel() == 0) {
+ return false;
+ }
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1L << tTier - 1) * (1L << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- if (hasPerfectOverclock()) {
- this.mMaxProgresstime /= 4;
- } else {
- this.mMaxProgresstime /= 2;
- }
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- if (mUseMultiparallelMode) {
- mMaxProgresstime = (int) Math.ceil(mMaxProgresstime * batchMultiplier);
- }
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(tRecipe.mDuration)
+ .setEUtDiscount(aEUPercent / 100.0f)
+ .setSpeedBoost(100.0f / (100.0f + aSpeedBonusPercent))
+ .setParallel(helper.getCurrentParallel())
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
+
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
updateSlots();
// Play sounds (GT++ addition - GT multiblocks play no sounds)
startProcess();
-
- log("GOOD RETURN - 1");
return true;
}
@@ -1266,131 +917,44 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex
return false;
}
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("BAD RETURN - 2");
- return false;
- }
-
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
-
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + aMaxParallelRecipes);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tRecipeEUt: " + tRecipeEUt);
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- log("Broke at " + parallelRecipes + ".");
- break;
- }
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
-
- if (parallelRecipes == 0) {
- log("BAD RETURN - 3");
- return false;
- }
-
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
-
- this.lEUt = (long) Math.ceil(tTotalEUt);
-
- this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
- this.mEfficiencyIncrease = 10000;
-
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1L << tTier - 1) * (1L << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= 2;
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
+ if (mUseMultiparallelMode) {
+ helper.enableBatchMode(128);
}
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
+ helper.build();
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
+ if (helper.getCurrentParallel() == 0) {
+ Logger.MACHINE_INFO("BAD RETURN - 2");
+ return false;
}
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(tRecipe.mDuration)
+ .setEUtDiscount(aEUPercent / 100.0f)
+ .setSpeedBoost(100.0f / (100.0f + aSpeedBonusPercent))
+ .setParallel(Math.min(aMaxParallelRecipes, helper.getCurrentParallel()))
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(mMaxProgresstime * helper.getDurationMultiplier());
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
updateSlots();
- // Play sounds (GT++ addition - GT multiblocks play no sounds)
- startProcess();
-
- log("GOOD RETURN - 1");
return true;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java
index 9c064c3973..bf9e9f3d94 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java
@@ -5,7 +5,6 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElement
import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
@@ -29,10 +28,8 @@ import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase;
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import java.util.ArrayList;
-import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GMTE_AmazonPackager extends GregtechMeta_MultiBlockBase<GMTE_AmazonPackager>
implements ISurvivalConstructable {
@@ -239,191 +236,6 @@ public class GMTE_AmazonPackager extends GregtechMeta_MultiBlockBase<GMTE_Amazon
return false;
}
- @Override
- public boolean checkRecipeGeneric(
- ItemStack[] aItemInputs,
- FluidStack[] aFluidInputs,
- int aMaxParallelRecipes,
- long aEUPercent,
- int aSpeedBonusPercent,
- int aOutputChanceRoll,
- GT_Recipe aRecipe) {
- // Based on the Processing Array. A bit overkill, but very flexible.
-
- // Reset outputs and progress stats
- this.lEUt = 0;
- this.mMaxProgresstime = 0;
- this.mOutputItems = new ItemStack[] {};
- this.mOutputFluids = new FluidStack[] {};
-
- long tVoltage = getMaxInputVoltage();
- byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
- long tEnergy = getMaxInputEnergy();
- log("Running checkRecipeGeneric(0)");
-
- GT_Recipe tRecipe = findRecipe(
- getBaseMetaTileEntity(),
- mLastRecipe,
- false,
- false,
- gregtech.api.enums.GT_Values.V[tTier],
- aFluidInputs,
- aItemInputs);
-
- log("Running checkRecipeGeneric(1)");
- this.mLastRecipe = tRecipe;
-
- if (tRecipe == null) {
- log("BAD RETURN - 1");
- return false;
- }
-
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("BAD RETURN - 2");
- return false;
- }
-
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
-
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + aMaxParallelRecipes);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tRecipeEUt: " + tRecipeEUt);
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, sNoFluids, aItemInputs)) {
- log("Broke at " + parallelRecipes + ".");
- break;
- }
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
-
- if (parallelRecipes == 0) {
- log("BAD RETURN - 3");
- return false;
- }
-
- if (mUseMultiparallelMode) {
- int extraParallelRecipes = 0;
- for (;
- extraParallelRecipes + parallelRecipes < aMaxParallelRecipes * MAX_BATCH_SIZE;
- extraParallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- break;
- }
- }
- batchMultiplier = 1.0f + (float) extraParallelRecipes / aMaxParallelRecipes;
- parallelRecipes += extraParallelRecipes;
- }
-
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
-
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
- this.lEUt = (long) Math.ceil(tTotalEUt);
-
- this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
- this.mEfficiencyIncrease = 10000;
-
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1L << tTier - 1) * (1L << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- if (this.hasPerfectOverclock()) this.mMaxProgresstime /= 4;
- else this.mMaxProgresstime /= 2;
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- if (mUseMultiparallelMode) {
- mMaxProgresstime = (int) Math.ceil(mMaxProgresstime * batchMultiplier);
- }
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
- updateSlots();
-
- // Play sounds (GT++ addition - GT multiblocks play no sounds)
- startProcess();
-
- log("GOOD RETURN - 1");
- return true;
- }
-
public boolean allowPutStack(final ItemStack aStack, ItemStack schematicStack) {
// If Schematic Static is not 1x1, 2x2, 3x3
if (!ItemList.Schematic_1by1.isStackEqual((Object) schematicStack)
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java
index 9144c3e0eb..0dc2303a0e 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java
@@ -6,7 +6,6 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
import static gregtech.api.util.GT_StructureUtility.ofCoil;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
@@ -20,6 +19,8 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus;
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 gtPlusPlus.api.objects.Logger;
@@ -27,10 +28,8 @@ import gtPlusPlus.core.block.ModBlocks;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase;
import java.util.ArrayList;
-import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GregtechMetaTileEntity_IndustrialAlloySmelter
extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialAlloySmelter>
@@ -229,7 +228,6 @@ public class GregtechMetaTileEntity_IndustrialAlloySmelter
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
long tEnergy = getMaxInputEnergy();
- Logger.WARNING("Running checkRecipeGeneric(0)");
GT_Recipe tRecipe = this.getRecipeMap()
.findRecipe(
@@ -240,7 +238,6 @@ public class GregtechMetaTileEntity_IndustrialAlloySmelter
aFluidInputs,
aItemInputs);
- Logger.WARNING("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
@@ -249,127 +246,53 @@ public class GregtechMetaTileEntity_IndustrialAlloySmelter
return false;
}
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- Logger.WARNING("BAD RETURN - 2");
- return false;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- int tHeatCapacityDivTiers = (int) mHeatingCapacity.getHeat() / 900;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
- // Count recipes to do in parallel, consuming input items and fluids and
- // considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- Logger.WARNING("Broke at " + parallelRecipes + ".");
- break;
- }
- Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
+ if (mUseMultiparallelMode) {
+ helper.enableBatchMode(128);
}
- if (parallelRecipes == 0) {
- Logger.WARNING("BAD RETURN - 3");
+ helper.build();
+
+ if (helper.getCurrentParallel() == 0) {
return false;
}
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = mLevel * 5;
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
- int rInt = 2;
-
- this.lEUt = (long) Math.max(Math.ceil(tTotalEUt), 1);
-
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1L << tTier - 1) * (1L << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= (tHeatCapacityDivTiers >= rInt ? 4 : 2);
- }
- }
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(tRecipe.mDuration)
+ .setEUtDiscount(aEUPercent / 100.0f)
+ .setSpeedBoost(100.0f / (100.0f + aSpeedBonusPercent))
+ .setParallel(Math.min(aMaxParallelRecipes, helper.getCurrentParallel()))
+ .enableHeatOC()
+ .setRecipeHeat(0)
+ // Need to multiple by 2 because heat OC is done only once every 1800 and this one does it once every
+ // 900
+ .setMultiHeat((int) getCoilLevel().getHeat() * 2)
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
+
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
updateSlots();
// Play sounds (GT++ addition - GT multiblocks play no sounds)
startProcess();
-
- Logger.WARNING("GOOD RETURN - 1");
return true;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java
index 6250d34dab..4316cf936d 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java
@@ -5,7 +5,6 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElement
import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
@@ -16,6 +15,8 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.util.GTPP_Recipe;
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 gtPlusPlus.core.block.ModBlocks;
@@ -28,7 +29,6 @@ import java.util.List;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
import team.chisel.carving.Carving;
public class GregtechMetaTileEntity_IndustrialChisel
@@ -234,7 +234,6 @@ public class GregtechMetaTileEntity_IndustrialChisel
GT_Recipe tRecipe = generateChiselRecipe(aItems.get(0), this.getGUIItemStack());
if (tRecipe == null) {
- log("BAD RETURN - 0");
return false;
}
@@ -249,11 +248,7 @@ public class GregtechMetaTileEntity_IndustrialChisel
this.mOutputFluids = new FluidStack[] {};
long tVoltage = getMaxInputVoltage();
- byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
long tEnergy = getMaxInputEnergy();
- log("Running checkRecipeGeneric(0)");
-
- log("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
@@ -261,136 +256,48 @@ public class GregtechMetaTileEntity_IndustrialChisel
int aEUPercent = getEuDiscountForParallelism();
int aSpeedBonusPercent = 200;
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("BAD RETURN - 2");
- return false;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
-
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + aMaxParallelRecipes);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tRecipeEUt: " + tRecipeEUt);
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- log("Broke at " + parallelRecipes + ".");
- break;
- }
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
+ if (mUseMultiparallelMode) {
+ helper.enableBatchMode(128);
}
- if (parallelRecipes == 0) {
- log("BAD RETURN - 3");
+ helper.build();
+
+ if (helper.getCurrentParallel() == 0) {
return false;
}
- // -- Try not to fail after this point - inputs have already been consumed! --
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + aMaxParallelRecipes);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tRecipeEUt: " + tRecipeEUt);
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
-
- this.lEUt = (long) Math.ceil(tTotalEUt);
-
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1L << tTier - 1) * (1L << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= 2;
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(10000) <= tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(tRecipe.mDuration)
+ .setEUtDiscount(aEUPercent / 100.0f)
+ .setSpeedBoost(100.0f / (100.0f + aSpeedBonusPercent))
+ .setParallel(Math.min(aMaxParallelRecipes, helper.getCurrentParallel()))
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
+
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
updateSlots();
// Play sounds (GT++ addition - GT multiblocks play no sounds)
startProcess();
-
- log("GOOD RETURN - 1");
return true;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java
index 320ff62f29..3fd71a56d2 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java
@@ -6,7 +6,6 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
import static gregtech.api.util.GT_StructureUtility.ofCoil;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
@@ -19,22 +18,20 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.util.GTPP_Recipe;
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 gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.block.ModBlocks;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.minecraft.PlayerUtils;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase;
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
-import java.util.ArrayList;
-import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GregtechMetaTileEntity_IndustrialDehydrator
extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialDehydrator>
@@ -76,7 +73,7 @@ public class GregtechMetaTileEntity_IndustrialDehydrator
.addSeparator()
.beginStructureBlock(3, 5, 3, true)
.addController("Bottom Center")
- .addCasingInfo(mCasingName, 10)
+ .addCasingInfo(mCasingName, 5)
.addInputBus("Any Casing", 1)
.addOutputBus("Any Casing", 1)
.addInputHatch("Any Casing", 1)
@@ -132,7 +129,7 @@ public class GregtechMetaTileEntity_IndustrialDehydrator
public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
mCasing = 0;
setCoilLevel(HeatingCoilLevel.None);
- return checkPiece(mName, 1, 4, 0) && mCasing >= 10 && getCoilLevel() != HeatingCoilLevel.None && checkHatch();
+ return checkPiece(mName, 1, 4, 0) && mCasing >= 5 && getCoilLevel() != HeatingCoilLevel.None && checkHatch();
}
@Override
@@ -206,7 +203,6 @@ public class GregtechMetaTileEntity_IndustrialDehydrator
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
long tEnergy = getMaxInputEnergy();
- Logger.WARNING("Running checkRecipeGeneric(0)");
GT_Recipe tRecipe = this.getRecipeMap()
.findRecipe(
@@ -217,140 +213,59 @@ public class GregtechMetaTileEntity_IndustrialDehydrator
aFluidInputs,
aItemInputs);
- Logger.WARNING("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
if (tRecipe == null || this.mHeatingCapacity.getHeat() < tRecipe.mSpecialValue) {
- Logger.WARNING("BAD RETURN - 1");
return false;
}
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- Logger.WARNING("BAD RETURN - 2");
- return false;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- int tHeatCapacityDivTiers = (int) (mHeatingCapacity.getHeat() - tRecipe.mSpecialValue) / 900;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
- // Count recipes to do in parallel, consuming input items and fluids and
- // considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- Logger.WARNING("Broke at " + parallelRecipes + ".");
- break;
- }
- Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
+ if (mUseMultiparallelMode) {
+ helper.enableBatchMode(128);
}
- if (parallelRecipes == 0) {
- Logger.WARNING("BAD RETURN - 3");
+ helper.build();
+
+ if (helper.getCurrentParallel() == 0) {
return false;
}
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
- int rInt = 2;
-
- this.lEUt = (long) Math.ceil(tTotalEUt);
-
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1L << tTier - 1) * (1L << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= (tHeatCapacityDivTiers >= rInt ? 4 : 2);
- }
- }
-
- if (tHeatCapacityDivTiers > 0) {
- this.lEUt = (long) (this.lEUt * (Math.pow(0.95, tHeatCapacityDivTiers)));
- }
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(tRecipe.mDuration)
+ .setEUtDiscount(aEUPercent / 100.0f)
+ .setSpeedBoost(100.0f / (100.0f + aSpeedBonusPercent))
+ .setParallel(Math.min(aMaxParallelRecipes, helper.getCurrentParallel()))
+ .enableHeatOC()
+ .enableHeatDiscount()
+ .setRecipeHeat(tRecipe.mSpecialValue)
+ .setMultiHeat((int) getCoilLevel().getHeat())
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
+
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
updateSlots();
// Play sounds (GT++ addition - GT multiblocks play no sounds)
startProcess();
-
- Logger.WARNING("GOOD RETURN - 1");
return true;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java
index 6955826eab..8e25769c9c 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java
@@ -5,7 +5,6 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElement
import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
@@ -27,14 +26,12 @@ import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.Gregtech
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GregtechMetaTileEntity_IndustrialMultiMachine
extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMultiMachine>
@@ -353,160 +350,51 @@ public class GregtechMetaTileEntity_IndustrialMultiMachine
this.mLastRecipeExtended[tCircuitID] = tRecipe;
if (tRecipe == null) {
- Logger.MACHINE_INFO("BAD RETURN - 1|" + tCircuitID);
-
- if (aItemInputs.length > 0) {
- Logger.MACHINE_INFO("Input Items: " + ItemUtils.getArrayStackNames(aItemInputs));
- }
- if (aFluidInputs.length > 0) {
- Logger.MACHINE_INFO("Input Fluids: " + ItemUtils.getFluidArrayStackNames(aFluidInputs));
- }
- return false;
- }
-
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- Logger.MACHINE_INFO("BAD RETURN - 2|" + tCircuitID);
return false;
}
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
-
- Logger.WARNING("parallelRecipes: " + parallelRecipes);
- Logger.WARNING("aMaxParallelRecipes: " + aMaxParallelRecipes);
- Logger.WARNING("tTotalEUt: " + tTotalEUt);
- Logger.WARNING("tVoltage: " + tVoltage);
- Logger.WARNING("tRecipeEUt: " + tRecipeEUt);
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- Logger.WARNING("Broke at " + parallelRecipes + ".");
- break;
- }
- Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
-
- if (parallelRecipes == 0) {
- Logger.MACHINE_INFO("BAD RETURN - 3|" + tCircuitID);
- return false;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
if (mUseMultiparallelMode) {
- int extraParallelRecipes = 0;
- for (;
- extraParallelRecipes + parallelRecipes < aMaxParallelRecipes * MAX_BATCH_SIZE;
- extraParallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- break;
- }
- }
- batchMultiplier = 1.0f + (float) extraParallelRecipes / aMaxParallelRecipes;
- parallelRecipes += extraParallelRecipes;
+ helper.enableBatchMode(128);
}
- // -- Try not to fail after this point - inputs have already been consumed! --
+ helper.build();
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
-
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
-
- this.lEUt = (long) Math.ceil(tTotalEUt);
+ if (helper.getCurrentParallel() == 0) {
+ return false;
+ }
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1L << tTier - 1) * (1L << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= 2;
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- if (mUseMultiparallelMode) {
- mMaxProgresstime = (int) Math.ceil(mMaxProgresstime * batchMultiplier);
- }
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(tRecipe.mDuration)
+ .setEUtDiscount(aEUPercent / 100.0f)
+ .setSpeedBoost(100.0f / (100.0f + aSpeedBonusPercent))
+ .setParallel(Math.min(aMaxParallelRecipes, helper.getCurrentParallel()))
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
+
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
updateSlots();
// Play sounds (GT++ addition - GT multiblocks play no sounds)
startProcess();
-
- Logger.MACHINE_INFO("GOOD RETURN - 1|" + tCircuitID);
return true;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java
index 9c10ad0357..21a8333b03 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java
@@ -6,7 +6,6 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElement
import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
@@ -45,7 +44,6 @@ import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GregtechMetaTileEntity_IsaMill extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IsaMill>
implements ISurvivalConstructable {
@@ -522,13 +520,10 @@ public class GregtechMetaTileEntity_IsaMill extends GregtechMeta_MultiBlockBase<
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
- long tEnergy = getMaxInputEnergy();
- log("Running checkRecipeGeneric(0)");
// checks if it has a milling ball with enough durability
ItemStack tMillingBallRecipe = findMillingBall(aItemInputs);
if (tMillingBallRecipe == null) {
- log("does not have milling ball");
return false;
}
@@ -540,149 +535,27 @@ public class GregtechMetaTileEntity_IsaMill extends GregtechMeta_MultiBlockBase<
aFluidInputs,
aItemInputs);
- log("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
if (tRecipe == null) {
- log("BAD RETURN - 1");
return false;
}
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("BAD RETURN - 2");
- return false;
- }
-
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
- log("aEUPercent " + aEUPercent);
- log("mEUt " + tRecipe.mEUt);
-
- int parallelRecipes = 0;
-
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + 1);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tEnergy: " + tEnergy);
- log("tRecipeEUt: " + tRecipeEUt);
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
- for (; parallelRecipes < 1 && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- log("Broke at " + parallelRecipes + ".");
- break;
- }
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
-
- if (parallelRecipes == 0) {
- log("BAD RETURN - 3");
- return false;
- }
-
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
-
- this.lEUt = (long) Math.ceil(tTotalEUt);
-
- this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
- this.mEfficiencyIncrease = 10000;
-
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1L << tTier - 1) * (1L << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= 4;
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
+ boolean tSuccess = super.checkRecipeGeneric(
+ aItemInputs,
+ aFluidInputs,
+ aMaxParallelRecipes,
+ aEUPercent,
+ aSpeedBonusPercent,
+ aOutputChanceRoll,
+ tRecipe);
// Damage Milling ball once all is said and done.
- if (tMillingBallRecipe != null) {
- log("damaging milling ball");
+ if (tSuccess) {
damageMillingBall(tMillingBallRecipe);
}
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
- updateSlots();
-
- // Play sounds (GT++ addition - GT multiblocks play no sounds)
- startProcess();
-
- log("GOOD RETURN - 1");
- return true;
+ return tSuccess;
}
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java
index 24588d6d2e..66a72aec86 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java
@@ -348,44 +348,6 @@ public class GregtechMetaTileEntity_Adv_DistillationTower
}
@Override
- public int canBufferOutputs(ItemStack[] aItemOutputs, FluidStack[] aFluidOutputs, int aParallelRecipes) {
- // do void excess checks
- if (mVoidExcess) return aParallelRecipes;
- // sb mode. no need to check layered outputs
- if (mMode == Mode.Distillery) return super.canBufferOutputs(aItemOutputs, aFluidOutputs, aParallelRecipes);
- // not enough output hatches
- if (mOutputHatchesByLayer.size() < aFluidOutputs.length) {
- log("Not enough output layers for distillation towers");
- return 0;
- }
- // first check if item output can be held. We delegate this to super class since we do not have special item
- // hatches
- aParallelRecipes = super.canBufferOutputs(aItemOutputs, new FluidStack[0], aParallelRecipes);
- if (aParallelRecipes == 0) return 0;
- for (int i = 0; i < aFluidOutputs.length; i++) {
- FluidStack tFluidOutput = aFluidOutputs[i];
- FluidStack tCopied = new FluidStack(tFluidOutput, 0);
- int toFill = tFluidOutput.amount * aParallelRecipes;
- for (GT_MetaTileEntity_Hatch_Output hatch : mOutputHatchesByLayer.get(i)) {
- boolean fluidMatch = hatch.isFluidLocked()
- ? tFluidOutput.getFluid().getName().equals(hatch.getLockedFluidName())
- : hatch.getFluid() == null || hatch.getFluid().isFluidEqual(tFluidOutput);
-
- if (fluidMatch) {
- tCopied.amount = toFill;
- toFill -= hatch.fill(tCopied, false);
- if (toFill == 0)
- // no more current fluid to fill. break out to go to next fluid
- break;
- }
- }
- // use ceil div
- aParallelRecipes -= (toFill + tFluidOutput.amount - 1) / tFluidOutput.amount;
- }
- return aParallelRecipes;
- }
-
- @Override
public String getMachineType() {
return "Distillery, Distillation Tower";
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java
index 5e2975ee37..5d17b2a922 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java
@@ -7,7 +7,6 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
import static gregtech.api.util.GT_StructureUtility.ofCoil;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
@@ -20,22 +19,21 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus;
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 gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.block.ModBlocks;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GT_MetaTileEntity_Hatch_CustomFluidBase;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase;
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import java.util.ArrayList;
-import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GregtechMetaTileEntity_Adv_EBF extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_EBF>
implements ISurvivalConstructable {
@@ -280,7 +278,6 @@ public class GregtechMetaTileEntity_Adv_EBF extends GregtechMeta_MultiBlockBase<
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
long tEnergy = getMaxInputEnergy();
- Logger.WARNING("Running checkRecipeGeneric(0)");
GT_Recipe tRecipe = this.getRecipeMap()
.findRecipe(
@@ -290,163 +287,59 @@ public class GregtechMetaTileEntity_Adv_EBF extends GregtechMeta_MultiBlockBase<
gregtech.api.enums.GT_Values.V[tTier],
aFluidInputs,
aItemInputs);
-
- Logger.WARNING("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
if (tRecipe == null || this.mHeatingCapacity.getHeat() < tRecipe.mSpecialValue) {
- Logger.WARNING("BAD RETURN - 1");
- return false;
- }
-
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- Logger.WARNING("BAD RETURN - 2");
return false;
}
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- int tHeatCapacityDivTiers = (int) (mHeatingCapacity.getHeat() - tRecipe.mSpecialValue) / 900;
- if (tHeatCapacityDivTiers > 0) tRecipeEUt = (int) (tRecipeEUt * (Math.pow(0.95, tHeatCapacityDivTiers)));
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
- // Count recipes to do in parallel, consuming input items and fluids and
- // considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- Logger.WARNING("Broke at " + parallelRecipes + ".");
- break;
- }
- Logger.WARNING("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
-
- if (parallelRecipes == 0) {
- Logger.WARNING("BAD RETURN - 3");
- return false;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
if (mUseMultiparallelMode) {
- int extraParallelRecipes = 0;
- for (;
- extraParallelRecipes + parallelRecipes < aMaxParallelRecipes * MAX_BATCH_SIZE;
- extraParallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- break;
- }
- }
- batchMultiplier = 1.0f + (float) extraParallelRecipes / aMaxParallelRecipes;
- parallelRecipes += extraParallelRecipes;
+ helper.enableBatchMode(128);
}
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
- int tHalfHeatCapacityDivTiers = tHeatCapacityDivTiers / 2;
+ helper.build();
- this.lEUt = (long) Math.ceil(tTotalEUt);
+ if (helper.getCurrentParallel() == 0) {
+ return false;
+ }
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1 << tTier - 1) * (1 << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- if (tHalfHeatCapacityDivTiers > 0) {
- this.mMaxProgresstime = mMaxProgresstime / 4;
- tHalfHeatCapacityDivTiers--;
- } else {
- this.mMaxProgresstime = mMaxProgresstime / 2;
- }
- if (this.mMaxProgresstime <= 1) {
- break;
- }
- }
- }
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- if (mUseMultiparallelMode) {
- mMaxProgresstime = (int) Math.ceil(mMaxProgresstime * batchMultiplier);
- }
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(tRecipe.mDuration)
+ .setEUtDiscount(aEUPercent / 100.0f)
+ .setSpeedBoost(100.0f / (100.0f + aSpeedBonusPercent))
+ .setParallel(Math.min(aMaxParallelRecipes, helper.getCurrentParallel()))
+ .enableHeatOC()
+ .enableHeatDiscount()
+ .setRecipeHeat(tRecipe.mSpecialValue)
+ .setMultiHeat((int) getCoilLevel().getHeat())
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
+
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
updateSlots();
// Play sounds (GT++ addition - GT multiblocks play no sounds)
startProcess();
-
- Logger.WARNING("GOOD RETURN - 1");
return true;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java
index 61a88b9a38..cab78ffef4 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java
@@ -6,7 +6,6 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass;
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
@@ -34,11 +33,9 @@ import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GregtechMTE_ElementalDuplicator extends GregtechMeta_MultiBlockBase<GregtechMTE_ElementalDuplicator> {
@@ -345,18 +342,9 @@ public class GregtechMTE_ElementalDuplicator extends GregtechMeta_MultiBlockBase
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
- long tEnergy = getMaxInputEnergy();
- log("Running checkRecipeGeneric(0)");
-
GT_Recipe tRecipe = null;
try {
- log("Checking " + aItemInputs.length + " Data Orbs");
-
- for (int i = 0; i < aItemInputs.length; i++) {
- ItemStack aItem = aItemInputs[i];
- log("Found: " + aItem.getDisplayName());
- }
ItemStack aDataOrbStack = null;
recipe:
for (GT_Recipe nRecipe : this.getRecipeMap().mRecipeList) {
@@ -367,10 +355,6 @@ public class GregtechMTE_ElementalDuplicator extends GregtechMeta_MultiBlockBase
for (ItemStack aItem : aItemInputs) {
if (nRecipe.mSpecialItems != null) {
if (GT_Utility.areStacksEqual(aTempStack, aItem, false)) {
- Materials tMaterial = Element.get(Behaviour_DataOrb.getDataName(aTempStack))
- .mLinkedMaterials
- .get(0);
- log("Found: " + aTempStack.getDisplayName() + " for " + tMaterial.name());
aDataOrbStack = aTempStack;
break recipe;
}
@@ -388,174 +372,26 @@ public class GregtechMTE_ElementalDuplicator extends GregtechMeta_MultiBlockBase
aFluidInputs,
aDataOrbStack,
aItemInputs);
- if (tRecipe != null) {
- Materials tMaterial = Element.get(Behaviour_DataOrb.getDataName(aDataOrbStack))
- .mLinkedMaterials
- .get(0);
- log("Found recipe for " + tMaterial.name());
- } else {
- log("No Recipe Found");
- }
- } else {
- log("Null DO");
}
-
} catch (Throwable t) {
t.printStackTrace();
}
- log("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
if (tRecipe == null) {
- log("BAD RETURN - 1");
- return false;
- }
-
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("BAD RETURN - 2");
- return false;
- }
-
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
-
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + aMaxParallelRecipes);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tRecipeEUt: " + tRecipeEUt);
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- log("Broke at " + parallelRecipes + ".");
- break;
- }
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
-
- if (parallelRecipes == 0) {
- log("BAD RETURN - 3");
return false;
}
- if (mUseMultiparallelMode) {
- int extraParallelRecipes = 0;
- for (;
- extraParallelRecipes + parallelRecipes < aMaxParallelRecipes * MAX_BATCH_SIZE;
- extraParallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- break;
- }
- }
- batchMultiplier = 1.0f + (float) extraParallelRecipes / aMaxParallelRecipes;
- parallelRecipes += extraParallelRecipes;
- }
-
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
-
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
- this.lEUt = (long) Math.ceil(tTotalEUt);
-
- this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
- this.mEfficiencyIncrease = 10000;
-
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1 << tTier - 1) * (1 << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= 4;
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- if (mUseMultiparallelMode) {
- mMaxProgresstime = (int) Math.ceil(mMaxProgresstime * batchMultiplier);
- }
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
- updateSlots();
-
- // Play sounds (GT++ addition - GT multiblocks play no sounds)
- startProcess();
-
- log("GOOD RETURN - 1");
- return true;
+ return super.checkRecipeGeneric(
+ aItemInputs,
+ aFluidInputs,
+ aMaxParallelRecipes,
+ aEUPercent,
+ aSpeedBonusPercent,
+ aOutputChanceRoll,
+ tRecipe);
}
@Override
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java
index 1c18f923be..b27f3d6b25 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java
@@ -4,7 +4,6 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass;
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
@@ -25,14 +24,11 @@ import gtPlusPlus.core.material.Material;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase;
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import gtPlusPlus.xmod.gregtech.common.helpers.FlotationRecipeHandler;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Objects;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GregtechMTE_FrothFlotationCell extends GregtechMeta_MultiBlockBase<GregtechMTE_FrothFlotationCell>
implements ISurvivalConstructable {
@@ -220,8 +216,6 @@ public class GregtechMTE_FrothFlotationCell extends GregtechMeta_MultiBlockBase<
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
- long tEnergy = getMaxInputEnergy();
- log("Running checkRecipeGeneric(0)");
GT_Recipe tRecipe = findRecipe(
getBaseMetaTileEntity(),
@@ -231,12 +225,10 @@ public class GregtechMTE_FrothFlotationCell extends GregtechMeta_MultiBlockBase<
aFluidInputs,
aItemInputs);
- log("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
if (tRecipe == null) {
- log("BAD RETURN - 1");
return false;
}
@@ -256,11 +248,6 @@ public class GregtechMTE_FrothFlotationCell extends GregtechMeta_MultiBlockBase<
}
if (foundMaterialName == null) {
- log("Did not find material from Milled Ore.");
- ItemStack milledStack = FlotationRecipeHandler.findMilledStack(tRecipe);
- if (milledStack != null) {
- log("Found stack: " + milledStack.getDisplayName());
- }
return false;
}
@@ -271,138 +258,17 @@ public class GregtechMTE_FrothFlotationCell extends GregtechMeta_MultiBlockBase<
// Check material match
if (!Objects.equals(lockedMaterialName, foundMaterialName)) {
- log("Did not find the correct milled type.");
- log("Found: " + foundMaterialName);
- log("Expected: " + lockedMaterialName);
return false;
}
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("BAD RETURN - 2");
- return false;
- }
-
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
-
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + aMaxParallelRecipes);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tRecipeEUt: " + tRecipeEUt);
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- log("Broke at " + parallelRecipes + ".");
- break;
- }
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
-
- if (parallelRecipes == 0) {
- log("BAD RETURN - 3");
- return false;
- }
-
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
-
- this.lEUt = (long) Math.ceil(tTotalEUt);
-
- this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
- this.mEfficiencyIncrease = 10000;
-
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1 << tTier - 1) * (1 << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= 4;
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
- updateSlots();
-
- // Play sounds (GT++ addition - GT multiblocks play no sounds)
- startProcess();
-
- log("GOOD RETURN - 1");
- return true;
+ return super.checkRecipeGeneric(
+ aItemInputs,
+ aFluidInputs,
+ aMaxParallelRecipes,
+ aEUPercent,
+ aSpeedBonusPercent,
+ aOutputChanceRoll,
+ tRecipe);
}
/*
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java
index 0eef97a5a4..bf3fbe0477 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java
@@ -23,6 +23,8 @@ import gregtech.api.items.GT_MetaGenerated_Tool;
import gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
+import gregtech.api.util.GT_ParallelHelper;
+import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.block.ModBlocks;
@@ -182,7 +184,19 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase<
toOutput = new ItemStack[] {ItemUtils.getSimpleStack(mWood, amplifiedOutputAmount)};
}
- if (canBufferOutputs(toOutput, new FluidStack[] {}, 1) == 0) {
+ GT_Recipe tRecipe = new GT_Recipe(null, toOutput, null, null, null, null, 0, 0, 0);
+
+ GT_ParallelHelper helper = new GT_ParallelHelper().setRecipe(tRecipe).setAvailableEUt(tVoltage);
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
+ }
+
+ if (mUseMultiparallelMode) {
+ helper.enableBatchMode(128);
+ }
+
+ helper.build();
+ if (helper.getCurrentParallel() == 0) {
return false;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java
index 2919ecd5fe..7422426669 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java
@@ -495,7 +495,6 @@ public class GregtechMetaTileEntity_IndustrialFishingPond
// If no core, return false;
if (aControlCoreTier == 0 && CORE.ConfigSwitches.requireControlCores) {
- log("Invalid/No Control Core");
return false;
}
@@ -508,7 +507,6 @@ public class GregtechMetaTileEntity_IndustrialFishingPond
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
long tEnergy = getMaxInputEnergy();
- log("Running checkRecipeGeneric(0)");
// Check to see if Voltage Tier > Control Core Tier
if (tTier > aControlCoreTier && CORE.ConfigSwitches.requireControlCores) {
@@ -528,98 +526,44 @@ public class GregtechMetaTileEntity_IndustrialFishingPond
mFishOutput = removeNulls(mFishOutput);
GT_Recipe g = new GTPP_Recipe(
true, new ItemStack[] {}, mFishOutput, null, new int[] {}, aFluidInputs, mOutputFluids, 200, 16, 0);
- aMaxParallelRecipes = this.canBufferOutputs(g, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("No Space");
- return false;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(g)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
- log("Mode: " + this.mMode + " | Is loot valid? " + (mFishOutput != null));
-
- int jslot = 0;
- for (ItemStack x : mFishOutput) {
- if (x != null) {
- log("Slot " + jslot + " in mFishOutput contains " + x.stackSize + "x " + x.getDisplayName() + ".");
- } else {
- log("Slot " + jslot + " in mFishOutput was null.");
- }
- jslot++;
+ if (mUseMultiparallelMode) {
+ helper.enableBatchMode(128);
}
- // EU discount
- float tRecipeEUt = (8 * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
-
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + aMaxParallelRecipes);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tRecipeEUt: " + tRecipeEUt);
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
+ helper.build();
- if (parallelRecipes == 0) {
- log("BAD RETURN - 3");
+ if (helper.getCurrentParallel() == 0) {
return false;
}
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
- this.mMaxProgresstime = (int) (20 * tTimeFactor * 4);
-
- this.lEUt = (long) Math.ceil(tTotalEUt);
-
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
- // Only Overclock as high as the control circuit.
- byte tTierOld = tTier;
- tTier = CORE.ConfigSwitches.requireControlCores ? (byte) aControlCoreTier : tTierOld;
-
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1L << tTier - 1) * (1L << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= 2;
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- log("Recipe Step. [3]");
- // Collect output item types
- ItemStack[] tOutputItems = mFishOutput;
-
- int rslot = 0;
- tOutputItems = removeNulls(mFishOutput);
-
- for (ItemStack x : tOutputItems) {
- if (x != null) {
- log("rSlot " + rslot + " in mFishOutput contains " + x.stackSize + "x " + x.getDisplayName() + ".");
- } else {
- log("rSlot " + rslot + " in mFishOutput was null.");
- }
- rslot++;
- }
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(g.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(g.mDuration)
+ .setEUtDiscount(aEUPercent / 100.0f)
+ .setSpeedBoost(100.0f / (100.0f + aSpeedBonusPercent))
+ .setParallel(Math.min(aMaxParallelRecipes, helper.getCurrentParallel()))
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
+
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
updateSlots();
// Play sounds (GT++ addition - GT multiblocks play no sounds)
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java
index 44ba0c347c..99c08bd17b 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java
@@ -7,7 +7,6 @@ import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.enums.GT_Values.E;
import static gregtech.api.enums.GT_Values.RES_PATH_GUI;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
@@ -31,12 +30,10 @@ import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.Gregtech
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import java.util.ArrayList;
import java.util.HashSet;
-import java.util.List;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GregtechMetaTileEntity_IndustrialRockBreaker
extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialRockBreaker>
@@ -267,12 +264,10 @@ public class GregtechMetaTileEntity_IndustrialRockBreaker
}
if (!aHasWater || !aHasLava) {
- log("BAD RETURN - 0-1");
return false;
}
ItemStack aGuiCircuit = this.getGUIItemStack();
if (aGuiCircuit == null || !ItemUtils.isControlCircuit(aGuiCircuit)) {
- log("BAD RETURN - 0-2");
return false;
}
@@ -298,7 +293,6 @@ public class GregtechMetaTileEntity_IndustrialRockBreaker
}
if (tRecipe == null) {
- log("BAD RETURN - 0-3");
return false;
}
@@ -313,11 +307,7 @@ public class GregtechMetaTileEntity_IndustrialRockBreaker
this.mOutputFluids = new FluidStack[] {};
long tVoltage = getMaxInputVoltage();
- byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
long tEnergy = getMaxInputEnergy();
- log("Running checkRecipeGeneric(0)");
-
- log("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
@@ -325,140 +315,48 @@ public class GregtechMetaTileEntity_IndustrialRockBreaker
int aEUPercent = getEuDiscountForParallelism();
int aSpeedBonusPercent = 200;
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("BAD RETURN - 2");
- return false;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
-
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + aMaxParallelRecipes);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tRecipeEUt: " + tRecipeEUt);
-
- if (aItems.size() > 0 && aCircuit == 3) {
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage
- // limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!this.depleteInput(tRecipe.mInputs[1])) {
- break;
- }
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
- } else if (aCircuit >= 1 && aCircuit <= 2) {
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
+ if (mUseMultiparallelMode) {
+ helper.enableBatchMode(128);
}
- log("Broke at " + parallelRecipes + ".");
- if (parallelRecipes == 0) {
- log("BAD RETURN - 3");
+ helper.build();
+
+ if (helper.getCurrentParallel() == 0) {
return false;
}
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
-
- this.lEUt = (long) Math.ceil(tTotalEUt);
-
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1L << tTier - 1) * (1L << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= 2;
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(10000) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(tRecipe.mDuration)
+ .setEUtDiscount(aEUPercent / 100.0f)
+ .setSpeedBoost(100.0f / (100.0f + aSpeedBonusPercent))
+ .setParallel(Math.min(aMaxParallelRecipes, helper.getCurrentParallel()))
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
+
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
updateSlots();
// Play sounds (GT++ addition - GT multiblocks play no sounds)
startProcess();
-
- log("GOOD RETURN - 1");
return true;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java
index e93ee44d91..49d867cb76 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java
@@ -5,7 +5,6 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElement
import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
@@ -30,12 +29,10 @@ import gtPlusPlus.core.util.minecraft.PlayerUtils;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase;
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import java.util.ArrayList;
-import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GregtechMetaTileEntity_MassFabricator
extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_MassFabricator> implements ISurvivalConstructable {
@@ -307,123 +304,45 @@ public class GregtechMetaTileEntity_MassFabricator
MaterialUtils.getVoltageForTier(1),
0);
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
-
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("BAD RETURN - 2");
- return false;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
- int parallelRecipes = 0;
- // Count recipes to do in parallel, consuming input items and fluids and
- // considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- break;
- }
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ". ");
- tTotalEUt += tRecipeEUt;
+ if (mUseMultiparallelMode) {
+ helper.enableBatchMode(128);
}
- log("Broke at " + parallelRecipes + ".");
- if (parallelRecipes > 0) {
-
- float batchMultiplier = 1.0f;
- if (mUseMultiparallelMode) {
- int extraParallelRecipes = 0;
- for (; extraParallelRecipes + parallelRecipes < aMaxParallelRecipes * 128; extraParallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- break;
- }
- }
- batchMultiplier = 1.0f + (float) extraParallelRecipes / aMaxParallelRecipes;
- parallelRecipes += extraParallelRecipes;
- }
- // -- Try not to fail after this point - inputs have already been
- // consumed! --
+ helper.build();
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe
- // duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
- if (mUseMultiparallelMode) {
- tTimeFactor *= batchMultiplier;
- }
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
- this.lEUt = (long) Math.ceil(tTotalEUt);
- this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
- this.mEfficiencyIncrease = 10000;
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1 << tTier - 1) * (1 << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= 4;
- }
- }
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
- tOutputItems = removeNulls(tOutputItems);
- for (ItemStack aOutputStack : tOutputItems) {
- if (aOutputStack != null) {
- mScrapProduced += aOutputStack.stackSize;
- }
- }
- // Sanitize item stack size, splitting any stacks greater than max
- // stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
- // Commit outputs
- this.mOutputItems = tOutputItems;
- updateSlots();
- // Play sounds (GT++ addition - GT multiblocks play no sounds)
- startProcess();
- return true;
+ if (helper.getCurrentParallel() == 0) {
+ return false;
}
- return false;
+
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(tRecipe.mDuration)
+ .setEUtDiscount(aEUPercent / 100.0f)
+ .setSpeedBoost(100.0f / (100.0f + aSpeedBonusPercent))
+ .setParallel(helper.getCurrentParallel())
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
+
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
+ updateSlots();
+ // Play sounds (GT++ addition - GT multiblocks play no sounds)
+ startProcess();
+ return true;
}
public boolean checkRecipeUU(
@@ -445,7 +364,6 @@ public class GregtechMetaTileEntity_MassFabricator
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
long tEnergy = getMaxInputEnergy();
- log("Running checkRecipeGeneric(0)");
GT_Recipe tRecipe = findRecipe(
getBaseMetaTileEntity(),
@@ -455,152 +373,76 @@ public class GregtechMetaTileEntity_MassFabricator
aFluidInputs,
aItemInputs);
- log("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
if (tRecipe == null) {
- log("BAD RETURN - 1");
return false;
}
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("BAD RETURN - 2");
- return false;
- }
-
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
-
- int parallelRecipes = 0;
-
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + aMaxParallelRecipes);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tRecipeEUt: " + tRecipeEUt);
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
- for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, false, aFluidInputs, aItemInputs)) {
- break;
- }
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
- }
-
- log("Broke at " + parallelRecipes + ".");
- if (parallelRecipes == 0) {
- log("BAD RETURN - 3");
- return false;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
if (mUseMultiparallelMode) {
- int extraParallelRecipes = 0;
- for (;
- extraParallelRecipes + parallelRecipes < aMaxParallelRecipes * MAX_BATCH_SIZE;
- extraParallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- break;
- }
- }
- batchMultiplier = 1.0f + (float) extraParallelRecipes / aMaxParallelRecipes;
- parallelRecipes += extraParallelRecipes;
+ helper.enableBatchMode(128);
}
- // -- Try not to fail after this point - inputs have already been consumed! --
+ helper.build();
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
-
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
-
- this.lEUt = (long) Math.ceil(tTotalEUt);
+ if (helper.getCurrentParallel() == 0) {
+ return false;
+ }
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1L << tTier - 1) * (1L << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= 4;
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- if (mUseMultiparallelMode) {
- mMaxProgresstime = (int) Math.ceil(mMaxProgresstime * batchMultiplier);
- }
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(tRecipe.mDuration)
+ .setEUtDiscount(aEUPercent / 100.0f)
+ .setSpeedBoost(100.0f / (100.0f + aSpeedBonusPercent))
+ .setParallel(Math.min(aMaxParallelRecipes, helper.getCurrentParallel()))
+ .enablePerfectOC()
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
+
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
int aMatterProduced = 0;
int aAmplifierProduced = 0;
int aScrapUsed = 0;
int aAmplifierUsed = 0;
- for (int i = 0; i < parallelRecipes; i++) {
+ for (int i = 0; i < helper.getCurrentParallel(); i++) {
// Logger.INFO("Trying to bump stats "+i);
for (ItemStack aInput : tRecipe.mInputs) {
if (aInput != null && GT_Utility.areStacksEqual(aInput, mScrap[0], true)) {
aScrapUsed += aInput.stackSize;
- // Logger.INFO("Found Scrap to use.");
}
}
for (FluidStack aInput : tRecipe.mFluidInputs) {
if (aInput != null && GT_Utility.areFluidsEqual(aInput, mUU[0], true)) {
aAmplifierUsed += aInput.amount;
- // Logger.INFO("Found UU-A to use.");
}
}
for (FluidStack aOutput : tRecipe.mFluidOutputs) {
if (aOutput != null && GT_Utility.areFluidsEqual(aOutput, mUU[0], true)) {
aAmplifierProduced += aOutput.amount;
- // Logger.INFO("Found UU-A as Output.");
}
if (aOutput != null && GT_Utility.areFluidsEqual(aOutput, mUU[1], true)) {
aMatterProduced += aOutput.amount;
- // Logger.INFO("Found UU-M as Output.");
}
}
}
@@ -609,41 +451,9 @@ public class GregtechMetaTileEntity_MassFabricator
this.mAmplifierProduced += aAmplifierProduced;
this.mScrapUsed += aScrapUsed;
this.mAmplifierUsed += aAmplifierUsed;
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
-
updateSlots();
-
// Play sounds (GT++ addition - GT multiblocks play no sounds)
startProcess();
-
- log("GOOD RETURN - 1");
return true;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java
index 2f06dafaad..80edf59fe3 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java
@@ -55,7 +55,7 @@ public class GregtechMetaTileEntity_QuantumForceTransformer
protected int mCraftingTier = 0;
protected int mFocusingTier = 0;
private boolean mSeparateInputBusses = false;
- private boolean mFluidMode = false, doFermium = false, doNeptunium = false;
+ private boolean mFluidMode = false, doFermium = false, doNeptunium = false, mBatchMode;
private static final Fluid mNeptunium = ELEMENT.getInstance().NEPTUNIUM.getPlasma();
private static final Fluid mFermium = ELEMENT.getInstance().FERMIUM.getPlasma();
private static final String MAIN_PIECE = "main";
@@ -715,19 +715,9 @@ public class GregtechMetaTileEntity_QuantumForceTransformer
private boolean processRecipe(
ItemStack[] aItemInputs, FluidStack[] aFluidInputs, GT_Recipe.GT_Recipe_Map aRecipeMap, ItemStack aStack) {
- int hatches = getExoticAndNormalEnergyHatchList().size();
- long tVoltage = getMaxInputVoltage() / hatches;
- long tAmps = getMaxInputAmps();
- long tTotalEUt = tVoltage * tAmps;
- byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
- GT_Recipe tRecipe = aRecipeMap
- .findRecipe(
- getBaseMetaTileEntity(),
- false,
- gregtech.api.enums.GT_Values.V[tTier],
- aFluidInputs,
- aItemInputs)
- .copy();
+ byte tTier = (byte) Math.max(1, GT_Utility.getTier(getAverageInputVoltage()));
+ GT_Recipe tRecipe = aRecipeMap.findRecipe(
+ getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs);
if (tRecipe != null && tRecipe.mSpecialValue <= getCraftingTier()) {
ItemStack aRecipeCatalyst = null;
@@ -754,7 +744,7 @@ public class GregtechMetaTileEntity_QuantumForceTransformer
}
}
- if (mFermiumHatch != null) {
+ if (mFermiumHatch != null && tRecipe.mSpecialValue <= getFocusingTier()) {
if (mFermiumHatch.getFluid() != null
&& mFermiumHatch.getFluid().isFluidEqual(new FluidStack(mFermium, 1))) {
doFermium = true;
@@ -765,19 +755,36 @@ public class GregtechMetaTileEntity_QuantumForceTransformer
doFermium = false;
}
- while (mCurrentParallel < mCurrentMaxParallel
- && tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- mCurrentParallel++;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(getMaxInputAmps() * getAverageInputVoltage())
+ .setMaxParallel(mCurrentMaxParallel)
+ .enableConsumption();
+
+ if (mBatchMode) {
+ helper.enableBatchMode(128);
}
- this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
- this.mEfficiencyIncrease = 10000;
+ helper.build();
+
+ if (helper.getCurrentParallel() == 0) {
+ return false;
+ }
- mMaxProgresstime = tRecipe.mDuration;
- lEUt = -tRecipe.mEUt * mCurrentParallel;
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(getAverageInputVoltage())
+ .setAmperage(getMaxInputAmps())
+ .setDuration(tRecipe.mDuration)
+ .setParallel(Math.min(mMaxParallel, helper.getCurrentParallel()))
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
- calculateOverclockedNessMultiInternal(
- tRecipe.mEUt * mCurrentParallel, tRecipe.mDuration, 1, tTotalEUt, false);
+ this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
+ this.mEfficiencyIncrease = 10000;
if (mMaxProgresstime == Integer.MAX_VALUE - 1 || lEUt == Long.MAX_VALUE - 1) return false;
@@ -789,7 +796,8 @@ public class GregtechMetaTileEntity_QuantumForceTransformer
if (aStack == null
|| aStack.getItemDamage() == 0
|| mNeptuniumHatch.getFluid() == null
- || !mNeptuniumHatch.getFluid().isFluidEqual(new FluidStack(mNeptunium, 1))) {
+ || !mNeptuniumHatch.getFluid().isFluidEqual(new FluidStack(mNeptunium, 1))
+ || tRecipe.mSpecialValue > getFocusingTier()) {
doNeptunium = false;
tChances = GetChanceOutputs(tRecipe, -1);
} else {
@@ -989,6 +997,15 @@ public class GregtechMetaTileEntity_QuantumForceTransformer
@Override
public boolean onWireCutterRightClick(
byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
+ if (aPlayer.isSneaking()) {
+ mBatchMode = !mBatchMode;
+ if (mBatchMode) {
+ GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("misc.BatchModeTextOn"));
+ } else {
+ GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("misc.BatchModeTextOff"));
+ }
+ return true;
+ }
mSeparateInputBusses = !mSeparateInputBusses;
GT_Utility.sendChatToPlayer(
aPlayer, StatCollector.translateToLocal("GT5U.machines.separatebus") + " " + mSeparateInputBusses);
@@ -1041,14 +1058,18 @@ public class GregtechMetaTileEntity_QuantumForceTransformer
aNBT.setBoolean("mSeparateInputBusses", mSeparateInputBusses);
aNBT.setBoolean("mFluidMode", mFluidMode);
aNBT.setBoolean("doFermium", doFermium);
+ aNBT.setBoolean("doNeptunium", doNeptunium);
+ aNBT.setBoolean("mBatchMode", mBatchMode);
super.saveNBTData(aNBT);
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
- this.mSeparateInputBusses = aNBT.getBoolean("mSeparateInputBusses");
- this.mFluidMode = aNBT.getBoolean("mFluidMode");
- this.doFermium = aNBT.getBoolean("doFermium");
+ mSeparateInputBusses = aNBT.getBoolean("mSeparateInputBusses");
+ mFluidMode = aNBT.getBoolean("mFluidMode");
+ doFermium = aNBT.getBoolean("doFermium");
+ doNeptunium = aNBT.getBoolean("doNeptunium");
+ mBatchMode = aNBT.getBoolean("mBatchMode");
super.loadNBTData(aNBT);
}
@@ -1084,39 +1105,6 @@ public class GregtechMetaTileEntity_QuantumForceTransformer
return Textures.BlockIcons.getCasingTextureForId(getCasingTextureId());
}
- @Override
- protected void calculateOverclockedNessMultiInternal(
- long aEUt, int aDuration, int mAmperage, long maxInputVoltage, boolean perfectOC) {
- // 5% space for cable loss
- long zMaxInputVoltage = maxInputVoltage / 100L * 95L;
- long zTime = aDuration;
- long zEUt = aEUt;
- if (zEUt > zMaxInputVoltage) {
- zTime = Integer.MAX_VALUE - 1;
- zEUt = Long.MAX_VALUE - 1;
- }
- while (zEUt << 2 < zMaxInputVoltage) {
- zEUt = zEUt << 2;
- zTime = zTime >> (perfectOC ? 2 : 1);
- if (zTime <= 0) {
- break;
- }
- }
- if (zEUt > zMaxInputVoltage) {
- zEUt = zEUt >> 2;
- zTime = zTime << (perfectOC ? 2 : 1);
- }
- if (zTime <= 0) {
- zTime = 1;
- }
-
- if (zTime > Integer.MAX_VALUE - 1) {
- zTime = Integer.MAX_VALUE - 1;
- }
- this.lEUt = zEUt;
- this.mMaxProgresstime = (int) zTime;
- }
-
@SideOnly(Side.CLIENT)
private void renderForceField(
double x, double y, double z, int side, double minU, double maxU, double minV, double maxV) {
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java
index 536f87f06e..1225fe318d 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java
@@ -8,7 +8,6 @@ import static gregtech.api.enums.GT_HatchElement.InputBus;
import static gregtech.api.enums.GT_HatchElement.InputHatch;
import static gregtech.api.enums.GT_HatchElement.OutputBus;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
@@ -21,6 +20,7 @@ import gregtech.api.interfaces.IIconContainer;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
+import gregtech.api.util.GT_ParallelHelper;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import gtPlusPlus.api.objects.Logger;
@@ -35,14 +35,11 @@ import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_AlgaeFarm;
import ic2.core.init.BlocksItems;
import ic2.core.init.InternalName;
-import java.util.ArrayList;
-import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase<GregtechMTE_AlgaePondBase>
implements ISurvivalConstructable {
@@ -366,12 +363,10 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase<Gregt
GT_Recipe aRecipe) {
if (this.mLevel < 0) {
- Logger.INFO("Bad Tier.");
return false;
}
if (!checkForWater()) {
- Logger.INFO("Not enough Water.");
return false;
}
@@ -381,8 +376,6 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase<Gregt
this.mOutputItems = new ItemStack[] {};
this.mOutputFluids = new FluidStack[] {};
- Logger.INFO("Running checkRecipeGeneric(0)");
-
GT_Recipe tRecipe = RecipeLoader_AlgaeFarm.getTieredRecipeFromCache(this.mLevel, isUsingCompost(aItemInputs));
this.mLastRecipe = tRecipe;
@@ -391,88 +384,38 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase<Gregt
return false;
}
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- return false;
- }
- if (tRecipe.mInputs.length > 0) {
- for (ItemStack aInputToConsume : tRecipe.mInputs) {
- this.depleteInput(aInputToConsume);
- }
- }
-
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- this.mMaxProgresstime = (int) (tRecipe.mDuration);
- this.lEUt = 0;
- this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
- this.mEfficiencyIncrease = 10000;
- Logger.INFO("Recipe time: " + this.mMaxProgresstime);
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= aMaxParallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(120)
+ .setMaxParallel(aMaxParallelRecipes)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < aMaxParallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
+ if (mUseMultiparallelMode) {
+ helper.enableBatchMode(128);
}
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
+ helper.build();
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
+ if (helper.getCurrentParallel() == 0) {
+ return false;
}
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
+ this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
+ this.mEfficiencyIncrease = 10000;
+ mMaxProgresstime = (int) Math.ceil(tRecipe.mDuration * helper.getDurationMultiplier());
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
updateSlots();
// Play sounds (GT++ addition - GT multiblocks play no sounds)
startProcess();
-
- Logger.INFO("GOOD RETURN - 1");
return true;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java
index da8804072c..cb25aeb155 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java
@@ -7,7 +7,6 @@ import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
import static gregtech.api.util.GT_StructureUtility.filterByMTETier;
import static gregtech.api.util.GT_StructureUtility.ofCoil;
-import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import com.gtnewhorizon.structurelib.StructureLibAPI;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
@@ -21,6 +20,8 @@ import gregtech.api.metatileentity.GregTechTileClientEvents;
import gregtech.api.metatileentity.implementations.*;
import gregtech.api.util.GTPP_Recipe;
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 gtPlusPlus.api.objects.Logger;
@@ -36,7 +37,6 @@ import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers.G
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
@@ -45,7 +45,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
-import org.apache.commons.lang3.ArrayUtils;
public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase<GregtechMTE_ChemicalPlant>
implements ISurvivalConstructable {
@@ -635,7 +634,6 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase<Gregt
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
long tEnergy = getMaxInputEnergy();
- log("Running checkRecipeGeneric(0)");
// GT_Recipe tRecipe = findRecipe(getBaseMetaTileEntity(), mLastRecipe, false,
// gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs);
@@ -643,7 +641,6 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase<Gregt
mLastRecipe, gregtech.api.enums.GT_Values.V[tTier], getSolidCasingTier(), aItemInputs, aFluidInputs);
if (tRecipe == null) {
- log("BAD RETURN - 1");
return false;
}
@@ -659,28 +656,17 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase<Gregt
if (aDoesRecipeNeedCatalyst) {
tCatalystRecipe = findCatalyst(aItemInputs, tRecipe.mInputs);
if (tCatalystRecipe == null) {
- log("does not have catalyst");
return false;
}
if (mCatalystBuses.size() != 1) {
- log("does not have correct number of catalyst hatches. (Required 1, found " + mCatalystBuses.size()
- + ")");
return false;
}
}
- log("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
if (tRecipe.mSpecialValue > this.mSolidCasingTier) {
- log("solid tier is too low");
- return false;
- }
-
- aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes);
- if (aMaxParallelRecipes == 0) {
- log("BAD RETURN - 2");
return false;
}
@@ -690,137 +676,50 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase<Gregt
if (tCatalystRecipe != null) {
tCatalysts = new ArrayList<ItemStack>();
tMaxParallelCatalyst = getCatalysts(aItemInputs, tCatalystRecipe, aMaxParallelRecipes, tCatalysts);
- log("Can process " + tMaxParallelCatalyst + " recipes. If less than " + aMaxParallelRecipes
- + ", catalyst does not have enough durability.");
}
if (tMaxParallelCatalyst == 0) {
- log("found not enough catalysts");
return false;
}
- // EU discount
- float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
- float tTotalEUt = 0.0f;
- log("aEUPercent " + aEUPercent);
- log("mEUt " + tRecipe.mEUt);
-
- int parallelRecipes = 0;
-
- log("parallelRecipes: " + parallelRecipes);
- log("aMaxParallelRecipes: " + tMaxParallelCatalyst);
- log("tTotalEUt: " + tTotalEUt);
- log("tVoltage: " + tVoltage);
- log("tEnergy: " + tEnergy);
- log("tRecipeEUt: " + tRecipeEUt);
- // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
- for (; parallelRecipes < tMaxParallelCatalyst && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
- if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
- log("Broke at " + parallelRecipes + ".");
- break;
- }
- log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ".");
- tTotalEUt += tRecipeEUt;
+ GT_ParallelHelper helper = new GT_ParallelHelper()
+ .setRecipe(tRecipe)
+ .setItemInputs(aItemInputs)
+ .setFluidInputs(aFluidInputs)
+ .setAvailableEUt(tEnergy)
+ .setMaxParallel(tMaxParallelCatalyst)
+ .enableConsumption()
+ .enableOutputCalculation();
+ if (!mVoidExcess) {
+ helper.enableVoidProtection(this);
}
- if (parallelRecipes == 0) {
- log("BAD RETURN - 3");
- return false;
+ if (mUseMultiparallelMode) {
+ helper.enableBatchMode(128);
}
- // -- Try not to fail after this point - inputs have already been consumed! --
-
- // Convert speed bonus to duration multiplier
- // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
- aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
- float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent);
- this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor);
+ helper.build();
- this.lEUt = (long) Math.ceil(tTotalEUt);
+ if (helper.getCurrentParallel() == 0) {
+ return false;
+ }
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
- // Overclock
- if (this.lEUt <= 16) {
- this.lEUt = (this.lEUt * (1 << tTier - 1) * (1 << tTier - 1));
- this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1));
- } else {
- while (this.lEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) {
- this.lEUt *= 4;
- this.mMaxProgresstime /= 2;
- }
- }
-
- if (this.lEUt > 0) {
- this.lEUt = (-this.lEUt);
- }
-
- this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
-
- // Collect fluid outputs
- FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length];
- for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) {
- if (tRecipe.getFluidOutput(h) != null) {
- tOutputFluids[h] = tRecipe.getFluidOutput(h).copy();
- tOutputFluids[h].amount *= parallelRecipes;
- }
- }
-
- // Collect output item types
- ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOutputItems[h] = tRecipe.getOutput(h).copy();
- tOutputItems[h].stackSize = 0;
- }
- }
-
- // Set output item stack sizes (taking output chance into account)
- for (int f = 0; f < tOutputItems.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) {
- for (int g = 0; g < parallelRecipes; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f))
- tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize;
- }
- }
- }
-
- tOutputItems = removeNulls(tOutputItems);
-
- // Sanitize item stack size, splitting any stacks greater than max stack size
- List<ItemStack> splitStacks = new ArrayList<ItemStack>();
- for (ItemStack tItem : tOutputItems) {
- while (tItem.getMaxStackSize() < tItem.stackSize) {
- ItemStack tmp = tItem.copy();
- tmp.stackSize = tmp.getMaxStackSize();
- tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
- splitStacks.add(tmp);
- }
- }
-
- if (splitStacks.size() > 0) {
- ItemStack[] tmp = new ItemStack[splitStacks.size()];
- tmp = splitStacks.toArray(tmp);
- tOutputItems = ArrayUtils.addAll(tOutputItems, tmp);
- }
-
- // Strip empty stacks
- List<ItemStack> tSList = new ArrayList<ItemStack>();
- for (ItemStack tS : tOutputItems) {
- if (tS.stackSize > 0) tSList.add(tS);
- }
- tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
-
- // Damage catalyst once all is said and done.
- if (tCatalystRecipe != null) {
- log("damaging catalyst");
- damageCatalyst(tCatalystRecipe, parallelRecipes);
- }
-
- // Commit outputs
- this.mOutputItems = tOutputItems;
- this.mOutputFluids = tOutputFluids;
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator()
+ .setRecipeEUt(tRecipe.mEUt)
+ .setEUt(tEnergy)
+ .setDuration(tRecipe.mDuration)
+ .setEUtDiscount(100.0f / aEUPercent)
+ .setSpeedBoost((100.0f / aSpeedBonusPercent))
+ .setParallel(Math.min(aMaxParallelRecipes, helper.getCurrentParallel()))
+ .calculate();
+ lEUt = -calculator.getConsumption();
+ mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplier());
+
+ mOutputItems = helper.getItemOutputs();
+ mOutputFluids = helper.getFluidOutputs();
updateSlots();
for (GT_MetaTileEntity_Hatch_Catalysts h : mCatalystBuses) {
h.updateSlots();
@@ -830,7 +729,6 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase<Gregt
// Play sounds (GT++ addition - GT multiblocks play no sounds)
startProcess();
- log("GOOD RETURN - 1");
return true;
}