aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/core/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/miscutil/core/util')
-rw-r--r--src/Java/miscutil/core/util/ClassUtils.java23
-rw-r--r--src/Java/miscutil/core/util/LoggingUtils.java54
-rw-r--r--src/Java/miscutil/core/util/gregtech/five/GregtechVersionRecipeHandler.java23
-rw-r--r--src/Java/miscutil/core/util/gregtech/five/eight/AddSmeltingAndAlloySmeltingRecipe.java21
-rw-r--r--src/Java/miscutil/core/util/gregtech/five/nine/AddSmeltingAndAlloySmeltingRecipe.java21
-rw-r--r--src/Java/miscutil/core/util/gregtech/recipehandlers/GregtechRecipe.java87
6 files changed, 164 insertions, 65 deletions
diff --git a/src/Java/miscutil/core/util/ClassUtils.java b/src/Java/miscutil/core/util/ClassUtils.java
new file mode 100644
index 0000000000..6ea9336006
--- /dev/null
+++ b/src/Java/miscutil/core/util/ClassUtils.java
@@ -0,0 +1,23 @@
+package miscutil.core.util;
+
+public class ClassUtils {
+
+
+ /*@ if (isPresent("com.optionaldependency.DependencyClass")) {
+ // This block will never execute when the dependency is not present
+ // There is therefore no more risk of code throwing NoClassDefFoundException.
+ executeCodeLinkingToDependency();
+ }*/
+ public static boolean isPresent(String className) {
+ try {
+ Class.forName(className);
+ return true;
+ } catch (Throwable ex) {
+ // Class or one of its dependencies is not present...
+ return false;
+ }
+ }
+
+
+
+}
diff --git a/src/Java/miscutil/core/util/LoggingUtils.java b/src/Java/miscutil/core/util/LoggingUtils.java
new file mode 100644
index 0000000000..5942ead120
--- /dev/null
+++ b/src/Java/miscutil/core/util/LoggingUtils.java
@@ -0,0 +1,54 @@
+package miscutil.core.util;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Date;
+
+public class LoggingUtils {
+
+ public static void profileLog(Object o){
+ try {
+ String content;
+ File file = new File("GregtechTimingsTC.txt");
+ // if file doesnt exists, then create it
+ if (!file.exists()) {
+ file.createNewFile();
+ FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write("============================================================");
+ bw.write(System.lineSeparator());
+ bw.close();
+ }
+ if (o instanceof String){
+ content = (String) o;
+ }
+ else {
+ content = o.toString();
+ }
+ FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write(content);
+ bw.write(System.lineSeparator());
+ bw.close();
+ System.out.println("Data Logged.");
+
+ } catch (IOException e) {
+ System.out.println("Data logging failed.");
+ }
+ }
+
+ public static boolean logCurrentSystemTime(String message){
+ Date date = new Date(System.currentTimeMillis());
+ try {
+ profileLog(message+" | "+date.toString());
+ return true;
+ }
+ catch (Throwable r) {
+ return false;
+ }
+
+ }
+
+}
diff --git a/src/Java/miscutil/core/util/gregtech/five/GregtechVersionRecipeHandler.java b/src/Java/miscutil/core/util/gregtech/five/GregtechVersionRecipeHandler.java
deleted file mode 100644
index 3025183204..0000000000
--- a/src/Java/miscutil/core/util/gregtech/five/GregtechVersionRecipeHandler.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package miscutil.core.util.gregtech.five;
-
-import miscutil.core.lib.CORE;
-import net.minecraft.item.ItemStack;
-
-public class GregtechVersionRecipeHandler {
-
- public static final boolean mainFork = isExperimentalVersion();
-
- public static boolean isExperimentalVersion(){
- return CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK;
- }
-
- public static void addSmeltingAndAlloySmeltingRecipe(ItemStack aInput, ItemStack aOutput){
- if (mainFork){
- miscutil.core.util.gregtech.five.nine.AddSmeltingAndAlloySmeltingRecipe.run(aInput, aOutput, false);
- }
- else {
- miscutil.core.util.gregtech.five.eight.AddSmeltingAndAlloySmeltingRecipe.run(aInput, aOutput);
- }
- }
-
-}
diff --git a/src/Java/miscutil/core/util/gregtech/five/eight/AddSmeltingAndAlloySmeltingRecipe.java b/src/Java/miscutil/core/util/gregtech/five/eight/AddSmeltingAndAlloySmeltingRecipe.java
deleted file mode 100644
index d990e70bae..0000000000
--- a/src/Java/miscutil/core/util/gregtech/five/eight/AddSmeltingAndAlloySmeltingRecipe.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package miscutil.core.util.gregtech.five.eight;
-
-import static gregtech.api.enums.GT_Values.RA;
-import gregtech.api.enums.ItemList;
-import gregtech.api.enums.OrePrefixes;
-import gregtech.api.util.GT_ModHandler;
-import net.minecraft.item.ItemStack;
-
-public class AddSmeltingAndAlloySmeltingRecipe {
-
- public static boolean run(ItemStack aInput, ItemStack aOutput) {
- if (aInput == null || aOutput == null) return false;
- boolean temp = false;
- if (aInput.stackSize == 1 && GT_ModHandler.addSmeltingRecipe(aInput, aOutput)) temp = true;
- if (RA.addAlloySmelterRecipe(aInput, OrePrefixes.ingot.contains(aOutput) ? ItemList.Shape_Mold_Ingot.get(0) : OrePrefixes.block.contains(aOutput) ? ItemList.Shape_Mold_Block.get(0) : OrePrefixes.nugget.contains(aOutput) ? ItemList.Shape_Mold_Nugget.get(0) : null, aOutput, 130, 3))
- temp = true;
- if (GT_ModHandler.addInductionSmelterRecipe(aInput, null, aOutput, null, aOutput.stackSize * 1600, 0)) temp = true;
- return temp;
- }
-
-}
diff --git a/src/Java/miscutil/core/util/gregtech/five/nine/AddSmeltingAndAlloySmeltingRecipe.java b/src/Java/miscutil/core/util/gregtech/five/nine/AddSmeltingAndAlloySmeltingRecipe.java
deleted file mode 100644
index 267a14b85e..0000000000
--- a/src/Java/miscutil/core/util/gregtech/five/nine/AddSmeltingAndAlloySmeltingRecipe.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package miscutil.core.util.gregtech.five.nine;
-
-import gregtech.api.enums.GT_Values;
-import gregtech.api.enums.ItemList;
-import gregtech.api.enums.OrePrefixes;
-import gregtech.api.util.GT_ModHandler;
-import net.minecraft.item.ItemStack;
-
-public class AddSmeltingAndAlloySmeltingRecipe {
-
- public static boolean run(ItemStack aInput, ItemStack aOutput, boolean hidden) {
- if (aInput == null || aOutput == null) return false;
- boolean temp = false;
- if (aInput.stackSize == 1 && GT_ModHandler.addSmeltingRecipe(aInput, aOutput)) temp = true;
- if (GT_Values.RA.addAlloySmelterRecipe(aInput, OrePrefixes.ingot.contains(aOutput) ? ItemList.Shape_Mold_Ingot.get(0) : OrePrefixes.block.contains(aOutput) ? ItemList.Shape_Mold_Block.get(0) : OrePrefixes.nugget.contains(aOutput) ? ItemList.Shape_Mold_Nugget.get(0) : null, aOutput, 130, 3))
- temp = true;
- if (GT_ModHandler.addInductionSmelterRecipe(aInput, null, aOutput, null, aOutput.stackSize * 1600, 0)) temp = true;
- return temp;
- }
-
-}
diff --git a/src/Java/miscutil/core/util/gregtech/recipehandlers/GregtechRecipe.java b/src/Java/miscutil/core/util/gregtech/recipehandlers/GregtechRecipe.java
new file mode 100644
index 0000000000..bab4c1ff0d
--- /dev/null
+++ b/src/Java/miscutil/core/util/gregtech/recipehandlers/GregtechRecipe.java
@@ -0,0 +1,87 @@
+package miscutil.core.util.gregtech.recipehandlers;
+
+import gregtech.api.util.GT_ModHandler;
+
+import java.lang.reflect.Method;
+
+import miscutil.core.lib.CORE;
+import miscutil.core.util.Utils;
+import net.minecraft.item.ItemStack;
+
+public final class GregtechRecipe {
+
+ public LibraryProxy ourProxy;
+ public GregtechRecipe(){
+ Utils.LOG_INFO("Initializing a recipe handler for different versions of Gregtech 5.");
+ try {
+ if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK){
+ this.ourProxy = new LibProxy1();
+ Utils.LOG_INFO("Selecting GT 5.7/5.8 Recipe Set");
+ }
+ if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK){
+ this.ourProxy = new LibProxy2();
+ Utils.LOG_INFO("Selecting GT 5.9 Recipe Set");
+ }
+ } catch (NoSuchMethodException e) {
+ this.ourProxy = null;
+ }
+ }
+
+ public boolean addSmeltingAndAlloySmeltingRecipe(ItemStack aInput, ItemStack aOutput) {
+ Utils.LOG_INFO("Adding a GT Furnace/Alloy Smelter Recipe");
+ return ourProxy.addSmeltingAndAlloySmeltingRecipe(aInput, aOutput);
+ }
+
+}
+
+abstract class LibraryProxy { // can also be interface unless you want to have common code here
+ abstract public boolean addSmeltingAndAlloySmeltingRecipe(ItemStack aInput, ItemStack aOutput);
+}
+
+class LibProxy1 extends LibraryProxy {
+ final Method m1;
+
+ public LibProxy1() throws NoSuchMethodException {
+ m1 = GT_ModHandler.class.getDeclaredMethod("addSmeltingAndAlloySmeltingRecipe", ItemStack.class, ItemStack.class);
+ }
+
+ @Override
+ public boolean addSmeltingAndAlloySmeltingRecipe(ItemStack aInput, ItemStack aOutput) {
+ try {
+ Utils.LOG_INFO("Trying with Gt 5.7/5.8 Method.");
+ return (boolean) m1.invoke(null, aInput, aOutput);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
+
+class LibProxy2 extends LibraryProxy {
+ final Method m2;
+
+ public LibProxy2() throws NoSuchMethodException {
+ m2 = GT_ModHandler.class.getDeclaredMethod("addSmeltingAndAlloySmeltingRecipe", ItemStack.class, ItemStack.class, boolean.class);
+ }
+
+ @Override
+ public boolean addSmeltingAndAlloySmeltingRecipe(ItemStack aInput, ItemStack aOutput) {
+ try {
+ Utils.LOG_INFO("Trying with Gt 5.9 Method.");
+ return (boolean) m2.invoke(null, aInput, aOutput, true);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
+
+/*class Lib { // v1
+ public static void addRecipe(ItemStack aInput, ItemStack aOutput) {
+ System.out.println("shit totally happened v1");
+ }
+}
+
+class Lib2 { // v2
+ public static void addRecipe(ItemStack aInput, ItemStack aOutput, boolean hidden) {
+ System.out.println("shit totally happened v2");
+ }
+}*/ \ No newline at end of file