From 4e04bf5e76ad92e1cc1b2b2eeaa0bc141975e73a Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Mon, 28 Dec 2020 15:02:27 +0100 Subject: More Refactor --- .../GT_MetaTileEntity_MultiBlockBase.java | 65 ++++++++++++++++++---- 1 file changed, 53 insertions(+), 12 deletions(-) (limited to 'src/main/java/gregtech/api/metatileentity') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 202e542c88..b859607ada 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -34,21 +34,21 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { public static boolean disableMaintenance; public boolean mMachine = false, mWrench = false, mScrewdriver = false, mSoftHammer = false, mHardHammer = false, mSolderingTool = false, mCrowbar = false, mRunningOnLoad = false; public int mPollution = 0, mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0, mEfficiencyIncrease = 0, mStartUpCheck = 100, mRuntime = 0, mEfficiency = 0; - public volatile int mUpdate = 0; + public volatile int mUpdate = 0; //TODO: Replace with AtomicInteger public ItemStack[] mOutputItems = null; public FluidStack[] mOutputFluids = null; public String mNEI; public int damageFactorLow = 5; public float damageFactorHigh = 0.6f; - public ArrayList mInputHatches = new ArrayList(); - public ArrayList mOutputHatches = new ArrayList(); - public ArrayList mInputBusses = new ArrayList(); - public ArrayList mOutputBusses = new ArrayList(); - public ArrayList mDynamoHatches = new ArrayList(); - public ArrayList mMufflerHatches = new ArrayList(); - public ArrayList mEnergyHatches = new ArrayList(); - public ArrayList mMaintenanceHatches = new ArrayList(); + public ArrayList mInputHatches = new ArrayList<>(); + public ArrayList mOutputHatches = new ArrayList<>(); + public ArrayList mInputBusses = new ArrayList<>(); + public ArrayList mOutputBusses = new ArrayList<>(); + public ArrayList mDynamoHatches = new ArrayList<>(); + public ArrayList mMufflerHatches = new ArrayList<>(); + public ArrayList mEnergyHatches = new ArrayList<>(); + public ArrayList mMaintenanceHatches = new ArrayList<>(); public GT_MetaTileEntity_MultiBlockBase(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional, 2); @@ -791,7 +791,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { } public ArrayList getStoredOutputs() { - ArrayList rList = new ArrayList(); + ArrayList rList = new ArrayList<>(); // for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) { // if (isValidMetaTileEntity(tHatch)) { // rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(1)); @@ -808,7 +808,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { } public ArrayList getStoredFluids() { - ArrayList rList = new ArrayList(); + ArrayList rList = new ArrayList<>(); for (GT_MetaTileEntity_Hatch_Input tHatch : mInputHatches) { tHatch.mRecipeMap = getRecipeMap(); if (isValidMetaTileEntity(tHatch) && tHatch.getFillableStack() != null) { @@ -819,7 +819,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { } public ArrayList getStoredInputs() { - ArrayList rList = new ArrayList(); + ArrayList rList = new ArrayList<>(); // for (GT_MetaTileEntity_Hatch_Input tHatch : mInputHatches) { // tHatch.mRecipeMap = getRecipeMap(); // if (isValidMetaTileEntity(tHatch) && tHatch.getBaseMetaTileEntity().getStackInSlot(0) != null) { @@ -1003,4 +1003,45 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { return false; } + + protected ItemStack[] getCompactedInputs(){ + ArrayList tInputList = getStoredInputs(); + int tInputList_sS = tInputList.size(); + for (int i = 0; i < tInputList_sS - 1; i++) { + for (int j = i + 1; j < tInputList_sS; j++) { + if (!GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) + continue; + if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) { + tInputList.remove(j--); + tInputList_sS = tInputList.size(); + } else { + tInputList.remove(i--); + tInputList_sS = tInputList.size(); + break; + } + } + } + return tInputList.toArray(new ItemStack[0]); + } + + protected FluidStack[] getCompactedFluids(){ + ArrayList tFluidList = getStoredFluids(); + int tFluidList_sS = tFluidList.size(); + for (int i = 0; i < tFluidList_sS - 1; i++) { + for (int j = i + 1; j < tFluidList_sS; j++) { + if (!GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) + continue; + + if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { + tFluidList.remove(j--); + tFluidList_sS = tFluidList.size(); + } else { + tFluidList.remove(i--); + tFluidList_sS = tFluidList.size(); + break; + } + } + } + return tFluidList.toArray(new FluidStack[0]); + } } -- cgit From 7fb679c5bec20dc8caa40b3a92b2a6590912f6f9 Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Mon, 28 Dec 2020 18:08:50 +0100 Subject: Added TODOs for code smell --- .../implementations/GT_MetaTileEntity_MultiBlockBase.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main/java/gregtech/api/metatileentity') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index b859607ada..e15166cf62 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -1005,6 +1005,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { } protected ItemStack[] getCompactedInputs(){ + //TODO: repalce method with a cleaner one ArrayList tInputList = getStoredInputs(); int tInputList_sS = tInputList.size(); for (int i = 0; i < tInputList_sS - 1; i++) { @@ -1025,6 +1026,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { } protected FluidStack[] getCompactedFluids(){ + //TODO: repalce method with a cleaner one ArrayList tFluidList = getStoredFluids(); int tFluidList_sS = tFluidList.size(); for (int i = 0; i < tFluidList_sS - 1; i++) { -- cgit From c3defc0dd1bc4a6cf3ab3fddcb44f969a85934ec Mon Sep 17 00:00:00 2001 From: Glease <4586901+glease@users.noreply.github.com> Date: Tue, 29 Dec 2020 20:46:28 +0800 Subject: Remove all energy cost of moving fluid and items Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java | 3 +-- .../api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java | 2 -- src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java | 1 - .../tileentities/automation/GT_MetaTileEntity_ItemDistributor.java | 1 - .../common/tileentities/automation/GT_MetaTileEntity_Regulator.java | 1 - 5 files changed, 1 insertion(+), 7 deletions(-) (limited to 'src/main/java/gregtech/api/metatileentity') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index 2c632c596b..497e42b9aa 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -516,8 +516,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B if (tMaxStacks > mOutputItems.length) tMaxStacks = mOutputItems.length; - int tCost = moveMultipleItemStacks(aBaseMetaTileEntity, tTileEntity2, aBaseMetaTileEntity.getFrontFacing(), aBaseMetaTileEntity.getBackFacing(), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1,tMaxStacks); - aBaseMetaTileEntity.decreaseStoredEnergyUnits(tCost, true); + moveMultipleItemStacks(aBaseMetaTileEntity, tTileEntity2, aBaseMetaTileEntity.getFrontFacing(), aBaseMetaTileEntity.getBackFacing(), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1,tMaxStacks); // for (int i = 0, tCosts = 1; i < mOutputItems.length && tCosts > 0 && aBaseMetaTileEntity.isUniversalEnergyStored(128); i++) { // tCosts = GT_Utility.moveOneItemStack(aBaseMetaTileEntity, tTileEntity2, aBaseMetaTileEntity.getFrontFacing(), aBaseMetaTileEntity.getBackFacing(), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); // if (tCosts > 0) aBaseMetaTileEntity.decreaseStoredEnergyUnits(tCosts, true); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java index 8758ea1a02..981072070b 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java @@ -261,7 +261,6 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM if (mInventory[i] == null) { for(byte b = 0;b<6;b++) aBaseMetaTileEntity.setInternalOutputRedstoneSignal(b,bInvert ? (byte)15 : (byte)0); - aBaseMetaTileEntity.decreaseStoredEnergyUnits(1, true); break; } } @@ -284,7 +283,6 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM if (tCost > 0 || aBaseMetaTileEntity.hasInventoryBeenModified()) { mSuccess = 50; - aBaseMetaTileEntity.decreaseStoredEnergyUnits(Math.abs(tCost), true); } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java b/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java index 39c87669f1..d62e7c67f7 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java @@ -52,7 +52,6 @@ public class GT_Cover_FluidRegulator extends GT_CoverBehavior { if (tLiquid.amount > 0) { if (aTileEntity.getUniversalEnergyCapacity() >= Math.min(1, tLiquid.amount / 10)) { if (aTileEntity.isUniversalEnergyStored(Math.min(1, tLiquid.amount / 10))) { - aTileEntity.decreaseStoredEnergyUnits(Math.min(1, tLiquid.amount / 10), true); tTank2.fill(directionTo, tTank1.drain(directionFrom, tLiquid.amount, true), true); } } else { diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java index 5fa3bc8c82..37d8585310 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java @@ -143,7 +143,6 @@ public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer } if (movedItems > 0 || aBaseMetaTileEntity.hasInventoryBeenModified()) { mSuccess = 50; - aBaseMetaTileEntity.decreaseStoredEnergyUnits(Math.abs(movedItems), true); } fillStacksIntoFirstSlots(); } diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java index b5a33bfb81..746e182066 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java @@ -95,7 +95,6 @@ public class GT_MetaTileEntity_Regulator tCosts = GT_Utility.moveOneItemStackIntoSlot(getBaseMetaTileEntity(), getBaseMetaTileEntity().getTileEntityAtSide(getBaseMetaTileEntity().getBackFacing()), getBaseMetaTileEntity().getBackFacing(), this.mTargetSlots[i], Arrays.asList(new ItemStack[]{this.mInventory[(i + 9)]}), false, (byte) this.mInventory[(i + 9)].stackSize, (byte) this.mInventory[(i + 9)].stackSize, (byte) 64, (byte) 1) * 3; if (tCosts > 0) { this.mSuccess = 50; - getBaseMetaTileEntity().decreaseStoredEnergyUnits(tCosts, true); break; } } -- cgit From eb2f20e5ed7e9c0d572928bb57a99d3f47c8fb11 Mon Sep 17 00:00:00 2001 From: Glease <4586901+glease@users.noreply.github.com> Date: Tue, 29 Dec 2020 23:09:38 +0800 Subject: Remove leftover code of logistics energy cost Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../metatileentity/implementations/GT_MetaTileEntity_Buffer.java | 2 +- src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'src/main/java/gregtech/api/metatileentity') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java index 981072070b..82cda6c670 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java @@ -248,7 +248,7 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if (aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isUniversalEnergyStored(getMinimumStoredEU()) && (aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified() || aTimer % 200 == 0 || mSuccess > 0)) { + if (aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.isServerSide() && (aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified() || aTimer % 200 == 0 || mSuccess > 0)) { mSuccess--; moveItems(aBaseMetaTileEntity, aTimer); for(byte b = 0;b<6;b++) diff --git a/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java b/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java index d62e7c67f7..f8784d570f 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java @@ -50,13 +50,7 @@ public class GT_Cover_FluidRegulator extends GT_CoverBehavior { tLiquid = tLiquid.copy(); tLiquid.amount = tTank2.fill(directionTo, tLiquid, false); if (tLiquid.amount > 0) { - if (aTileEntity.getUniversalEnergyCapacity() >= Math.min(1, tLiquid.amount / 10)) { - if (aTileEntity.isUniversalEnergyStored(Math.min(1, tLiquid.amount / 10))) { - tTank2.fill(directionTo, tTank1.drain(directionFrom, tLiquid.amount, true), true); - } - } else { - tTank2.fill(directionTo, tTank1.drain(directionFrom, tLiquid.amount, true), true); - } + tTank2.fill(directionTo, tTank1.drain(directionFrom, tLiquid.amount, true), true); } } } -- cgit