diff options
author | miozune <miozune@gmail.com> | 2023-10-30 18:42:33 +0900 |
---|---|---|
committer | Martin Robertz <dream-master@gmx.net> | 2023-10-30 12:58:27 +0100 |
commit | 6612c5495e0d225550a8459ee2c9f8a2097bd66f (patch) | |
tree | fbe4e65ee4ad728014de1f957a704004cd51e474 /src/main | |
parent | 31d4cad2dbda1c39ae5c70fec205353da70b5b30 (diff) | |
download | GT5-Unofficial-6612c5495e0d225550a8459ee2c9f8a2097bd66f.tar.gz GT5-Unofficial-6612c5495e0d225550a8459ee2c9f8a2097bd66f.tar.bz2 GT5-Unofficial-6612c5495e0d225550a8459ee2c9f8a2097bd66f.zip |
Cleanup isValidMetaTileEntity
Diffstat (limited to 'src/main')
11 files changed, 140 insertions, 231 deletions
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<T extends GT_MetaTileEntity_Ex super(aName); } - public static boolean isValidMetaTileEntity(final MetaTileEntity aMetaTileEntity) { - return (aMetaTileEntity.getBaseMetaTileEntity() != null) - && (aMetaTileEntity.getBaseMetaTileEntity().getMetaTileEntity() == aMetaTileEntity) - && !aMetaTileEntity.getBaseMetaTileEntity().isDead(); - } - private static int toStackCount(Entry<ItemStack, Integer> e) { int tMaxStackSize = e.getKey().getMaxStackSize(); int tStackSize = e.getValue(); @@ -307,50 +302,40 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex public int getPollutionReductionForAllMufflers() { int mPollutionReduction = 0; - for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { - if (isValidMetaTileEntity(tHatch)) { - mPollutionReduction = Math.max(calculatePollutionReductionForHatch(tHatch, 100), mPollutionReduction); - } + for (GT_MetaTileEntity_Hatch_Muffler tHatch : filterValidMTEs(mMufflerHatches)) { + mPollutionReduction = Math.max(calculatePollutionReductionForHatch(tHatch, 100), mPollutionReduction); } return mPollutionReduction; } public long getStoredEnergyInAllEnergyHatches() { long storedEnergy = 0; - for (GT_MetaTileEntity_Hatch tHatch : mAllEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); - } + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(mAllEnergyHatches)) { + storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); } return storedEnergy; } public long getMaxEnergyStorageOfAllEnergyHatches() { long maxEnergy = 0; - for (GT_MetaTileEntity_Hatch tHatch : mAllEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); - } + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(mAllEnergyHatches)) { + maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); } return maxEnergy; } public long getStoredEnergyInAllDynamoHatches() { long storedEnergy = 0; - for (GT_MetaTileEntity_Hatch tHatch : mAllDynamoHatches) { - if (isValidMetaTileEntity(tHatch)) { - storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); - } + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(mAllDynamoHatches)) { + storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); } return storedEnergy; } public long getMaxEnergyStorageOfAllDynamoHatches() { long maxEnergy = 0; - for (GT_MetaTileEntity_Hatch tHatch : mAllDynamoHatches) { - if (isValidMetaTileEntity(tHatch)) { - maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); - } + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(mAllDynamoHatches)) { + maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); } return maxEnergy; } @@ -415,8 +400,8 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex if (mEnergyHatches.size() == 1) // so it only takes 1 amp is only 1 hatch is present so it works like most gt // multies return mEnergyHatches.get(0).getBaseMetaTileEntity().getInputVoltage(); - for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) - if (isValidMetaTileEntity(tHatch)) rEnergy += tHatch.getBaseMetaTileEntity().getInputVoltage() + for (GT_MetaTileEntity_Hatch_Energy tHatch : filterValidMTEs(mEnergyHatches)) + rEnergy += tHatch.getBaseMetaTileEntity().getInputVoltage() * tHatch.getBaseMetaTileEntity().getInputAmperage(); return rEnergy; } @@ -522,17 +507,15 @@ public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_Ex */ protected boolean depleteInputFromRestrictedHatches(Collection<GT_MetaTileEntity_Hatch_CustomFluidBase> 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<T extends GT_MetaTileEntity_Ex @Override public void updateSlots() { - for (final GT_MetaTileEntity_Hatch_InputBattery tHatch : this.mChargeHatches) { - if (isValidMetaTileEntity(tHatch)) { - tHatch.updateSlots(); - } + for (final GT_MetaTileEntity_Hatch_InputBattery tHatch : filterValidMTEs(this.mChargeHatches)) { + tHatch.updateSlots(); } - for (final GT_MetaTileEntity_Hatch_OutputBattery tHatch : this.mDischargeHatches) { - if (isValidMetaTileEntity(tHatch)) { - tHatch.updateSlots(); - } + for (final GT_MetaTileEntity_Hatch_OutputBattery tHatch : filterValidMTEs(this.mDischargeHatches)) { + tHatch.updateSlots(); } super.updateSlots(); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java index d4db6b1350..13b879dd00 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java @@ -2,6 +2,7 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; import static gregtech.api.enums.GT_Values.V; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; import java.util.ArrayList; import java.util.Collections; @@ -183,15 +184,13 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu @Override public boolean depleteInput(FluidStack aLiquid) { if (aLiquid == null) return false; - for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mSteamInputFluids) { - if (isValidMetaTileEntity(tHatch)) { - 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; - } + 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<T extends GregtechMeta_SteamMu if (GT_Utility.isStackInvalid(aStack)) return false; FluidStack aLiquid = GT_Utility.getFluidForFilledItem(aStack, true); if (aLiquid != null) return depleteInput(aLiquid); - for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mSteamInputFluids) { - if (isValidMetaTileEntity(tHatch)) { - 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_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<T extends GregtechMeta_SteamMu @Override public ArrayList<FluidStack> getStoredFluids() { ArrayList<FluidStack> 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<T extends GregtechMeta_SteamMu @Override public ArrayList<ItemStack> getStoredInputs() { ArrayList<ItemStack> 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<T extends GregtechMeta_SteamMu while (outputSuccess && aStack.stackSize > 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<T extends GregtechMeta_SteamMu @Override public ArrayList<ItemStack> getStoredOutputs() { ArrayList<ItemStack> 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<T extends GregtechMeta_SteamMu @Override public List<ItemStack> getItemOutputSlots(ItemStack[] toOutput) { List<ItemStack> 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<T extends GregtechMeta_SteamMu @Override public void updateSlots() { - for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mSteamInputFluids) - if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); - for (GT_MetaTileEntity_Hatch_Steam_BusInput tHatch : mSteamInputs) - if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mSteamInputFluids)) tHatch.updateSlots(); + for (GT_MetaTileEntity_Hatch_Steam_BusInput tHatch : filterValidMTEs(mSteamInputs)) tHatch.updateSlots(); } @Override diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java index da6dcc4b28..b8d5ebdf8b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java @@ -12,6 +12,7 @@ import static gregtech.api.enums.GT_HatchElement.Muffler; import static gregtech.api.enums.GT_HatchElement.OutputBus; import static gregtech.api.enums.GT_HatchElement.OutputHatch; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; import java.util.ArrayList; @@ -157,8 +158,7 @@ public class GregtechMetaTileEntity_IndustrialVacuumFreezer extends @Override public void updateSlots() { - for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mCryotheumHatches) - if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mCryotheumHatches)) tHatch.updateSlots(); super.updateSlots(); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java index 23889df16e..f8f8a28ccc 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java @@ -12,6 +12,7 @@ import static gregtech.api.enums.GT_HatchElement.Muffler; import static gregtech.api.enums.GT_HatchElement.OutputBus; import static gregtech.api.enums.GT_HatchElement.OutputHatch; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; import java.util.ArrayList; import java.util.HashSet; @@ -428,11 +429,9 @@ public class GregtechMetaTileEntity_IsaMill extends GregtechMeta_MultiBlockBase< @Override public ArrayList<ItemStack> getStoredInputs() { ArrayList<ItemStack> tItems = super.getStoredInputs(); - for (GT_MetaTileEntity_Hatch_MillingBalls tHatch : mMillingBallBuses) { + for (GT_MetaTileEntity_Hatch_MillingBalls tHatch : filterValidMTEs(mMillingBallBuses)) { tHatch.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - tItems.addAll(tHatch.getContentUsageSlots()); - } + tItems.addAll(tHatch.getContentUsageSlots()); } return tItems; } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java index a17b1c70c1..f951927434 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java @@ -13,6 +13,7 @@ import static gregtech.api.enums.GT_HatchElement.OutputBus; import static gregtech.api.enums.GT_HatchElement.OutputHatch; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gregtech.api.util.GT_Utility.filterValidMTEs; import java.util.ArrayList; @@ -23,7 +24,6 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.NotNull; @@ -179,28 +179,10 @@ public class GregtechMetaTileEntity_Adv_EBF extends GregtechMeta_MultiBlockBase< @Override public void updateSlots() { - for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mPyrotheumHatches) - if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mPyrotheumHatches)) tHatch.updateSlots(); super.updateSlots(); } - private boolean depleteFuel(int aAmount) { - for (final GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : this.mPyrotheumHatches) { - 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; - } - } - } - return false; - } - @Override protected IIconContainer getActiveOverlay() { return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java index 2f0bcc2c4f..4063c967d7 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java @@ -11,6 +11,7 @@ import static gregtech.api.enums.GT_HatchElement.Muffler; import static gregtech.api.enums.GT_HatchElement.OutputBus; import static gregtech.api.enums.GT_HatchElement.OutputHatch; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; import java.util.ArrayList; import java.util.Collection; @@ -376,11 +377,9 @@ public class GregtechMTE_ElementalDuplicator extends GregtechMeta_MultiBlockBase @Override public ArrayList<ItemStack> getStoredInputs() { ArrayList<ItemStack> tItems = super.getStoredInputs(); - for (GT_MetaTileEntity_Hatch_ElementalDataOrbHolder tHatch : mReplicatorDataOrbHatches) { + for (GT_MetaTileEntity_Hatch_ElementalDataOrbHolder tHatch : filterValidMTEs(mReplicatorDataOrbHatches)) { tHatch.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - tItems.add(tHatch.getOrbByCircuit()); - } + tItems.add(tHatch.getOrbByCircuit()); } tItems.removeAll(Collections.singleton(null)); return tItems; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java index 74a51a0260..143fedb5a5 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java @@ -9,6 +9,7 @@ import static gregtech.api.enums.GT_HatchElement.InputHatch; import static gregtech.api.enums.GT_HatchElement.Maintenance; import static gregtech.api.enums.GT_HatchElement.Muffler; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.AirIntake; import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; @@ -384,31 +385,18 @@ public class GregtechMetaTileEntity_LargeRocketEngine extends long totalOutput = 0; long aFirstVoltageFound = -1; boolean aFoundMixedDynamos = false; - for (GT_MetaTileEntity_Hatch aDynamo : this.mAllDynamoHatches) { - if (aDynamo == null) { - return false; - } - if (isValidMetaTileEntity(aDynamo)) { - long aVoltage = aDynamo.maxEUOutput(); - long aTotal = aDynamo.maxAmperesOut() * aVoltage; - // Check against voltage to check when hatch mixing - if (aFirstVoltageFound == -1) { - aFirstVoltageFound = aVoltage; - } else { - /** - * Calcualtes overclocked ness using long integers - * - * @param aEUt - recipe EUt - * @param aDuration - recipe Duration - * @param mAmperage - should be 1 ? - */ - // Long time calculation - if (aFirstVoltageFound != aVoltage) { - aFoundMixedDynamos = true; - } + for (GT_MetaTileEntity_Hatch aDynamo : filterValidMTEs(this.mAllDynamoHatches)) { + long aVoltage = aDynamo.maxEUOutput(); + long aTotal = aDynamo.maxAmperesOut() * aVoltage; + // Check against voltage to check when hatch mixing + if (aFirstVoltageFound == -1) { + aFirstVoltageFound = aVoltage; + } else { + if (aFirstVoltageFound != aVoltage) { + aFoundMixedDynamos = true; } - totalOutput += aTotal; } + totalOutput += aTotal; } if (totalOutput < aEU || (aFoundMixedDynamos && !aAllowMixedVoltageDynamos)) { @@ -417,29 +405,24 @@ public class GregtechMetaTileEntity_LargeRocketEngine extends } long leftToInject; - // Long EUt calculation long aVoltage; - // Isnt too low EUt check? int aAmpsToInject; int aRemainder; - // xEUt *= 4;//this is effect of everclocking - for (GT_MetaTileEntity_Hatch aDynamo : this.mAllDynamoHatches) { - if (isValidMetaTileEntity(aDynamo)) { - leftToInject = aEU - injected; - aVoltage = aDynamo.maxEUOutput(); - aAmpsToInject = (int) (leftToInject / aVoltage); - aRemainder = (int) (leftToInject - (aAmpsToInject * aVoltage)); - long powerGain; - for (int i = 0; i < Math.min(aDynamo.maxAmperesOut(), aAmpsToInject + 1); i++) { - if (i == Math.min(aDynamo.maxAmperesOut(), aAmpsToInject)) { - powerGain = aRemainder; - } else { - powerGain = aVoltage; - } - aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(powerGain, false); - injected += powerGain; + for (GT_MetaTileEntity_Hatch aDynamo : filterValidMTEs(this.mAllDynamoHatches)) { + leftToInject = aEU - injected; + aVoltage = aDynamo.maxEUOutput(); + aAmpsToInject = (int) (leftToInject / aVoltage); + aRemainder = (int) (leftToInject - (aAmpsToInject * aVoltage)); + long powerGain; + for (int i = 0; i < Math.min(aDynamo.maxAmperesOut(), aAmpsToInject + 1); i++) { + if (i == Math.min(aDynamo.maxAmperesOut(), aAmpsToInject)) { + powerGain = aRemainder; + } else { + powerGain = aVoltage; } + aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(powerGain, false); + injected += powerGain; } } return injected > 0; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java index d06566213a..01454f5b91 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java @@ -11,6 +11,7 @@ import static gregtech.api.enums.GT_HatchElement.OutputHatch; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import static gregtech.api.util.GT_StructureUtility.filterByMTETier; import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gregtech.api.util.GT_Utility.filterValidMTEs; import java.util.ArrayList; import java.util.HashMap; @@ -688,13 +689,11 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase<Gregt if (this.getControllerSlot() != null) { tItems.add(this.getControllerSlot()); } - for (GT_MetaTileEntity_Hatch_Catalysts tHatch : mCatalystBuses) { + for (GT_MetaTileEntity_Hatch_Catalysts tHatch : filterValidMTEs(mCatalystBuses)) { tHatch.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - AutoMap<ItemStack> aHatchContent = tHatch.getContentUsageSlots(); - if (!aHatchContent.isEmpty()) { - tItems.addAll(aHatchContent); - } + AutoMap<ItemStack> aHatchContent = tHatch.getContentUsageSlots(); + if (!aHatchContent.isEmpty()) { + tItems.addAll(aHatchContent); } } return tItems; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/mega/GregTechMetaTileEntity_MegaAlloyBlastSmelter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/mega/GregTechMetaTileEntity_MegaAlloyBlastSmelter.java index edf3adf40b..e327e2111e 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/mega/GregTechMetaTileEntity_MegaAlloyBlastSmelter.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/mega/GregTechMetaTileEntity_MegaAlloyBlastSmelter.java @@ -14,6 +14,7 @@ import static gregtech.api.enums.GT_HatchElement.OutputBus; import static gregtech.api.enums.GT_HatchElement.OutputHatch; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gregtech.api.util.GT_Utility.filterValidMTEs; import java.util.ArrayList; import java.util.List; @@ -313,11 +314,9 @@ public class GregTechMetaTileEntity_MegaAlloyBlastSmelter int paras = getBaseMetaTileEntity().isActive() ? processingLogic.getCurrentParallels() : 0; int discountP = (int) (getCoilDiscount(coilLevel) * 1000) / 10; - for (GT_MetaTileEntity_Hatch tHatch : mExoticEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); - maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); - } + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(mExoticEnergyHatches)) { + storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); + maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); } return new String[] { "------------ Critical Information ------------", diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java index fce6ec4408..389e267545 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java @@ -9,6 +9,7 @@ import static gregtech.api.enums.GT_HatchElement.Maintenance; import static gregtech.api.enums.GT_HatchElement.Muffler; import static gregtech.api.enums.GT_HatchElement.OutputHatch; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; import java.util.ArrayList; @@ -196,10 +197,8 @@ public abstract class GregtechMetaTileEntity_LargerTurbineBase extends public final double getMufflerReduction() { double totalReduction = 0; - for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { - if (isValidMetaTileEntity(tHatch)) { - totalReduction += ((double) tHatch.calculatePollutionReduction(100)) / 100; - } + for (GT_MetaTileEntity_Hatch_Muffler tHatch : filterValidMTEs(mMufflerHatches)) { + totalReduction += ((double) tHatch.calculatePollutionReduction(100)) / 100; } return totalReduction / 4; } @@ -610,11 +609,9 @@ public abstract class GregtechMetaTileEntity_LargerTurbineBase extends long storedEnergy = 0; long maxEnergy = 0; - for (GT_MetaTileEntity_Hatch_Dynamo tHatch : mDynamoHatches) { - if (isValidMetaTileEntity(tHatch)) { - storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); - maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); - } + for (GT_MetaTileEntity_Hatch_Dynamo tHatch : filterValidMTEs(mDynamoHatches)) { + storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); + maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); } boolean aIsSteam = this.getClass().getName().toLowerCase().contains("steam"); @@ -679,15 +676,13 @@ public abstract class GregtechMetaTileEntity_LargerTurbineBase extends public boolean polluteEnvironment(int aPollutionLevel) { if (this.requiresMufflers()) { mPollution += aPollutionLevel * getPollutionMultiplier() * mufflerReduction; - for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { - if (isValidMetaTileEntity(tHatch)) { - if (mPollution >= 10000) { - if (PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10000)) { - mPollution -= 10000; - } - } else { - break; + for (GT_MetaTileEntity_Hatch_Muffler tHatch : filterValidMTEs(mMufflerHatches)) { + if (mPollution >= 10000) { + if (PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10000)) { + mPollution -= 10000; } + } else { + break; } } return mPollution < 10000; @@ -793,8 +788,7 @@ public abstract class GregtechMetaTileEntity_LargerTurbineBase extends if (this.mTurbineRotorHatches.isEmpty() || ((System.currentTimeMillis() / 1000) - mLastHatchUpdate) <= 2) { return; } - for (GT_MetaTileEntity_Hatch_Turbine h : this.mTurbineRotorHatches) { - if (!isValidMetaTileEntity(h)) continue; + for (GT_MetaTileEntity_Hatch_Turbine h : filterValidMTEs(this.mTurbineRotorHatches)) { h.setActive(aState); } @@ -833,16 +827,11 @@ public abstract class GregtechMetaTileEntity_LargerTurbineBase extends public boolean addEnergyOutputMultipleDynamos(long aEU, boolean aAllowMixedVoltageDynamos) { int injected = 0; long aFirstVoltageFound = -1; - for (GT_MetaTileEntity_Hatch aDynamo : mAllDynamoHatches) { - if (aDynamo == null) { - return false; - } - if (isValidMetaTileEntity(aDynamo)) { - long aVoltage = aDynamo.maxEUOutput(); - // Check against voltage to check when hatch mixing - if (aFirstVoltageFound == -1) { - aFirstVoltageFound = aVoltage; - } + for (GT_MetaTileEntity_Hatch aDynamo : filterValidMTEs(mAllDynamoHatches)) { + long aVoltage = aDynamo.maxEUOutput(); + // Check against voltage to check when hatch mixing + if (aFirstVoltageFound == -1) { + aFirstVoltageFound = aVoltage; } } @@ -851,21 +840,19 @@ public abstract class GregtechMetaTileEntity_LargerTurbineBase extends int aAmpsToInject; int aRemainder; int ampsOnCurrentHatch; - for (GT_MetaTileEntity_Hatch aDynamo : mAllDynamoHatches) { - if (isValidMetaTileEntity(aDynamo)) { - leftToInject = aEU - injected; - aVoltage = aDynamo.maxEUOutput(); - aAmpsToInject = (int) (leftToInject / aVoltage); - aRemainder = (int) (leftToInject - (aAmpsToInject * aVoltage)); - ampsOnCurrentHatch = (int) Math.min(aDynamo.maxAmperesOut(), aAmpsToInject); - for (int i = 0; i < ampsOnCurrentHatch; i++) { - aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(aVoltage, false); - } - injected += aVoltage * ampsOnCurrentHatch; - if (aRemainder > 0 && ampsOnCurrentHatch < aDynamo.maxAmperesOut()) { - aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(aRemainder, false); - injected += aRemainder; - } + for (GT_MetaTileEntity_Hatch aDynamo : filterValidMTEs(mAllDynamoHatches)) { + leftToInject = aEU - injected; + aVoltage = aDynamo.maxEUOutput(); + aAmpsToInject = (int) (leftToInject / aVoltage); + aRemainder = (int) (leftToInject - (aAmpsToInject * aVoltage)); + ampsOnCurrentHatch = (int) Math.min(aDynamo.maxAmperesOut(), aAmpsToInject); + for (int i = 0; i < ampsOnCurrentHatch; i++) { + aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(aVoltage, false); + } + injected += aVoltage * ampsOnCurrentHatch; + if (aRemainder > 0 && ampsOnCurrentHatch < aDynamo.maxAmperesOut()) { + aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(aRemainder, false); + injected += aRemainder; } } return injected > 0; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java index 8e7f2b97ed..175d2be7a2 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java @@ -12,6 +12,7 @@ import static gregtech.api.enums.GT_HatchElement.Maintenance; import static gregtech.api.enums.Mods.TecTech; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; +import static gregtech.api.util.GT_Utility.filterValidMTEs; import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTEnergy; @@ -569,10 +570,6 @@ public class GregtechMetaTileEntity_PowerSubStationController } private long drawEnergyFromHatch(MetaTileEntity aHatch) { - if (!isValidMetaTileEntity(aHatch)) { - return 0; - } - long stored = aHatch.getEUVar(); long voltage = aHatch.maxEUInput() * aHatch.maxAmperesIn(); @@ -589,10 +586,6 @@ public class GregtechMetaTileEntity_PowerSubStationController } private long addEnergyToHatch(MetaTileEntity aHatch) { - if (!isValidMetaTileEntity(aHatch)) { - return 0; - } - long voltage = aHatch.maxEUOutput() * aHatch.maxAmperesOut(); if (aHatch.getEUVar() > aHatch.maxEUStore() - voltage) { @@ -638,18 +631,18 @@ public class GregtechMetaTileEntity_PowerSubStationController long aInputAverage = 0; long aOutputAverage = 0; // Input Power - for (GT_MetaTileEntity_Hatch THatch : this.mDischargeHatches) { + for (GT_MetaTileEntity_Hatch THatch : filterValidMTEs(this.mDischargeHatches)) { aInputAverage += drawEnergyFromHatch(THatch); } - for (GT_MetaTileEntity_Hatch tHatch : this.mAllEnergyHatches) { + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(this.mAllEnergyHatches)) { aInputAverage += drawEnergyFromHatch(tHatch); } // Output Power - for (GT_MetaTileEntity_Hatch THatch : this.mChargeHatches) { + for (GT_MetaTileEntity_Hatch THatch : filterValidMTEs(this.mChargeHatches)) { aOutputAverage += addEnergyToHatch(THatch); } - for (GT_MetaTileEntity_Hatch tHatch : this.mAllDynamoHatches) { + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(this.mAllDynamoHatches)) { aOutputAverage += addEnergyToHatch(tHatch); } // reset progress time |