aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2019-02-28 23:49:40 +0000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2019-02-28 23:49:40 +0000
commit5ffa0957e9d936ec999ee5157be771ff4b315aac (patch)
tree2ec784e5da7c45edc48b18e42f3b98e0cbcf0466 /src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java
parent5b5e135356516e684a8e5baad0299554a3f63ebc (diff)
downloadGT5-Unofficial-5ffa0957e9d936ec999ee5157be771ff4b315aac.tar.gz
GT5-Unofficial-5ffa0957e9d936ec999ee5157be771ff4b315aac.tar.bz2
GT5-Unofficial-5ffa0957e9d936ec999ee5157be771ff4b315aac.zip
+ Enabled Tinkers compat for GT++ Materials.
$ Migrated lots of TiCon code to be reflective. $ Upload missing class ItemDummyResearch.java.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java')
-rw-r--r--src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java330
1 files changed, 290 insertions, 40 deletions
diff --git a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java
index 10eb93b4d7..b902e38a1e 100644
--- a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java
+++ b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java
@@ -1,44 +1,112 @@
package gtPlusPlus.xmod.tinkers.util;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+
import gtPlusPlus.core.lib.LoadedMods;
import gtPlusPlus.core.material.Material;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import net.minecraft.block.Block;
+import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
-import tconstruct.library.TConstructRegistry;
-import tconstruct.library.crafting.FluidType;
-import tconstruct.library.crafting.Smeltery;
-import tconstruct.smeltery.TinkerSmeltery;
+import net.minecraftforge.fluids.FluidStack;
public class TinkersUtils {
private static Object mSmelteryInstance;
private static Class mSmelteryClassInstance;
+
+ private static Object mTinkersRegistryInstance;
+ private static Class mTinkersRegistryClass;
+
+ private static final Class mToolMaterialClass;
- public static Object getSmelteryInstance() {
+ private static final HashMap<String, Method> mMethodCache = new LinkedHashMap<String, Method>();
+
+
+ static {
+ setRegistries();
+ mToolMaterialClass = ReflectionUtils.getClass("tconstruct.library.tools.ToolMaterial");
+ }
+
+
+ /**
+ *
+ * @param aSwitch - The Registry to return
+ */
+ private static Object getTiConDataInstance(int aSwitch) {
if (!LoadedMods.TiCon) {
return null;
}
else {
- if (mSmelteryInstance == null || mSmelteryClassInstance == null) {
- if (mSmelteryClassInstance == null) {
- mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery");
- }
- if (mSmelteryClassInstance != null) {
- try {
- mSmelteryInstance = ReflectionUtils.getField(mSmelteryClassInstance, "instance").get(null);
+
+ if (mTinkersRegistryClass == null || mSmelteryClassInstance == null) {
+ setRegistries();
+ }
+
+ // getSmelteryInstance
+ if (aSwitch == 0) {
+
+ //Set Smeltery Instance
+ if (mSmelteryInstance == null || mSmelteryClassInstance == null) {
+ if (mSmelteryClassInstance == null) {
+ mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery");
}
- catch (IllegalArgumentException | IllegalAccessException e) {
+ if (mSmelteryClassInstance != null) {
+ try {
+ mSmelteryInstance = ReflectionUtils.getField(mSmelteryClassInstance, "instance").get(null);
+ }
+ catch (IllegalArgumentException | IllegalAccessException e) {
+ }
}
}
- }
- }
- if (mSmelteryInstance != null) {
- return mSmelteryInstance;
- }
- return null;
+
+ //Return Smeltery Instance
+ if (mSmelteryInstance != null) {
+ return mSmelteryInstance;
+ }
+ }
+
+ // getTableCastingInstance || getBasinCastingInstance
+ else if (aSwitch == 1) {
+ if (mTinkersRegistryClass == null || mTinkersRegistryInstance == null) {
+ if (mTinkersRegistryClass == null) {
+ mTinkersRegistryClass = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry");
+ }
+ if (mTinkersRegistryClass != null) {
+ if (mTinkersRegistryInstance == null) {
+ try {
+ mTinkersRegistryInstance = ReflectionUtils.getField(mTinkersRegistryClass, "instance").get(null);
+ }
+ catch (IllegalArgumentException | IllegalAccessException e) {
+ }
+ }
+ }
+ }
+
+ //Return Smeltery Instance
+ if (mTinkersRegistryInstance != null) {
+ return mTinkersRegistryInstance;
+ }
+ }
+
+ return null;
+ }
+ }
+
+ private static void setRegistries() {
+ if (mTinkersRegistryClass == null) {
+ mTinkersRegistryClass = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry");
+ }
+ if (mSmelteryClassInstance == null) {
+ mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery");
+ }
}
public static final boolean isTiConFirstInOD() {
@@ -75,56 +143,100 @@ public class TinkersUtils {
* @param duration How long one "portion" of liquid fuels the smeltery. Lava is 10.
*/
public static void addSmelteryFuel (Fluid fluid, int power, int duration){
- ReflectionUtils.invokeVoid(getSmelteryInstance(), "addSmelteryFuel", new Class[] {Fluid.class, int.class, int.class}, new Object[] {fluid, power, duration});
+ ReflectionUtils.invokeVoid(getTiConDataInstance(0), "addSmelteryFuel", new Class[] {Fluid.class, int.class, int.class}, new Object[] {fluid, power, duration});
}
/**
* Returns true if the liquid is a valid smeltery fuel.
*/
public static boolean isSmelteryFuel (Fluid fluid){
- return ReflectionUtils.invoke(getSmelteryInstance(), "isSmelteryFuel", new Class[] {Fluid.class}, new Object[] {fluid});
+ return ReflectionUtils.invoke(getTiConDataInstance(0), "isSmelteryFuel", new Class[] {Fluid.class}, new Object[] {fluid});
}
/**
* Returns the power of a smeltery fuel or 0 if it's not a fuel.
*/
public static int getFuelPower (Fluid fluid){
- return (int) ReflectionUtils.invokeNonBool(getSmelteryInstance(), "getFuelPower", new Class[] {Fluid.class}, new Object[] {fluid});
+ return (int) ReflectionUtils.invokeNonBool(getTiConDataInstance(0), "getFuelPower", new Class[] {Fluid.class}, new Object[] {fluid});
}
/**
* Returns the duration of a smeltery fuel or 0 if it's not a fuel.
*/
public static int getFuelDuration (Fluid fluid){
- return (int) ReflectionUtils.invokeNonBool(getSmelteryInstance(), "getFuelDuration", new Class[] {Fluid.class}, new Object[] {fluid});
+ return (int) ReflectionUtils.invokeNonBool(getTiConDataInstance(0), "getFuelDuration", new Class[] {Fluid.class}, new Object[] {fluid});
}
+
+
+
+
+
+
public static boolean registerFluidType(String name, Block block, int meta, int baseTemperature, Fluid fluid, boolean isToolpart) {
-
-
-
- //FluidType.registerFluidType(mLocalName, aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(0).getFluid(), true);
- return false;
+ if (mMethodCache.get("registerFluidType") == null) {
+ Method m = ReflectionUtils.getMethod(ReflectionUtils.getClass("tconstruct.library.crafting.FluidType"), "registerFluidType", String.class, Block.class, int.class, int.class, Fluid.class, boolean.class);
+ mMethodCache.put("registerFluidType", m);
+ }
+ try {
+ mMethodCache.get("registerFluidType").invoke(null, name, block, meta, baseTemperature, fluid, isToolpart);
+ return true;
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ return false;
+ }
}
- public static boolean addMelting(Material aMaterial) {
- Smeltery.addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9));
- Smeltery.addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144));
- return false;
+
+
+
+
+
+
+
+ public static boolean addBaseMeltingRecipes(Material aMaterial) {
+ return addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)) &&
+ addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144));
}
- public static boolean addBasinRecipe(Material aMaterial) {
- TConstructRegistry.getBasinCasting().addCastingRecipe(aMaterial.getBlock(1),
- aMaterial.getFluid(144*9), (ItemStack) null, true, 100);
- return false;
+ public static boolean addMelting(ItemStack input, Block block, int metadata, int temperature, FluidStack liquid) {
+ if (mMethodCache.get("addMelting") == null) {
+ Method m = ReflectionUtils.getMethod(mSmelteryClassInstance, "addMelting", ItemStack.class, Block.class, int.class, int.class, FluidStack.class);
+ mMethodCache.put("addMelting", m);
+ }
+ try {
+ mMethodCache.get("addMelting").invoke(null, input, block, metadata, temperature, liquid);
+ return true;
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ return false;
+ }
}
- public static boolean addCastingTableRecipe(Material aMaterial) {
- ItemStack ingotcast = new ItemStack(TinkerSmeltery.metalPattern, 1, 0);
- TConstructRegistry.getTableCasting().addCastingRecipe(aMaterial.getIngot(1), aMaterial.getFluid(144), ingotcast, false, 50);
- return false;
+
+
+
+
+
+
+
+
+
+
+ public static boolean addBaseBasinRecipes(Material aMaterial) {
+ return addBasinRecipe(aMaterial.getBlock(1), aMaterial.getFluid(144*9), (ItemStack) null, true, 100);
}
+ public static boolean addBasinRecipe(ItemStack output, FluidStack metal, ItemStack cast, boolean consume, int delay) {
+ if (mMethodCache.get("addBasinRecipe") == null) {
+ Method m = ReflectionUtils.getMethod(ReflectionUtils.getClass("tconstruct.library.crafting.LiquidCasting"), "addCastingRecipe", ItemStack.class, FluidStack.class, ItemStack.class, boolean.class, int.class);
+ mMethodCache.put("addBasinRecipe", m);
+ }
+ try {
+ mMethodCache.get("addBasinRecipe").invoke(getCastingInstance(0), output, metal, cast, consume, delay);
+ return true;
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ return false;
+ }
+ }
@@ -132,6 +244,24 @@ public class TinkersUtils {
+ public static boolean addBaseCastingRecipes(Material aMaterial) {
+ ItemStack ingotcast = getPattern(1);
+ return addCastingTableRecipe(aMaterial.getIngot(1), aMaterial.getFluid(144), ingotcast, false, 50);
+ }
+
+ public static boolean addCastingTableRecipe(ItemStack output, FluidStack metal, ItemStack cast, boolean consume, int delay) {
+ if (mMethodCache.get("addCastingTableRecipe") == null) {
+ Method m = ReflectionUtils.getMethod(ReflectionUtils.getClass("tconstruct.library.crafting.LiquidCasting"), "addBasinRecipe", ItemStack.class, FluidStack.class, ItemStack.class, boolean.class, int.class);
+ mMethodCache.put("addCastingTableRecipe", m);
+ }
+ try {
+ mMethodCache.get("addCastingTableRecipe").invoke(getCastingInstance(1), output, metal, cast, consume, delay);
+ return true;
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ return false;
+ }
+ }
+
@@ -139,7 +269,127 @@ public class TinkersUtils {
+ public static Object getCastingInstance(int aType) {
+ if (aType == 0) {
+ return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getTableCasting", new Class[] {}, new Object[] {});
+ }
+ else if (aType == 1) {
+ return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getBasinCasting", new Class[] {}, new Object[] {});
+ }
+ else {
+ return null;
+ }
+ }
+
+ private static Item mTinkerMetalPattern;
+ public static ItemStack getPattern(int aType) {
+ if (mTinkerMetalPattern == null) {
+ Field m = ReflectionUtils.getField(ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"), "metalPattern");
+ if (m != null) {
+ try {
+ mTinkerMetalPattern = (Item) m.get(null);
+ } catch (IllegalArgumentException | IllegalAccessException e) {
+ }
+ }
+ }
+ if (mTinkerMetalPattern != null) {
+ ItemStack ingotCast = new ItemStack(mTinkerMetalPattern, aType, 0);
+ return ingotCast;
+ }
+ return ItemUtils.getErrorStack(1, "Bad Tinkers Pattern");
+
+
+
+
+
+
+
+ }
+ /**
+ * Generates Tinkers {@link ToolMaterial}'s reflectively.
+ * @param name
+ * @param localizationString
+ * @param level
+ * @param durability
+ * @param speed
+ * @param damage
+ * @param handle
+ * @param reinforced
+ * @param stonebound
+ * @param style
+ * @param primaryColor
+ * @return
+ */
+ public static Object generateToolMaterial(String name, String localizationString, int level, int durability, int speed, int damage, float handle, int reinforced, float stonebound, String style, int primaryColor) {
+ try {
+ Constructor constructor = mToolMaterialClass.getConstructor(String.class, String.class, int.class, int.class, int.class, int.class, float.class, int.class, float.class, String.class, int.class);
+ Object myObject = constructor.newInstance(name, localizationString, level, durability, speed, damage, handle, reinforced, stonebound, style, primaryColor);
+ return myObject;
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return null;
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
+ public static void addToolMaterial(int id, Object aToolMaterial) {
+ setRegistries();
+ if (mMethodCache.get("addToolMaterial") == null) {
+ Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addToolMaterial", int.class, mToolMaterialClass);
+ mMethodCache.put("addToolMaterial", m);
+ }
+ try {
+ mMethodCache.get("addToolMaterial").invoke(mTinkersRegistryClass, id, aToolMaterial);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+
+ }
+ }
+
+ public static void addDefaultToolPartMaterial(int id) {
+ setRegistries();
+ if (mMethodCache.get("addDefaultToolPartMaterial") == null) {
+ Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addDefaultToolPartMaterial", int.class);
+ mMethodCache.put("addDefaultToolPartMaterial", m);
+ }
+ try {
+ mMethodCache.get("addDefaultToolPartMaterial").invoke(mTinkersRegistryClass, id);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ }
+ }
+
+ public static void addBowMaterial(int id, int drawspeed, float maxSpeed) {
+ setRegistries();
+ if (mMethodCache.get("addBowMaterial") == null) {
+ Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addBowMaterial", int.class, int.class, float.class);
+ mMethodCache.put("addBowMaterial", m);
+ }
+ try {
+ mMethodCache.get("addBowMaterial").invoke(mTinkersRegistryClass, id, drawspeed, maxSpeed);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ }
+ }
+
+ public static void addArrowMaterial(int id, float mass, float fragility) {
+ setRegistries();
+ if (mMethodCache.get("addArrowMaterial") == null) {
+ Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addArrowMaterial", int.class, float.class, float.class);
+ mMethodCache.put("addArrowMaterial", m);
+ }
+ try {
+ mMethodCache.get("addArrowMaterial").invoke(mTinkersRegistryClass, id, mass, fragility);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ }
+ }
}