From 92f2b931a3bd7f858bd57d146a620e497da3174b Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 22 Mar 2021 15:22:11 -0700 Subject: swapped repetitive if-block to switch statement and cached machine tier --- .../multi/GT_MetaTileEntity_ProcessingArray.java | 100 +++++++++++---------- 1 file changed, 52 insertions(+), 48 deletions(-) (limited to 'src/main/java') 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 1fdc698fe4..371c7948c7 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 @@ -139,6 +139,8 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBl } private String mMachine = ""; + private int mMachineTier = 0; + public boolean checkRecipe(ItemStack aStack) { if (!isCorrectMachinePart(mInventory[1])) { return false; @@ -146,62 +148,64 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBl GT_Recipe.GT_Recipe_Map map = getRecipeMap(); if (map == null) return false; - if (mInventory[1].getUnlocalizedName().endsWith("10")) { - tTier = 9; - mMult = 2;//u need 4x less machines and they will use 4x less power - } else if (mInventory[1].getUnlocalizedName().endsWith("11")) { - tTier = 9; - mMult = 4;//u need 16x less machines and they will use 16x less power - } else if (mInventory[1].getUnlocalizedName().endsWith("12") || - mInventory[1].getUnlocalizedName().endsWith("13") || - mInventory[1].getUnlocalizedName().endsWith("14") || - mInventory[1].getUnlocalizedName().endsWith("15")) { - tTier = 9; - mMult = 6;//u need 64x less machines and they will use 64x less power - } else if (mInventory[1].getUnlocalizedName().endsWith("1")) { - tTier = 1; - mMult = 0;//*1 - } else if (mInventory[1].getUnlocalizedName().endsWith("2")) { - tTier = 2; - mMult = 0;//*1 - } else if (mInventory[1].getUnlocalizedName().endsWith("3")) { - tTier = 3; - mMult = 0;//*1 - } else if (mInventory[1].getUnlocalizedName().endsWith("4")) { - tTier = 4; - mMult = 0;//*1 - } else if (mInventory[1].getUnlocalizedName().endsWith("5")) { - tTier = 5; - mMult = 0;//*1 - } else if (mInventory[1].getUnlocalizedName().endsWith("6")) { - tTier = 6; - mMult = 0;//*1 - } else if (mInventory[1].getUnlocalizedName().endsWith("7")) { - tTier = 7; - mMult = 0;//*1 - } else if (mInventory[1].getUnlocalizedName().endsWith("8")) { - tTier = 8; - mMult = 0;//*1 - } else if (mInventory[1].getUnlocalizedName().endsWith("9")) { - tTier = 9; - mMult = 0;//*1 - } else { - tTier = 0; - mMult = 0;//*1 + if (!mMachine.equals(mInventory[1].getUnlocalizedName())) { + mLastRecipe = null; + mMachine = mInventory[1].getUnlocalizedName(); } - if (!mMachine.equals(mInventory[1].getUnlocalizedName())) mLastRecipe = null; - mMachine = mInventory[1].getUnlocalizedName(); + if (mLastRecipe == null) { + try { + int length = mMachine.length(); + + mMachineTier = Integer.parseInt(mMachine.substring(length - 2)); + + } catch (NumberFormatException e) { + } + + switch (mMachineTier) { + default: + tTier = 0; + mMult = 0;//*1 + break; + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + tTier = mMachineTier; + mMult = 0;//*1 + break; + case 10: + tTier = 9; + mMult = 2;//u need 4x less machines and they will use 4x less power + break; + case 11: + tTier = 9; + mMult = 4;//u need 16x less machines and they will use 16x less power + break; + case 12: + case 13: + case 14: + case 15: + tTier = 9; + mMult = 6;//u need 64x less machines and they will use 64x less power + break; + } + } ArrayList tFluidList = getStoredFluids(); FluidStack[] tFluids = (FluidStack[]) tFluidList.toArray(new FluidStack[tFluidList.size()]); if (mSeparate) { ArrayList tInputList = new ArrayList(); for (GT_MetaTileEntity_Hatch_InputBus tHatch : mInputBusses) { - IGregTechTileEntity tInpuBus = tHatch.getBaseMetaTileEntity(); - for (int i = tInpuBus.getSizeInventory() - 1; i >= 0; i--) { - if (tInpuBus.getStackInSlot(i) != null) - tInputList.add(tInpuBus.getStackInSlot(i)); + IGregTechTileEntity tInputBus = tHatch.getBaseMetaTileEntity(); + for (int i = tInputBus.getSizeInventory() - 1; i >= 0; i--) { + if (tInputBus.getStackInSlot(i) != null) + tInputList.add(tInputBus.getStackInSlot(i)); } ItemStack[] tInputs = (ItemStack[]) tInputList.toArray(new ItemStack[tInputList.size()]); if (processRecipe(tInputs, tFluids, map)) -- cgit From 6ea482c9512fc18ba05f1a3c9a1292df2af6d730 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 23 Mar 2021 12:50:46 -0700 Subject: removed mMachineTier member --- .../machines/multi/GT_MetaTileEntity_ProcessingArray.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/main/java') 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 371c7948c7..d86e8cf7f8 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 @@ -139,7 +139,6 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBl } private String mMachine = ""; - private int mMachineTier = 0; public boolean checkRecipe(ItemStack aStack) { if (!isCorrectMachinePart(mInventory[1])) { @@ -153,16 +152,18 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBl mMachine = mInventory[1].getUnlocalizedName(); } + int machineTier = 0; + if (mLastRecipe == null) { try { int length = mMachine.length(); - mMachineTier = Integer.parseInt(mMachine.substring(length - 2)); + machineTier = Integer.parseInt(mMachine.substring(length - 2)); } catch (NumberFormatException e) { } - switch (mMachineTier) { + switch (machineTier) { default: tTier = 0; mMult = 0;//*1 @@ -176,7 +177,7 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBl case 7: case 8: case 9: - tTier = mMachineTier; + tTier = machineTier; mMult = 0;//*1 break; case 10: -- cgit