aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus
diff options
context:
space:
mode:
authorJordan Byrne <draknyte1@hotmail.com>2017-12-08 08:51:36 +1000
committerJordan Byrne <draknyte1@hotmail.com>2017-12-08 08:51:36 +1000
commit4f57b824fa40ac0628bf0f7fe9215bdd06cc0c52 (patch)
tree0e9c53999d0623df1dfecf15c9cd66bb3347b129 /src/Java/gtPlusPlus
parent7440302502c7c813b1e081d5a51610686d554abd (diff)
downloadGT5-Unofficial-4f57b824fa40ac0628bf0f7fe9215bdd06cc0c52.tar.gz
GT5-Unofficial-4f57b824fa40ac0628bf0f7fe9215bdd06cc0c52.tar.bz2
GT5-Unofficial-4f57b824fa40ac0628bf0f7fe9215bdd06cc0c52.zip
+ Added better ways to get GT Version.
Diffstat (limited to 'src/Java/gtPlusPlus')
-rw-r--r--src/Java/gtPlusPlus/core/util/Utils.java57
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechNitroDieselFix.java248
2 files changed, 172 insertions, 133 deletions
diff --git a/src/Java/gtPlusPlus/core/util/Utils.java b/src/Java/gtPlusPlus/core/util/Utils.java
index 9ef411fcc5..0fd90953ff 100644
--- a/src/Java/gtPlusPlus/core/util/Utils.java
+++ b/src/Java/gtPlusPlus/core/util/Utils.java
@@ -3,6 +3,7 @@ package gtPlusPlus.core.util;
import java.awt.Color;
import java.awt.Graphics;
import java.io.File;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
@@ -19,6 +20,7 @@ import org.apache.logging.log4j.Logger;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
+import gregtech.GT_Mod;
import gregtech.api.enums.Materials;
import gregtech.api.enums.TC_Aspects;
import gregtech.api.enums.TC_Aspects.TC_AspectStack;
@@ -30,10 +32,12 @@ import gtPlusPlus.core.item.ModItems;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.material.Material;
import gtPlusPlus.core.proxy.ClientProxy;
+import gtPlusPlus.core.util.array.Pair;
import gtPlusPlus.core.util.fluid.FluidUtils;
import gtPlusPlus.core.util.item.ItemUtils;
import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.nbt.NBTUtils;
+import gtPlusPlus.core.util.reflect.ReflectionUtils;
import ic2.core.Ic2Items;
import ic2.core.init.InternalName;
import ic2.core.item.resources.ItemCell;
@@ -231,7 +235,7 @@ public class Utils {
public static void LOG_ASM(final String s) {
FMLRelaunchLog.info("", s);
}
-
+
//Register an event to both busses.
public static void registerEvent(Object o){
MinecraftForge.EVENT_BUS.register(o);
@@ -808,4 +812,55 @@ public class Utils {
return GT_Utility.copy(new Object[] { rStack });
}
+ @SuppressWarnings({ "unused", "unchecked" })
+ public static Pair<Integer, Integer> getGregtechVersion(){
+ Pair<Integer, Integer> version;
+ if (GT_Mod.VERSION == 509){
+ Class<GT_Mod> clazz;
+ try {
+ clazz = (Class<GT_Mod>) Class.forName("gregtech.GT_Mod");
+ Field mSubversion = ReflectionUtils.getField(clazz, "SUBVERSION");
+ if (mSubversion != null){
+ int mSub = 0;
+ mSub = mSubversion.getInt(clazz);
+ if (mSub != 0){
+ version = new Pair<Integer, Integer>(9, mSub);
+ return version;
+ }
+ }
+ }
+ catch (Throwable t){}
+ }
+ //5.08.33
+ else if (GT_Mod.VERSION == 508){
+ version = new Pair<Integer, Integer>(8, 33);
+ return version;
+
+ }
+ //5.07.07
+ else if (GT_Mod.VERSION == 507){
+ version = new Pair<Integer, Integer>(7, 7);
+ return version;
+
+ }
+ //Returb Bad Value
+ version = new Pair<Integer, Integer>(0, 0);
+ return version;
+ }
+
+ public static int getGregtechVersionAsInt(){
+ Pair<Integer, Integer> ver = getGregtechVersion();
+ return 50000+(ver.getKey()*100)+(ver.getValue());
+ }
+
+ public static String getGregtechVersionAsString(){
+ Pair<Integer, Integer> ver = getGregtechVersion();
+ return "5."+ver.getKey()+"."+ver.getValue();
+ }
+
+ public static int getGregtechSubVersion(){
+ Pair<Integer, Integer> ver = getGregtechVersion();
+ return ver.getValue();
+ }
+
}
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechNitroDieselFix.java b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechNitroDieselFix.java
index 1c40e98e4e..d70149ff99 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechNitroDieselFix.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechNitroDieselFix.java
@@ -29,145 +29,129 @@ public class GregtechNitroDieselFix {
public static void run(){
if (CORE.configSwitches.enableNitroFix){
Utils.LOG_INFO("Gregtech5u Content | Attempting to Fix Nitro-Diesel production.");
+ try {
+ int mSub = Utils.getGregtechSubVersion();
+ if (mSub != 0){
+ if (mSub >= 30){
+ Class mb = Class.forName("gregtech.api.enums.MaterialBuilder");
+ Object df = mb.getConstructor(int.class, TextureSet.class, String.class).newInstance(975, TextureSet.SET_FLUID, "Nitro-Diesel [Old]");
+ if (mb.isInstance(df)){
- if (GT_Mod.VERSION == 509){
- Utils.LOG_INFO("[Nitro] Found GT 5.09.");
- Class<GT_Mod> clazz;
- try {
- clazz = (Class<GT_Mod>) Class.forName("gregtech.GT_Mod");
- Field mSubversion = ReflectionUtils.getField(clazz, "SUBVERSION");
- Utils.LOG_INFO("[Nitro] Reflected into GT_Mod.class");
- if (mSubversion != null){
- Utils.LOG_INFO("[Nitro] Sub Version field is not null.");
- int mSub = 0;
- mSub = mSubversion.getInt(clazz);
- if (mSub != 0){
- Utils.LOG_INFO("[Nitro] Sub Version is greater than 0.");
- if (mSub >= 30){
- Utils.LOG_INFO("[Nitro] Sub version is at least 30.");
- Class mb = Class.forName("gregtech.api.enums.MaterialBuilder");
- Object df = mb.getConstructor(int.class, TextureSet.class, String.class).newInstance(975, TextureSet.SET_FLUID, "Nitro-Diesel [Old]");
- if (mb.isInstance(df)){
-
- Utils.LOG_INFO("[Nitro] Created new instance of Material builder, for Nitro fix.");
-
- //Get Methods
- Method addFluid = mb.getDeclaredMethod("addFluid");
- Method addCell = mb.getDeclaredMethod("addCell");
- Method setColour = mb.getDeclaredMethod("setColor", Dyes.class);
- Method setFuelPower = mb.getDeclaredMethod("setFuelPower", int.class);
- Method setMaterials = mb.getDeclaredMethod("setMaterialList", List.class);
- Method setTemp = mb.getDeclaredMethod("setLiquidTemperature", int.class);
- Method setRGB = mb.getDeclaredMethod("setRGB", int.class, int.class, int.class);
- Method construct = mb.getDeclaredMethod("constructMaterial");
- Utils.LOG_INFO("[Nitro] Got internal methods for setting fields.");
-
- //Invoke the methods
- addFluid.invoke(df);
- addCell.invoke(df);
- setColour.invoke(df, Dyes.dyeLime);
- setFuelPower.invoke(df, 512000);
- setMaterials.invoke(df, Arrays.asList(new MaterialStack(Materials.Glyceryl, 1), new MaterialStack(Materials.Fuel, 4)));
- setTemp.invoke(df, 295);
- setRGB.invoke(df, 200, 255, 0);
- Materials mNitroFix = (Materials) construct.invoke(df);
- Utils.LOG_INFO("[Nitro] Invoked 8 method calls successfully.");
-
- GT_Mod.gregtechproxy.addFluid("NitroFuel_Old", "Nitro Diesel [Old]", mNitroFix, 1, 295, GT_OreDictUnificator.get(OrePrefixes.cell, mNitroFix, 1L), ItemList.Cell_Empty.get(1L, new Object[0]), 1000);
- Utils.LOG_INFO("[Nitro] Added a fluid.");
-
-
- /**
- * Do Recipe Stuff
- */
-
- //Set up some Variables
- final Collection<GT_Recipe> xSingle = GT_Recipe.GT_Recipe_Map.sChemicalRecipes.mRecipeList;
- final Collection<GT_Recipe> xMulti = GT_Recipe.GT_Recipe_Map.sMultiblockChemicalRecipes.mRecipeList;
- final FluidStack mNitroStack = Materials.NitroFuel.getFluid(1000);
- GT_Recipe toRemoveSingle[] = new GT_Recipe[99];
- GT_Recipe toRemoveMulti[] = new GT_Recipe[99];
- int mIndexSingle = 0;
- int mIndexMulti = 0;
-
- //Iterate Single Block recipes for Nitro production.
- for (GT_Recipe rnd : xSingle){
- for (FluidStack mOutputFluid : rnd.mFluidOutputs){
- if (mOutputFluid.isFluidEqual(mNitroStack)){
- toRemoveSingle[mIndexSingle++] = rnd;
- }
- }
- }
- Utils.LOG_INFO("[Nitro] Found "+mIndexSingle+" single block Chemical Reactor recipes to remove.");
-
- //Iterate Multi Block recipes for Nitro production.
- for (GT_Recipe rnd : xMulti){
- for (FluidStack mOutputFluid : rnd.mFluidOutputs){
- if (mOutputFluid.isFluidEqual(mNitroStack)){
- toRemoveMulti[mIndexMulti++] = rnd;
- }
- }
+ Utils.LOG_INFO("[Nitro] Created new instance of Material builder, for Nitro fix.");
+
+ //Get Methods
+ Method addFluid = mb.getDeclaredMethod("addFluid");
+ Method addCell = mb.getDeclaredMethod("addCell");
+ Method setColour = mb.getDeclaredMethod("setColor", Dyes.class);
+ Method setFuelPower = mb.getDeclaredMethod("setFuelPower", int.class);
+ Method setMaterials = mb.getDeclaredMethod("setMaterialList", List.class);
+ Method setTemp = mb.getDeclaredMethod("setLiquidTemperature", int.class);
+ Method setRGB = mb.getDeclaredMethod("setRGB", int.class, int.class, int.class);
+ Method construct = mb.getDeclaredMethod("constructMaterial");
+ Utils.LOG_INFO("[Nitro] Got internal methods for setting fields.");
+
+ //Invoke the methods
+ addFluid.invoke(df);
+ addCell.invoke(df);
+ setColour.invoke(df, Dyes.dyeLime);
+ setFuelPower.invoke(df, 512000);
+ setMaterials.invoke(df, Arrays.asList(new MaterialStack(Materials.Glyceryl, 1), new MaterialStack(Materials.Fuel, 4)));
+ setTemp.invoke(df, 295);
+ setRGB.invoke(df, 200, 255, 0);
+ Materials mNitroFix = (Materials) construct.invoke(df);
+ Utils.LOG_INFO("[Nitro] Invoked 8 method calls successfully.");
+
+ GT_Mod.gregtechproxy.addFluid("NitroFuel_Old", "Nitro Diesel [Old]", mNitroFix, 1, 295, GT_OreDictUnificator.get(OrePrefixes.cell, mNitroFix, 1L), ItemList.Cell_Empty.get(1L, new Object[0]), 1000);
+ Utils.LOG_INFO("[Nitro] Added a fluid.");
+
+
+ /**
+ * Do Recipe Stuff
+ */
+
+ //Set up some Variables
+ final Collection<GT_Recipe> xSingle = GT_Recipe.GT_Recipe_Map.sChemicalRecipes.mRecipeList;
+ final Collection<GT_Recipe> xMulti = GT_Recipe.GT_Recipe_Map.sMultiblockChemicalRecipes.mRecipeList;
+ final FluidStack mNitroStack = Materials.NitroFuel.getFluid(1000);
+ GT_Recipe toRemoveSingle[] = new GT_Recipe[99];
+ GT_Recipe toRemoveMulti[] = new GT_Recipe[99];
+ int mIndexSingle = 0;
+ int mIndexMulti = 0;
+
+ //Iterate Single Block recipes for Nitro production.
+ for (GT_Recipe rnd : xSingle){
+ for (FluidStack mOutputFluid : rnd.mFluidOutputs){
+ if (mOutputFluid.isFluidEqual(mNitroStack)){
+ toRemoveSingle[mIndexSingle++] = rnd;
}
- Utils.LOG_INFO("[Nitro] Found "+mIndexMulti+" multi block Chemical Reactor recipes to remove.");
-
- //Remove Single Block recipes found.
- int mRemovedSingle = 0;
- int mRemovedMulti = 0;
- for (GT_Recipe single : toRemoveSingle){
- if (GT_Recipe.GT_Recipe_Map.sChemicalRecipes.mRecipeList.remove(single)){
- mRemovedSingle++;
- }
- }
- Utils.LOG_INFO("[Nitro] Removed "+mRemovedSingle+" single block Chemical Reactor recipes.");
-
- //Remove Multi Block recipes found.
- for (GT_Recipe multi : toRemoveMulti){
- if (GT_Recipe.GT_Recipe_Map.sMultiblockChemicalRecipes.mRecipeList.remove(multi)){
- mRemovedMulti++;
- }
- }
- Utils.LOG_INFO("[Nitro] Removed "+mRemovedMulti+" multi block Chemical Reactor recipes.");
-
- //Build a New Recipe set
- Materials mFuels[] = {Materials.LightFuel, Materials.Fuel, Materials.Diesel};
- for (Materials fuel : mFuels){
- boolean didAdd[] = new boolean[3];
- Utils.LOG_INFO("[Nitro] Getting ready to add back in the old nitro-diesel recipe to the mixer, using "+fuel.mDefaultLocalName+" as the fuel input.");
- didAdd[0] = GT_Values.RA.addMixerRecipe(fuel.getCells(4), Materials.Glycerol.getCells(1), GT_Values.NI, GT_Values.NI, GT_Values.NF, GT_Values.NF, mNitroFix.getCells(5), 20, 30);
- didAdd[1] = GT_Values.RA.addMixerRecipe(fuel.getCells(4), GT_Values.NI, GT_Values.NI, GT_Values.NI, Materials.Glycerol.getFluid(1000L),mNitroFix.getFluid(5000L), ItemList.Cell_Empty.get(4L), 20, 30);
- didAdd[2] = GT_Values.RA.addMixerRecipe(Materials.Glycerol.getCells(1), GT_Values.NI,GT_Values.NI,GT_Values.NI, fuel.getFluid(4000L),mNitroFix.getFluid(5000L), ItemList.Cell_Empty.get(1L), 20, 30);
- Utils.LOG_INFO("[Nitro] Did the recipes add? 1: "+didAdd[0]+" | 2: "+didAdd[1]+" | 3: "+didAdd[2]);
- }
-
- for (Materials fuel : mFuels){
- boolean didAdd[] = new boolean[3];
- Utils.LOG_INFO("[Nitro] Getting ready to add back in the old nitro-diesel recipe to the chemical reactors, using "+fuel.mDefaultLocalName+" as the fuel input.");
- didAdd[0] = GT_Values.RA.addChemicalRecipe(fuel.getCells(4), Materials.Glycerol.getCells(1), GT_Values.NF, GT_Values.NF, mNitroFix.getCells(5), 20, 30);
- didAdd[1] = GT_Values.RA.addChemicalRecipe(fuel.getCells(4), GT_Values.NI, Materials.Glycerol.getFluid(1000L),mNitroFix.getFluid(5000L), ItemList.Cell_Empty.get(4L), 20, 30);
- didAdd[2] = GT_Values.RA.addChemicalRecipe(Materials.Glycerol.getCells(1), GT_Values.NI, fuel.getFluid(4000L),mNitroFix.getFluid(5000L), ItemList.Cell_Empty.get(1L), 20, 30);
- Utils.LOG_INFO("[Nitro] Did the recipes add? 1: "+didAdd[0]+" | 2: "+didAdd[1]+" | 3: "+didAdd[2]);
- }
-
- Utils.LOG_INFO("[Nitro] Getting ready to add back in the old glycerol recipe!");
- GT_Values.RA.addChemicalRecipe(Materials.Nitrogen.getCells(1), Materials.Carbon.getDust(1), Materials.Water.getFluid(2000L), Materials.Glycerol.getFluid(3000L), ItemList.Cell_Empty.get(1), 3000, 30);
- Utils.LOG_INFO("[Nitro] Added recipes.");
-
-
-
-
-
-
- }
+ }
+ }
+ Utils.LOG_INFO("[Nitro] Found "+mIndexSingle+" single block Chemical Reactor recipes to remove.");
+
+ //Iterate Multi Block recipes for Nitro production.
+ for (GT_Recipe rnd : xMulti){
+ for (FluidStack mOutputFluid : rnd.mFluidOutputs){
+ if (mOutputFluid.isFluidEqual(mNitroStack)){
+ toRemoveMulti[mIndexMulti++] = rnd;
+ }
+ }
}
+ Utils.LOG_INFO("[Nitro] Found "+mIndexMulti+" multi block Chemical Reactor recipes to remove.");
+
+ //Remove Single Block recipes found.
+ int mRemovedSingle = 0;
+ int mRemovedMulti = 0;
+ for (GT_Recipe single : toRemoveSingle){
+ if (GT_Recipe.GT_Recipe_Map.sChemicalRecipes.mRecipeList.remove(single)){
+ mRemovedSingle++;
+ }
+ }
+ Utils.LOG_INFO("[Nitro] Removed "+mRemovedSingle+" single block Chemical Reactor recipes.");
+
+ //Remove Multi Block recipes found.
+ for (GT_Recipe multi : toRemoveMulti){
+ if (GT_Recipe.GT_Recipe_Map.sMultiblockChemicalRecipes.mRecipeList.remove(multi)){
+ mRemovedMulti++;
+ }
+ }
+ Utils.LOG_INFO("[Nitro] Removed "+mRemovedMulti+" multi block Chemical Reactor recipes.");
+
+ //Build a New Recipe set
+ Materials mFuels[] = {Materials.LightFuel, Materials.Fuel, Materials.Diesel};
+ for (Materials fuel : mFuels){
+ boolean didAdd[] = new boolean[3];
+ Utils.LOG_INFO("[Nitro] Getting ready to add back in the old nitro-diesel recipe to the mixer, using "+fuel.mDefaultLocalName+" as the fuel input.");
+ didAdd[0] = GT_Values.RA.addMixerRecipe(fuel.getCells(4), Materials.Glycerol.getCells(1), GT_Values.NI, GT_Values.NI, GT_Values.NF, GT_Values.NF, mNitroFix.getCells(5), 20, 30);
+ didAdd[1] = GT_Values.RA.addMixerRecipe(fuel.getCells(4), GT_Values.NI, GT_Values.NI, GT_Values.NI, Materials.Glycerol.getFluid(1000L),mNitroFix.getFluid(5000L), ItemList.Cell_Empty.get(4L), 20, 30);
+ didAdd[2] = GT_Values.RA.addMixerRecipe(Materials.Glycerol.getCells(1), GT_Values.NI,GT_Values.NI,GT_Values.NI, fuel.getFluid(4000L),mNitroFix.getFluid(5000L), ItemList.Cell_Empty.get(1L), 20, 30);
+ Utils.LOG_INFO("[Nitro] Did the recipes add? 1: "+didAdd[0]+" | 2: "+didAdd[1]+" | 3: "+didAdd[2]);
+ }
+
+ for (Materials fuel : mFuels){
+ boolean didAdd[] = new boolean[3];
+ Utils.LOG_INFO("[Nitro] Getting ready to add back in the old nitro-diesel recipe to the chemical reactors, using "+fuel.mDefaultLocalName+" as the fuel input.");
+ didAdd[0] = GT_Values.RA.addChemicalRecipe(fuel.getCells(4), Materials.Glycerol.getCells(1), GT_Values.NF, GT_Values.NF, mNitroFix.getCells(5), 20, 30);
+ didAdd[1] = GT_Values.RA.addChemicalRecipe(fuel.getCells(4), GT_Values.NI, Materials.Glycerol.getFluid(1000L),mNitroFix.getFluid(5000L), ItemList.Cell_Empty.get(4L), 20, 30);
+ didAdd[2] = GT_Values.RA.addChemicalRecipe(Materials.Glycerol.getCells(1), GT_Values.NI, fuel.getFluid(4000L),mNitroFix.getFluid(5000L), ItemList.Cell_Empty.get(1L), 20, 30);
+ Utils.LOG_INFO("[Nitro] Did the recipes add? 1: "+didAdd[0]+" | 2: "+didAdd[1]+" | 3: "+didAdd[2]);
+ }
+
+ Utils.LOG_INFO("[Nitro] Getting ready to add back in the old glycerol recipe!");
+ GT_Values.RA.addChemicalRecipe(Materials.Nitrogen.getCells(1), Materials.Carbon.getDust(1), Materials.Water.getFluid(2000L), Materials.Glycerol.getFluid(3000L), ItemList.Cell_Empty.get(1), 3000, 30);
+ Utils.LOG_INFO("[Nitro] Added recipes.");
+
}
}
}
- catch (ClassNotFoundException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
- Utils.LOG_INFO("[Nitro] ================ Error ================");
- e.printStackTrace();
- Utils.LOG_INFO("[Nitro] ================ Error ================");
- }
}
+ catch (ClassNotFoundException | IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
+ Utils.LOG_INFO("[Nitro] ================ Error ================");
+ e.printStackTrace();
+ Utils.LOG_INFO("[Nitro] ================ Error ================");
+ }
}
}
+
+
+
}