aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java
diff options
context:
space:
mode:
authorJakub <53441451+kuba6000@users.noreply.github.com>2022-08-29 16:04:28 +0200
committerGitHub <noreply@github.com>2022-08-29 16:04:28 +0200
commit7d1f51a8937e0a86486267437d444696e81e8aa0 (patch)
treea5b145e7271998f7b4b968a2212ed487e54a92b5 /src/main/java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java
parent5267969156d30b4bb5f4cb2279ebb49db6bd40e2 (diff)
downloadGT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.gz
GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.bz2
GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.zip
Buildscript + Spotless (#318)
* Convert AES.java to readable class * Buildscript * Spotless
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java')
-rw-r--r--src/main/java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java294
1 files changed, 144 insertions, 150 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java b/src/main/java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java
index f237aed335..b0b5b48d7d 100644
--- a/src/main/java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java
+++ b/src/main/java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java
@@ -1,169 +1,163 @@
package gtPlusPlus.xmod.galacticraft.util;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
import gregtech.api.enums.Materials;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.item.chemistry.RocketFuels;
import gtPlusPlus.core.util.minecraft.FluidUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import net.minecraft.entity.Entity;
import net.minecraftforge.fluids.FluidStack;
public class GalacticUtils {
- static final private Class<?> aTieredRocket;
- static final private Class<?> aLandingPad;
- static final private Class<?> aBuggyPad;
- static final private Class<?> aIDockable;
- static final private Class<?> aIFuelable;
- static final private Method getRocketTier;
- static final private Method getRocket;
- static final private Method getBuggy;
-
- static {
- Class<?> a1, a2, a3, a4, a5;
- Method m1, m2, m3;
- try {
- a1 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.api.prefab.entity.EntityTieredRocket");
- a2 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.tile.TileEntityLandingPad");
- a3 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.tile.TileEntityBuggyFueler");
- a4 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.api.entity.IDockable");
- a5 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.api.entity.IFuelable");
- m1 = ReflectionUtils.getMethod(a1, "getRocketTier");
- m2 = ReflectionUtils.getMethod(a2, "getDockedEntity");
- m3 = ReflectionUtils.getMethod(a3, "getDockedEntity");
- }
- catch (Throwable t) {
- a1 = null;
- a2 = null;
- a3 = null;
- a4 = null;
- a5 = null;
- m1 = null;
- m2 = null;
- m3 = null;
- }
- aTieredRocket = a1;
- aLandingPad = a2;
- aBuggyPad = a3;
- aIDockable = a4;
- aIFuelable = a5;
- getRocketTier = m1;
- getRocket = m2;
- getBuggy = m3;
- if (a1 != null && a2 != null && a3 != null && a4 != null && a5 != null && m1 != null && m2 != null && m3 != null) {
- Logger.SPACE("Successfully relfected into 5 classes and 3 methods.");
- }
- else {
- Logger.SPACE("Failed to relfect into Galacticraft classes and methods.");
- if (a1 == null) {
- Logger.SPACE("micdoodle8.mods.galacticraft.api.prefab.entity.EntityTieredRocket was null..");
- }
- if (a2 == null) {
- Logger.SPACE("micdoodle8.mods.galacticraft.core.tile.TileEntityLandingPad was null..");
- }
- if (a3 == null) {
- Logger.SPACE("micdoodle8.mods.galacticraft.core.tile.TileEntityBuggyFueler was null..");
- }
- if (a4 == null) {
- Logger.SPACE("micdoodle8.mods.galacticraft.api.entity.IDockable was null..");
- }
- if (a5 == null) {
- Logger.SPACE("micdoodle8.mods.galacticraft.api.entity.IFuelable was null..");
- }
- if (m1 == null) {
- Logger.SPACE("getRocketTier was null..");
- }
- if (m2 == null) {
- Logger.SPACE("getDockedEntity was null..");
- }
- if (m3 == null) {
- Logger.SPACE("getDockedEntity(buggy) was null..");
- }
- }
- }
-
-
- public static int getRocketTier(Entity aEntity) {
- if (aTieredRocket.isInstance(aEntity)) {
- if (getRocketTier != null) {
- try {
- return (int) getRocketTier.invoke(aEntity, new Object[] {});
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- }
- }
- }
- return -1;
- }
-
- public static int getRocketTier(Object aEntity) {
- if (aIFuelable.isInstance(aEntity)) {
- if (aLandingPad.isInstance(aEntity)) {
- Object rocket;
- try {
- rocket = getRocket.invoke(aLandingPad, new Object[] {});
- if (aIDockable.isInstance(rocket) && rocket != null) {
- return getRocketTier((Entity) rocket);
- }
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- }
- }
- else if (aBuggyPad.isInstance(aEntity)) {
- Object buggy;
- try {
- buggy = getBuggy.invoke(aBuggyPad, new Object[] {});
- if (aIDockable.isInstance(buggy) && buggy != null) {
- return 0;
- }
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- }
- }
- }
- return -1;
- }
-
- public static boolean isFuelValidForTier(int aTier, FluidStack aFuel) {
- FluidStack aValidForThisTier = getValidFuelForTier(aTier);
- if (aFuel.isFluidEqual(aValidForThisTier)) {
- return true;
- }
- return false;
- }
+ private static final Class<?> aTieredRocket;
+ private static final Class<?> aLandingPad;
+ private static final Class<?> aBuggyPad;
+ private static final Class<?> aIDockable;
+ private static final Class<?> aIFuelable;
+ private static final Method getRocketTier;
+ private static final Method getRocket;
+ private static final Method getBuggy;
+ static {
+ Class<?> a1, a2, a3, a4, a5;
+ Method m1, m2, m3;
+ try {
+ a1 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.api.prefab.entity.EntityTieredRocket");
+ a2 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.tile.TileEntityLandingPad");
+ a3 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.tile.TileEntityBuggyFueler");
+ a4 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.api.entity.IDockable");
+ a5 = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.api.entity.IFuelable");
+ m1 = ReflectionUtils.getMethod(a1, "getRocketTier");
+ m2 = ReflectionUtils.getMethod(a2, "getDockedEntity");
+ m3 = ReflectionUtils.getMethod(a3, "getDockedEntity");
+ } catch (Throwable t) {
+ a1 = null;
+ a2 = null;
+ a3 = null;
+ a4 = null;
+ a5 = null;
+ m1 = null;
+ m2 = null;
+ m3 = null;
+ }
+ aTieredRocket = a1;
+ aLandingPad = a2;
+ aBuggyPad = a3;
+ aIDockable = a4;
+ aIFuelable = a5;
+ getRocketTier = m1;
+ getRocket = m2;
+ getBuggy = m3;
+ if (a1 != null
+ && a2 != null
+ && a3 != null
+ && a4 != null
+ && a5 != null
+ && m1 != null
+ && m2 != null
+ && m3 != null) {
+ Logger.SPACE("Successfully relfected into 5 classes and 3 methods.");
+ } else {
+ Logger.SPACE("Failed to relfect into Galacticraft classes and methods.");
+ if (a1 == null) {
+ Logger.SPACE("micdoodle8.mods.galacticraft.api.prefab.entity.EntityTieredRocket was null..");
+ }
+ if (a2 == null) {
+ Logger.SPACE("micdoodle8.mods.galacticraft.core.tile.TileEntityLandingPad was null..");
+ }
+ if (a3 == null) {
+ Logger.SPACE("micdoodle8.mods.galacticraft.core.tile.TileEntityBuggyFueler was null..");
+ }
+ if (a4 == null) {
+ Logger.SPACE("micdoodle8.mods.galacticraft.api.entity.IDockable was null..");
+ }
+ if (a5 == null) {
+ Logger.SPACE("micdoodle8.mods.galacticraft.api.entity.IFuelable was null..");
+ }
+ if (m1 == null) {
+ Logger.SPACE("getRocketTier was null..");
+ }
+ if (m2 == null) {
+ Logger.SPACE("getDockedEntity was null..");
+ }
+ if (m3 == null) {
+ Logger.SPACE("getDockedEntity(buggy) was null..");
+ }
+ }
+ }
+ public static int getRocketTier(Entity aEntity) {
+ if (aTieredRocket.isInstance(aEntity)) {
+ if (getRocketTier != null) {
+ try {
+ return (int) getRocketTier.invoke(aEntity, new Object[] {});
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ }
+ }
+ }
+ return -1;
+ }
- public static FluidStack getValidFuelForTier(Entity aEntity) {
- if (aTieredRocket.isInstance(aEntity)) {
- return getValidFuelForTier(getRocketTier(aEntity));
- }
- else {
- Logger.SPACE("Failed to get valid rocket fuel for "+aEntity.getClass().getCanonicalName());
- return getValidFuelForTier(0);
- }
- }
+ public static int getRocketTier(Object aEntity) {
+ if (aIFuelable.isInstance(aEntity)) {
+ if (aLandingPad.isInstance(aEntity)) {
+ Object rocket;
+ try {
+ rocket = getRocket.invoke(aLandingPad, new Object[] {});
+ if (aIDockable.isInstance(rocket) && rocket != null) {
+ return getRocketTier((Entity) rocket);
+ }
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ }
+ } else if (aBuggyPad.isInstance(aEntity)) {
+ Object buggy;
+ try {
+ buggy = getBuggy.invoke(aBuggyPad, new Object[] {});
+ if (aIDockable.isInstance(buggy) && buggy != null) {
+ return 0;
+ }
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ }
+ }
+ }
+ return -1;
+ }
- public static FluidStack getValidFuelForTier(int aTier) {
- if (aTier > 0 && aTier <= 2) {
- return FluidUtils.getFluidStack(RocketFuels.RP1_Plus_Liquid_Oxygen, 1000);
- }
- else if (aTier >= 3 && aTier <= 5) {
- return FluidUtils.getFluidStack(RocketFuels.Dense_Hydrazine_Mix, 1000);
- }
- else if (aTier >= 6 && aTier <= 7) {
- return FluidUtils.getFluidStack(RocketFuels.Monomethylhydrazine_Plus_Nitric_Acid, 1000);
- }
- else if (aTier >= 8 && aTier <= 10) {
- return FluidUtils.getFluidStack(RocketFuels.Unsymmetrical_Dimethylhydrazine_Plus_Nitrogen_Tetroxide, 1000);
- }
- else {
- if (aTier == 0) {
- return Materials.Fuel.getFluid(1000);
- }
- return null;
- }
+ public static boolean isFuelValidForTier(int aTier, FluidStack aFuel) {
+ FluidStack aValidForThisTier = getValidFuelForTier(aTier);
+ if (aFuel.isFluidEqual(aValidForThisTier)) {
+ return true;
+ }
+ return false;
+ }
- }
+ public static FluidStack getValidFuelForTier(Entity aEntity) {
+ if (aTieredRocket.isInstance(aEntity)) {
+ return getValidFuelForTier(getRocketTier(aEntity));
+ } else {
+ Logger.SPACE(
+ "Failed to get valid rocket fuel for " + aEntity.getClass().getCanonicalName());
+ return getValidFuelForTier(0);
+ }
+ }
+ public static FluidStack getValidFuelForTier(int aTier) {
+ if (aTier > 0 && aTier <= 2) {
+ return FluidUtils.getFluidStack(RocketFuels.RP1_Plus_Liquid_Oxygen, 1000);
+ } else if (aTier >= 3 && aTier <= 5) {
+ return FluidUtils.getFluidStack(RocketFuels.Dense_Hydrazine_Mix, 1000);
+ } else if (aTier >= 6 && aTier <= 7) {
+ return FluidUtils.getFluidStack(RocketFuels.Monomethylhydrazine_Plus_Nitric_Acid, 1000);
+ } else if (aTier >= 8 && aTier <= 10) {
+ return FluidUtils.getFluidStack(RocketFuels.Unsymmetrical_Dimethylhydrazine_Plus_Nitrogen_Tetroxide, 1000);
+ } else {
+ if (aTier == 0) {
+ return Materials.Fuel.getFluid(1000);
+ }
+ return null;
+ }
+ }
}