diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-09-02 17:50:19 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-09-02 17:50:19 +1000 |
commit | fdc062fe2d37655ff406dd92b4d796bd90cda484 (patch) | |
tree | 5bfd39fb4a248bb2be610718901cf5ce59adca97 /src/Java/miscutil/core/util/gregtech | |
parent | b2f32b27b25d6275510905ec2c3683c4f390a95b (diff) | |
download | GT5-Unofficial-fdc062fe2d37655ff406dd92b4d796bd90cda484.tar.gz GT5-Unofficial-fdc062fe2d37655ff406dd92b4d796bd90cda484.tar.bz2 GT5-Unofficial-fdc062fe2d37655ff406dd92b4d796bd90cda484.zip |
+ Added new Utility classes.
% Changed compat handling for GT to use reflection to check class values.
Diffstat (limited to 'src/Java/miscutil/core/util/gregtech')
4 files changed, 87 insertions, 65 deletions
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 |