diff options
author | Yang Xizhi <60341015+GlodBlock@users.noreply.github.com> | 2021-12-25 02:05:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-24 19:05:52 +0100 |
commit | 07745f72ffbd2ecd2724549093857851930f9137 (patch) | |
tree | bba7741ba05168d82fc426ddc04b861c43ecbb28 /src/main/java/gregtech/api/util | |
parent | 9b7d225b93fb15efc958786fb90c923b20d8752f (diff) | |
download | GT5-Unofficial-07745f72ffbd2ecd2724549093857851930f9137.tar.gz GT5-Unofficial-07745f72ffbd2ecd2724549093857851930f9137.tar.bz2 GT5-Unofficial-07745f72ffbd2ecd2724549093857851930f9137.zip |
tt support for pa (#833)
* tt support for pa
* remove anti pattern. clear up duplicated code fragments
* fix copy pasting error
* add vanilla energy hatch back
Co-authored-by: Glease <4586901+Glease@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_ExoticEnergyInputHelper.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/util/GT_ExoticEnergyInputHelper.java b/src/main/java/gregtech/api/util/GT_ExoticEnergyInputHelper.java new file mode 100644 index 0000000000..3de3d42f14 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_ExoticEnergyInputHelper.java @@ -0,0 +1,71 @@ +package gregtech.api.util; + +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity; + +public class GT_ExoticEnergyInputHelper { + /** + * The Valid Types of TecTech Hatch List. + */ + private static final List<Class<?>> sExoticEnergyHatchType = new ArrayList<>(); + + static { + tryRegister("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti"); + tryRegister("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyTunnel"); + } + + public static void register(Class<? extends GT_MetaTileEntity_Hatch> clazz) { + if (!GT_MetaTileEntity_Hatch.class.isAssignableFrom(clazz)) + throw new IllegalArgumentException(clazz.getName() + " is not a subclass of " + GT_MetaTileEntity_Hatch.class.getName()); + sExoticEnergyHatchType.add(clazz); + } + + public static void tryRegister(String className) { + Class<?> clazz; + try { + clazz = Class.forName(className); + } catch (ClassNotFoundException e) { + return; + } + if (!GT_MetaTileEntity_Hatch.class.isAssignableFrom(clazz)) + throw new IllegalArgumentException(clazz.getName() + " is not a subclass of " + GT_MetaTileEntity_Hatch.class.getName()); + sExoticEnergyHatchType.add(clazz); + } + + public static boolean drainEnergy(long aEU, Collection<? extends GT_MetaTileEntity_Hatch> hatches) { + for (GT_MetaTileEntity_Hatch tHatch : hatches) { + long tDrain = Math.min(tHatch.getBaseMetaTileEntity().getStoredEU(), aEU); + tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(tDrain, false); + aEU -= tDrain; + } + return aEU <= 0; + } + + public static boolean isExoticEnergyInput(IMetaTileEntity aHatch) { + for (Class<?> clazz : sExoticEnergyHatchType) { + if (clazz.isInstance(aHatch)) + return true; + } + return false; + } + + public static long getMaxInputVoltageMulti(Collection<? extends GT_MetaTileEntity_Hatch> hatches) { + long rVoltage = 0; + for (GT_MetaTileEntity_Hatch tHatch : hatches) + if (isValidMetaTileEntity(tHatch)) rVoltage += tHatch.getBaseMetaTileEntity().getInputVoltage(); + return rVoltage; + } + + public static long getMaxInputAmpsMulti(Collection<? extends GT_MetaTileEntity_Hatch> hatches) { + long rAmp = 0; + for (GT_MetaTileEntity_Hatch tHatch : hatches) + if (isValidMetaTileEntity(tHatch)) rAmp += tHatch.getBaseMetaTileEntity().getInputAmperage(); + return rAmp; + } +} |