From c596231af4020af855cbe44dd0aaf906931b62c3 Mon Sep 17 00:00:00 2001 From: Logan Perkins Date: Sun, 12 Jun 2016 10:39:33 -0700 Subject: [PATCH 1/2] Make processing array use all input stacks --- .../GT_MetaTileEntity_ProcessingArray.java | 32 +++---------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java index bedc4d65..cdbeb562 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java @@ -148,34 +148,12 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBl if (mInventory[1].getUnlocalizedName().endsWith("5")) { tTier = 5; } - for (int i = 0; i < tInputList.size() - 1; i++) { - for (int j = i + 1; j < tInputList.size(); j++) { - if (GT_Utility.areStacksEqual((ItemStack) tInputList.get(i), (ItemStack) tInputList.get(j))) { - if (((ItemStack) tInputList.get(i)).stackSize >= ((ItemStack) tInputList.get(j)).stackSize) { - tInputList.remove(j--); - } else { - tInputList.remove(i--); - break; - } - } - } - } - ItemStack[] tInputs = (ItemStack[]) Arrays.copyOfRange(tInputList.toArray(new ItemStack[tInputList.size()]), 0, 2); + + ItemStack[] tInputs = (ItemStack[]) tInputList.toArray(new ItemStack[tInputList.size()]); ArrayList tFluidList = getStoredFluids(); - for (int i = 0; i < tFluidList.size() - 1; i++) { - for (int j = i + 1; j < tFluidList.size(); j++) { - if (GT_Utility.areFluidsEqual((FluidStack) tFluidList.get(i), (FluidStack) tFluidList.get(j))) { - if (((FluidStack) tFluidList.get(i)).amount >= ((FluidStack) tFluidList.get(j)).amount) { - tFluidList.remove(j--); - } else { - tFluidList.remove(i--); - break; - } - } - } - } - FluidStack[] tFluids = (FluidStack[]) Arrays.copyOfRange(tFluidList.toArray(new FluidStack[tInputList.size()]), 0, 1); + + FluidStack[] tFluids = (FluidStack[]) tFluidList.toArray(new FluidStack[rFluidList.size()]); if (tInputList.size() > 0 || tFluids.length > 0) { GT_Recipe tRecipe = map.findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); if (tRecipe != null) { @@ -308,4 +286,4 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBl public boolean explodesOnComponentBreak(ItemStack aStack) { return false; } -} \ No newline at end of file +} From 54ae577be0c9705fddd29836a5fdca58c89e6c50 Mon Sep 17 00:00:00 2001 From: Logan Perkins Date: Sun, 12 Jun 2016 10:41:52 -0700 Subject: [PATCH 2/2] Make recipe input work for split stacks --- .../java/gregtech/api/util/GT_Recipe.java | 85 ++++++++++++++----- 1 file changed, 65 insertions(+), 20 deletions(-) diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 71b00199..0b03d199 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -317,57 +317,102 @@ public class GT_Recipe { public boolean isRecipeInputEqual(boolean aDecreaseStacksizeBySuccess, boolean aDontCheckStackSizes, FluidStack[] aFluidInputs, ItemStack... aInputs) { if (mFluidInputs.length > 0 && aFluidInputs == null) return false; + int amt; for (FluidStack tFluid : mFluidInputs) if (tFluid != null) { boolean temp = true; + amt = tFluid.amount; for (FluidStack aFluid : aFluidInputs) - if (aFluid != null && aFluid.isFluidEqual(tFluid) && (aDontCheckStackSizes || aFluid.amount >= tFluid.amount)) { - temp = false; - break; + if (aFluid != null && aFluid.isFluidEqual(tFluid)){ + if (aDontCheckStackSizes ){ + temp = false; + break; + } + amt -= aFluid.amount; + if (amt<1){ + temp = false; + break; + } } if (temp) return false; } if (mInputs.length > 0 && aInputs == null) return false; - for (ItemStack tStack : mInputs) + for (ItemStack tStack : mInputs) { if (tStack != null) { + amt = tStack.stackSize; boolean temp = true; - for (ItemStack aStack : aInputs) - if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true)) && (aDontCheckStackSizes || aStack.stackSize >= tStack.stackSize)) { - temp = false; - break; + for (ItemStack aStack : aInputs) { + if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) { + if (aDontCheckStackSizes) { + temp = false; + break; + } + amt -= aStack.stackSize; + if (amt < 1) { + temp = false; + break; + } } + } if (temp) return false; } - + } if (aDecreaseStacksizeBySuccess) { if (aFluidInputs != null) { - for (FluidStack tFluid : mFluidInputs) + for (FluidStack tFluid : mFluidInputs) { if (tFluid != null) { - for (FluidStack aFluid : aFluidInputs) - if (aFluid != null && aFluid.isFluidEqual(tFluid) && (aDontCheckStackSizes || aFluid.amount >= tFluid.amount)) { - aFluid.amount -= tFluid.amount; - break; + amt = tFluid.amount; + for (FluidStack aFluid : aFluidInputs) { + if (aFluid != null && aFluid.isFluidEqual(tFluid)) { + if (aDontCheckStackSizes) { + aFluid.amount -= amt; + break; + } + if (aFluid.amount < amt) { + amt -= aFluid.amount; + aFluid.amount = 0; + } else { + aFluid.amount -= amt; + amt = 0; + break; + } } + } } + } } if (aInputs != null) { - for (ItemStack tStack : mInputs) + for (ItemStack tStack : mInputs) { if (tStack != null) { - for (ItemStack aStack : aInputs) - if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true)) && (aDontCheckStackSizes || aStack.stackSize >= tStack.stackSize)) { - aStack.stackSize -= tStack.stackSize; - break; + amt = tStack.stackSize; + for (ItemStack aStack : aInputs) { + if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) { + if (aDontCheckStackSizes){ + aStack.stackSize -= amt; + break; + } + if (aStack.stackSize < amt){ + amt -= aStack.stackSize; + aStack.stackSize = 0; + }else{ + aStack.stackSize -= amt; + amt = 0; + break; + } } + } } + } } } return true; } + public static class GT_Recipe_Map { /** * Contains all Recipe Maps @@ -1272,4 +1317,4 @@ public class GT_Recipe { return super.containsInput(aFluid) || Dyes.isAnyFluidDye(aFluid); } } -} \ No newline at end of file +}