From 6612c5495e0d225550a8459ee2c9f8a2097bd66f Mon Sep 17 00:00:00 2001 From: miozune Date: Mon, 30 Oct 2023 18:42:33 +0900 Subject: Cleanup isValidMetaTileEntity --- .../base/GregtechMeta_MultiBlockBase.java | 73 +++++++------------ .../base/GregtechMeta_SteamMultiBase.java | 81 ++++++++++------------ 2 files changed, 61 insertions(+), 93 deletions(-) (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations') 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 01e0f731f6..cf460ca084 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,6 +1,7 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; import static gregtech.api.enums.Mods.TecTech; +import static gregtech.api.util.GT_Utility.filterValidMTEs; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -120,12 +121,6 @@ public abstract class GregtechMeta_MultiBlockBase e) { int tMaxStackSize = e.getKey().getMaxStackSize(); int tStackSize = e.getValue(); @@ -307,50 +302,40 @@ public abstract class GregtechMeta_MultiBlockBase aHatches, int aAmount) { - for (final GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : aHatches) { - if (isValidMetaTileEntity(tHatch)) { - FluidStack tLiquid = tHatch.getFluid(); - if (tLiquid == null || tLiquid.amount < aAmount) { - continue; - } - tLiquid = tHatch.drain(aAmount, false); - if (tLiquid != null && tLiquid.amount >= aAmount) { - tLiquid = tHatch.drain(aAmount, true); - return tLiquid != null && tLiquid.amount >= aAmount; - } + for (final GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(aHatches)) { + FluidStack tLiquid = tHatch.getFluid(); + if (tLiquid == null || tLiquid.amount < aAmount) { + continue; + } + tLiquid = tHatch.drain(aAmount, false); + if (tLiquid != null && tLiquid.amount >= aAmount) { + tLiquid = tHatch.drain(aAmount, true); + return tLiquid != null && tLiquid.amount >= aAmount; } } return false; @@ -540,15 +523,11 @@ public abstract class GregtechMeta_MultiBlockBase= aLiquid.amount) { - tLiquid = tHatch.drain(aLiquid.amount, true); - return tLiquid != null && tLiquid.amount >= aLiquid.amount; - } + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mSteamInputFluids)) { + FluidStack tLiquid = tHatch.getFluid(); + if (tLiquid != null && tLiquid.isFluidEqual(aLiquid)) { + tLiquid = tHatch.drain(aLiquid.amount, false); + if (tLiquid != null && tLiquid.amount >= aLiquid.amount) { + tLiquid = tHatch.drain(aLiquid.amount, true); + return tLiquid != null && tLiquid.amount >= aLiquid.amount; } } } @@ -203,25 +202,21 @@ public abstract class GregtechMeta_SteamMultiBase= aStack.stackSize) { - tHatch.getBaseMetaTileEntity().decrStackSize(0, aStack.stackSize); - return true; - } + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mSteamInputFluids)) { + if (GT_Utility.areStacksEqual(aStack, tHatch.getBaseMetaTileEntity().getStackInSlot(0))) { + if (tHatch.getBaseMetaTileEntity().getStackInSlot(0).stackSize >= aStack.stackSize) { + tHatch.getBaseMetaTileEntity().decrStackSize(0, aStack.stackSize); + return true; } } } - for (GT_MetaTileEntity_Hatch_Steam_BusInput tHatch : mSteamInputs) { + for (GT_MetaTileEntity_Hatch_Steam_BusInput tHatch : filterValidMTEs(mSteamInputs)) { tHatch.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (GT_Utility.areStacksEqual(aStack, tHatch.getBaseMetaTileEntity().getStackInSlot(i))) { - if (tHatch.getBaseMetaTileEntity().getStackInSlot(0).stackSize >= aStack.stackSize) { - tHatch.getBaseMetaTileEntity().decrStackSize(0, aStack.stackSize); - return true; - } + for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (GT_Utility.areStacksEqual(aStack, tHatch.getBaseMetaTileEntity().getStackInSlot(i))) { + if (tHatch.getBaseMetaTileEntity().getStackInSlot(0).stackSize >= aStack.stackSize) { + tHatch.getBaseMetaTileEntity().decrStackSize(0, aStack.stackSize); + return true; } } } @@ -232,8 +227,8 @@ public abstract class GregtechMeta_SteamMultiBase getStoredFluids() { ArrayList rList = new ArrayList<>(); - for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mSteamInputFluids) { - if (isValidMetaTileEntity(tHatch) && tHatch.getFillableStack() != null) { + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mSteamInputFluids)) { + if (tHatch.getFillableStack() != null) { rList.add(tHatch.getFillableStack()); } } @@ -243,13 +238,11 @@ public abstract class GregtechMeta_SteamMultiBase getStoredInputs() { ArrayList rList = new ArrayList<>(); - for (GT_MetaTileEntity_Hatch_Steam_BusInput tHatch : mSteamInputs) { + for (GT_MetaTileEntity_Hatch_Steam_BusInput tHatch : filterValidMTEs(mSteamInputs)) { tHatch.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - if (tHatch.getBaseMetaTileEntity().getStackInSlot(i) != null) { - rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(i)); - } + for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + if (tHatch.getBaseMetaTileEntity().getStackInSlot(i) != null) { + rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(i)); } } } @@ -264,15 +257,15 @@ public abstract class GregtechMeta_SteamMultiBase 0) { outputSuccess = false; ItemStack single = aStack.splitStack(1); - for (GT_MetaTileEntity_Hatch_Steam_BusOutput tHatch : mSteamOutputs) { - if (!outputSuccess && isValidMetaTileEntity(tHatch)) { + for (GT_MetaTileEntity_Hatch_Steam_BusOutput tHatch : filterValidMTEs(mSteamOutputs)) { + if (!outputSuccess) { for (int i = tHatch.getSizeInventory() - 1; i >= 0 && !outputSuccess; i--) { if (tHatch.getBaseMetaTileEntity().addStackToSlot(i, single)) outputSuccess = true; } } } - for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) { - if (!outputSuccess && isValidMetaTileEntity(tHatch) && tHatch.outputsItems()) { + for (GT_MetaTileEntity_Hatch_Output tHatch : filterValidMTEs(mOutputHatches)) { + if (!outputSuccess && tHatch.outputsItems()) { if (tHatch.getBaseMetaTileEntity().addStackToSlot(1, single)) outputSuccess = true; } } @@ -283,11 +276,9 @@ public abstract class GregtechMeta_SteamMultiBase getStoredOutputs() { ArrayList rList = new ArrayList<>(); - for (GT_MetaTileEntity_Hatch_Steam_BusOutput tHatch : mSteamOutputs) { - if (isValidMetaTileEntity(tHatch)) { - for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { - rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(i)); - } + for (GT_MetaTileEntity_Hatch_Steam_BusOutput tHatch : filterValidMTEs(mSteamOutputs)) { + for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; i--) { + rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(i)); } } return rList; @@ -296,7 +287,7 @@ public abstract class GregtechMeta_SteamMultiBase getItemOutputSlots(ItemStack[] toOutput) { List ret = new ArrayList<>(); - for (final GT_MetaTileEntity_Hatch tBus : filterValidMetaTileEntities(mSteamOutputs)) { + for (final GT_MetaTileEntity_Hatch tBus : filterValidMTEs(mSteamOutputs)) { final IInventory tBusInv = tBus.getBaseMetaTileEntity(); for (int i = 0; i < tBusInv.getSizeInventory(); i++) { ret.add(tBus.getStackInSlot(i)); @@ -307,10 +298,8 @@ public abstract class GregtechMeta_SteamMultiBase