aboutsummaryrefslogtreecommitdiff
path: root/src/Java
diff options
context:
space:
mode:
authorAlkalus <draknyte1@hotmail.com>2018-02-05 02:40:14 +1000
committerGitHub <noreply@github.com>2018-02-05 02:40:14 +1000
commit992d063a7ce73b40bd380d310d661eb8bed4c1bb (patch)
tree79669d47b8f433ec44566c0ae8e35aa95892906d /src/Java
parent3e5a09f65c0e283f1eaf92ca5e8e39e22cb30f96 (diff)
parentd64a97fa8293ef6cb32f1fe5daea38a3669e8869 (diff)
downloadGT5-Unofficial-992d063a7ce73b40bd380d310d661eb8bed4c1bb.tar.gz
GT5-Unofficial-992d063a7ce73b40bd380d310d661eb8bed4c1bb.tar.bz2
GT5-Unofficial-992d063a7ce73b40bd380d310d661eb8bed4c1bb.zip
Merge pull request #208 from codewarrior0/can-buffer-outputs-stacking-check
Change canBufferOutputs to consider whether outputs can stack. Check if items in the output buses can stack with the outputs. Consider max number of parallel recipes in canBufferOutputs. Reset outputs and progress earlier in checkRecipeGeneric().
Diffstat (limited to 'src/Java')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java45
1 files changed, 32 insertions, 13 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java
index 44a16666b7..e0da8e9fc2 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java
@@ -120,8 +120,10 @@ GT_MetaTileEntity_MultiBlockBase {
public String getSound() { return ""; }
- public boolean canBufferOutputs(final GT_Recipe aRecipe) {
- // Count slots available in hatches
+ public boolean canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes) {
+ // Count slots available in output buses
+ ArrayList<ItemStack> tBusStacks = new ArrayList<>();
+
int tEmptySlots = 0;
for (final GT_MetaTileEntity_Hatch_OutputBus tBus : this.mOutputBusses) {
if (!isValidMetaTileEntity(tBus)) {
@@ -132,12 +134,26 @@ GT_MetaTileEntity_MultiBlockBase {
if (tBus.getStackInSlot(i) == null) {
tEmptySlots++;
}
+ else {
+ tBusStacks.add(tBus.getStackInSlot(i));
+ }
}
}
- // TODO: Check if any of the output stacks can stack with the stacks in the hatches?
+ int slotsNeeded = aRecipe.mOutputs.length;
+ for (final ItemStack tRecipeOutput: aRecipe.mOutputs) {
+ int amount = tRecipeOutput.stackSize * aParallelRecipes;
+ for (final ItemStack tBusStack : tBusStacks) {
+ if (GT_Utility.areStacksEqual(tBusStack, tRecipeOutput)) {
+ if (tBusStack.stackSize + amount <= tBusStack.getMaxStackSize()) {
+ slotsNeeded--;
+ break;
+ }
+ }
+ }
+ }
// Enough open slots?
- if (tEmptySlots < aRecipe.mOutputs.length) return false;
+ if (tEmptySlots < slotsNeeded) return false;
// For each output fluid, make sure an output hatch can accept it.
for (FluidStack tRecipeFluid: aRecipe.mFluidOutputs) {
@@ -181,13 +197,17 @@ GT_MetaTileEntity_MultiBlockBase {
ItemStack[] aItemInputs, FluidStack[] aFluidInputs,
int aMaxParallelRecipes, int aEUPercent,
int aSpeedBonusPercent, int aOutputChanceRoll) {
+ // Based on the Processing Array. A bit overkill, but very flexible.
+ // Reset outputs and progress stats
+ this.mEUt = 0;
+ this.mMaxProgresstime = 0;
+ this.mOutputItems = new ItemStack[]{};
+ this.mOutputFluids = new FluidStack[]{};
- // Based on the Processing Array. A bit overkill, but very flexible.
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
- int parallelRecipes = 0;
GT_Recipe tRecipe = this.getRecipeMap().findRecipe(
getBaseMetaTileEntity(), mLastRecipe, false,
@@ -200,7 +220,7 @@ GT_MetaTileEntity_MultiBlockBase {
return false;
}
- if (!this.canBufferOutputs(tRecipe)) {
+ if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) {
return false;
}
@@ -208,12 +228,8 @@ GT_MetaTileEntity_MultiBlockBase {
float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
float tTotalEUt = 0.0f;
- // Reset outputs and progress stats
- this.mEUt = 0;
- this.mMaxProgresstime = 0;
- this.mOutputItems = new ItemStack[]{};
- this.mOutputFluids = new FluidStack[]{};
-
+ int parallelRecipes = 0;
+
// Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tVoltage - tRecipeEUt); parallelRecipes++) {
if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
@@ -226,6 +242,9 @@ GT_MetaTileEntity_MultiBlockBase {
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);