aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity
diff options
context:
space:
mode:
authormiozune <miozune@gmail.com>2023-10-30 18:42:33 +0900
committerMartin Robertz <dream-master@gmx.net>2023-10-30 12:58:27 +0100
commit6612c5495e0d225550a8459ee2c9f8a2097bd66f (patch)
treefbe4e65ee4ad728014de1f957a704004cd51e474 /src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity
parent31d4cad2dbda1c39ae5c70fec205353da70b5b30 (diff)
downloadGT5-Unofficial-6612c5495e0d225550a8459ee2c9f8a2097bd66f.tar.gz
GT5-Unofficial-6612c5495e0d225550a8459ee2c9f8a2097bd66f.tar.bz2
GT5-Unofficial-6612c5495e0d225550a8459ee2c9f8a2097bd66f.zip
Cleanup isValidMetaTileEntity
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity')
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java73
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java81
2 files changed, 61 insertions, 93 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