diff options
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/tinkers')
3 files changed, 737 insertions, 32 deletions
diff --git a/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java b/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java index 501fe6579a..3b2bcba5dd 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java @@ -6,6 +6,7 @@ import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.tinkers.material.BaseTinkersMaterial; import gtPlusPlus.xmod.tinkers.util.TinkersUtils; import net.minecraft.block.Block; import net.minecraftforge.fluids.Fluid; @@ -13,6 +14,8 @@ import net.minecraftforge.fluids.FluidRegistry; public class HANDLER_Tinkers { + public static AutoMap<BaseTinkersMaterial> mTinkerMaterials = new AutoMap<BaseTinkersMaterial>(); + public static final void preInit() { if (LoadedMods.TiCon) { @@ -31,9 +34,14 @@ public class HANDLER_Tinkers { } } - public static final void postInit() { + public static final void postInit() { if (LoadedMods.TiCon) { - Class aTinkersSmeltery = ReflectionUtils.getClassByName("tconstruct.smeltery.TinkerSmeltery"); + + for (BaseTinkersMaterial y : mTinkerMaterials) { + //y.generate(); + } + + Class aTinkersSmeltery = ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"); AutoMap<Fluid> aTweakedFluids = new AutoMap<Fluid>(); if (aTinkersSmeltery != null) { try { @@ -84,7 +92,7 @@ public class HANDLER_Tinkers { } } } - } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { } } } diff --git a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java new file mode 100644 index 0000000000..6f47909a01 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -0,0 +1,274 @@ +package gtPlusPlus.xmod.tinkers.material; + +import static gtPlusPlus.core.util.math.MathUtils.safeCast_LongToInt; + +import java.util.HashMap; + +import cpw.mods.fml.common.event.FMLInterModComms; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.xmod.tinkers.HANDLER_Tinkers; +import gtPlusPlus.xmod.tinkers.util.TinkersUtils; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fluids.Fluid; + +public class BaseTinkersMaterial { + + + + private static HashMap<String, Integer> aInternalMaterialIdMap = new HashMap<String, Integer>(); + private static int aNextFreeID; + + public final String mLocalName; + + private final String mUnlocalName; + private final int mID; + private final Material mMaterial; + + static { + aNextFreeID = (Short.MAX_VALUE/2)+420; + } + + public BaseTinkersMaterial(Material aMaterial) { + mLocalName = aMaterial.getLocalizedName(); + mUnlocalName = "material.gtpp."+Utils.sanitizeString(mLocalName); + mMaterial = aMaterial; + mID = aNextFreeID++; + Logger.INFO("[TiCon] Assigning ID "+mID+" to "+mLocalName+"."); + aInternalMaterialIdMap.put(mUnlocalName, mID); + HANDLER_Tinkers.mTinkerMaterials.put(this); + } + + public String getUnlocalName() { + return mUnlocalName; + } + + private static int calcDurability(Material aMaterial) { + return safeCast_LongToInt(aMaterial.vDurability); + } + + private static int calcMiningSpeed(Material aMaterial) { + return (aMaterial.vHarvestLevel * 2)+aMaterial.vTier; + } + + private static int calcHarvestLevel(Material aMaterial) { + return aMaterial.vHarvestLevel; + } + + private static int calcAttack(Material aMaterial) { + return aMaterial.vHarvestLevel+aMaterial.vTier+aMaterial.vRadiationLevel; + } + + private static float calcHandleModifier(Material aMaterial) { + return 1f; + } + + private static int calcReinforced(Material aMaterial) { + return aMaterial.getMeltingPointC()/3600; + } + + private static int calcBowProjectileSpeed(Material aMaterial) { + return aMaterial.vHarvestLevel+2; + } + + private static int calcBowDrawSpeed(Material aMaterial) { + return aMaterial.vHarvestLevel+8; + } + + private static float calcProjectileMass(Material aMaterial) { + return (aMaterial.getMeltingPointC()/1800)*0.1f; + } + + private static float calcProjectileFragility(Material aMaterial) { + return 0f; + } + + private static String calcStyle(Material aMaterial) { + String aReturn = "" + EnumChatFormatting.WHITE; + int aTemp = aMaterial.getMeltingPointC(); + if (aTemp < 3600) { + aReturn = "" + EnumChatFormatting.WHITE; + } + else if (aTemp >= 3600) { + aReturn = "" + EnumChatFormatting.YELLOW; + } + else if (aTemp >= (3600*2)) { + aReturn = "" + EnumChatFormatting.GREEN; + } + else if (aTemp >= (3600*3)) { + aReturn = "" + EnumChatFormatting.RED; + } + else if (aTemp >= (3600*4)) { + aReturn = "" + EnumChatFormatting.DARK_RED; + } + else { + aReturn = "" + EnumChatFormatting.GOLD; + } + return aReturn; + } + + private static int calcColour(Material aMaterial) { + return aMaterial.getRgbAsHex(); + } + + public Object generateToolMaterial(Material aMaterial) { + int level, dura, speed, dmg, reinf, primColour; + float handle, stonebound; + level = calcHarvestLevel(aMaterial); + dura = calcDurability(aMaterial); + speed = calcMiningSpeed(aMaterial); + dmg = calcAttack(aMaterial); + reinf = calcReinforced(aMaterial); + primColour = calcColour(aMaterial); + handle = calcHandleModifier(aMaterial); + //stonebound = calcHarvestLevel(aMaterial); + stonebound = 0; + return TinkersUtils.generateToolMaterial(aMaterial.getLocalizedName(), aMaterial.getUnlocalizedName(), level, dura, speed, dmg, handle, reinf, stonebound, calcStyle(aMaterial), primColour); + } + + public void generate() { + + Logger.INFO("[TiCon] Trying to generate Material: "+mLocalName); + int id = mID; + if (id > 0) { + + //Object aTinkersCustomMaterial = generateToolMaterial(mMaterial); + //Logger.INFO("[TiCon] Created Material: "+mLocalName); + + //TinkersUtils.addToolMaterial(id, aTinkersCustomMaterial); + //TinkersUtils.addDefaultToolPartMaterial(id); + //TinkersUtils.addBowMaterial(id, calcBowDrawSpeed(mMaterial), 1.0F); + //TinkersUtils.addArrowMaterial(id, calcProjectileMass(mMaterial), calcProjectileFragility(mMaterial)); + + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("Id", id); + tag.setString("Name", mUnlocalName); + tag.setString("localizationString", mLocalName); + tag.setInteger("Durability", calcDurability(mMaterial)); // 97 + tag.setInteger("MiningSpeed", calcMiningSpeed(mMaterial)); // 150 + tag.setInteger("HarvestLevel", calcHarvestLevel(mMaterial)); // 1 + tag.setInteger("Attack", calcAttack(mMaterial)); // 0 + tag.setFloat("HandleModifier", calcHandleModifier(mMaterial)); // 1.0f + tag.setInteger("Reinforced", calcReinforced(mMaterial)); // 0 + tag.setFloat("Bow_ProjectileSpeed", calcBowProjectileSpeed(mMaterial)); // 3.0f + tag.setInteger("Bow_DrawSpeed", calcBowDrawSpeed(mMaterial)); // 18 + tag.setFloat("Projectile_Mass", calcProjectileMass(mMaterial)); // 0.69f + tag.setFloat("Projectile_Fragility", calcProjectileFragility(mMaterial)); // 0.2f + tag.setString("Style", calcStyle(mMaterial)); + tag.setInteger("Color", calcColour(mMaterial)); + + + boolean generate = generateRecipes(mMaterial, id); + + if (generate) { + Logger.INFO("[TiCon] Sending IMC: addMaterial - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addMaterial", tag); + + ItemStack itemstack = mMaterial.getIngot(1); + tag = new NBTTagCompound(); + tag.setInteger("MaterialId", id); + NBTTagCompound item = new NBTTagCompound(); + itemstack.writeToNBT(item); + tag.setTag("Item", item); + tag.setInteger("Value", 2); // What is value for? + + Logger.INFO("[TiCon] Sending IMC: addPartBuilderMaterial - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addPartBuilderMaterial", tag); + + tag = new NBTTagCompound(); + tag.setInteger("MaterialId", id); + tag.setInteger("Value", 2); // What is value for? + item = new NBTTagCompound(); + itemstack.writeToNBT(item); + tag.setTag("Item", item); + + Logger.INFO("[TiCon] Sending IMC: addMaterialItem - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addMaterialItem", tag); + } + + + } + + } + + private boolean generateRecipes(Material aMaterial, int aID) { + + Block aMatBlock; + Integer aMelt; + Fluid aFluid; + + try { + aMatBlock = aMaterial.getBlock(); + aMelt = aMaterial.getMeltingPointC(); + aFluid = aMaterial.getFluid(0).getFluid(); + } + catch (Throwable t) { + return false; + } + + if (aMatBlock == null || aMelt == null || aFluid == null) { + return false; + } + + + //Smeltery.addMelting(new ItemStack(ExtraUtils.unstableIngot, 1, 0), ExtraUtils.decorative1, 5, 850, aMaterial.getFluid(72)); + TinkersUtils.registerFluidType(mLocalName, aMatBlock, 0, aMelt, aFluid, true); + TinkersUtils.addMelting(aMaterial.getBlock(1), aMatBlock, 0, aMelt, aMaterial.getFluid(144*9)); + TinkersUtils.addMelting(aMaterial.getIngot(1), aMatBlock, 0, aMelt, aMaterial.getFluid(144)); + if (aMelt <= 3600) { + ItemStack ingotcast = TinkersUtils.getPattern(1); + TinkersUtils.addBasinRecipe(aMaterial.getBlock(1), + aMaterial.getFluid(144*9), (ItemStack) null, true, 100); + TinkersUtils.addCastingTableRecipe(aMaterial.getIngot(1), + aMaterial.getFluid(144), ingotcast, false, 50); + } + + boolean extended = TinkersUtils.generateCastingRecipes(aMaterial, aID); + + + + + + + //TConstructRegistry.getBasinCasting().addCastingRecipe(new ItemStack(ExtraUtils.decorative1, 1, 5), new FluidStack(unstable, 1296), (ItemStack)null, true, 100); + + + + + + + + + + + + + + + + + + + + + + + + + + + + return true; + } + + + + + + + +} diff --git a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index aed5b46e0a..f0c6d76b7c 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -1,48 +1,99 @@ 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.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; + +import gregtech.api.enums.Materials; 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 net.minecraftforge.fluids.FluidStack; public class TinkersUtils { - private static Object mSmelteryInstance; - private static Class mSmelteryClassInstance; + private static final Class mClass_Smeltery; + private static final Class mClass_TConstructRegistry; + private static final Class mClass_ToolMaterial; + private static final Class mClass_IPattern; + private static final Class mClass_DynamicToolPart; + private static final Class mClass_FluidType; + private static final Class mClass_CastingRecipe; + private static final Class mClass_TinkerSmeltery; + + private static final Field mField_MoltenIronFluid; + + private static final Method mMethod_getFluidType; + private static final Method mMethod_getCastingRecipes; - public static Object getSmelteryInstance() { + private static Object mSmelteryInstance; + private static Object mTinkersRegistryInstance; + + private static final HashMap<String, Method> mMethodCache = new LinkedHashMap<String, Method>(); + + + static { + mClass_Smeltery = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); + mClass_TConstructRegistry = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); + + mClass_ToolMaterial = ReflectionUtils.getClass("tconstruct.library.tools.ToolMaterial"); + mClass_IPattern = ReflectionUtils.getClass("tconstruct.library.util.IPattern"); + mClass_DynamicToolPart = ReflectionUtils.getClass("tconstruct.library.tools.DynamicToolPart"); + mClass_FluidType = ReflectionUtils.getClass("tconstruct.library.crafting.FluidType"); + mClass_CastingRecipe = ReflectionUtils.getClass("tconstruct.library.crafting.CastingRecipe"); + mClass_TinkerSmeltery = ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"); + + mField_MoltenIronFluid = ReflectionUtils.getField(mClass_TinkerSmeltery, "moltenIronFluid"); + + mMethod_getFluidType = ReflectionUtils.getMethod(mClass_FluidType, "getFluidType", String.class); + mMethod_getCastingRecipes = ReflectionUtils.getMethod(getCastingInstance(0), "getCastingRecipes", new Class[] {}); + } + + + /** + * + * @param aSwitch - The Registry to return + */ + private static void setTiConDataInstance() { if (!LoadedMods.TiCon) { - return null; - } - else { - if (mSmelteryInstance == null || mSmelteryClassInstance == null) { - if (mSmelteryClassInstance == null) { + return; + } else { + if (mSmelteryInstance == null) { + if (mClass_Smeltery != null) { try { - mSmelteryClassInstance = Class.forName("tconstruct.library.crafting.Smeltery"); + mSmelteryInstance = ReflectionUtils.getField(mClass_Smeltery, "instance").get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { } - catch (ClassNotFoundException e) {} } - if (mSmelteryClassInstance != null) { + } + if (mTinkersRegistryInstance == null) { + if (mClass_TConstructRegistry != null) { try { - mSmelteryInstance = ReflectionUtils.getField(mSmelteryClassInstance, "instance").get(null); - } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + mTinkersRegistryInstance = ReflectionUtils.getField(mClass_TConstructRegistry, "instance").get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { } } - } - } - if (mSmelteryInstance != null) { - return mSmelteryInstance; - } - return null; + } + } } public static final boolean isTiConFirstInOD() { if (LoadedMods.TiCon) { try { - return (boolean) ReflectionUtils.getField(Class.forName("PHConstruct"), "tconComesFirst").get(null); - } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) { + return (boolean) ReflectionUtils.getField(ReflectionUtils.getClass("PHConstruct"), "tconComesFirst").get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { } } return false; @@ -51,8 +102,8 @@ public class TinkersUtils { public static final boolean stopTiconLoadingFirst() { if (isTiConFirstInOD()) { try { - ReflectionUtils.setFieldValue(Class.forName("PHConstruct"), "tconComesFirst", false); - if ((boolean) ReflectionUtils.getField(Class.forName("PHConstruct"), "tconComesFirst").get(null) == false) { + ReflectionUtils.setFinalFieldValue(ReflectionUtils.getClass("PHConstruct"), "tconComesFirst", false); + if ((boolean) ReflectionUtils.getField(ReflectionUtils.getClass("PHConstruct"), "tconComesFirst").get(null) == false) { return true; } //Did not work, let's see where TiCon uses this and prevent it. @@ -72,28 +123,400 @@ 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}); + setTiConDataInstance(); + ReflectionUtils.invokeVoid(mSmelteryInstance, "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}); + setTiConDataInstance(); + return ReflectionUtils.invoke(mSmelteryInstance, "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}); + setTiConDataInstance(); + return (int) ReflectionUtils.invokeNonBool(mSmelteryInstance, "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}); + setTiConDataInstance(); + return (int) ReflectionUtils.invokeNonBool(mSmelteryInstance, "getFuelDuration", new Class[] {Fluid.class}, new Object[] {fluid}); + } + + + + + + + + public static boolean registerFluidType(String name, Block block, int meta, int baseTemperature, Fluid fluid, boolean isToolpart) { + 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 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 addMelting(ItemStack input, Block block, int metadata, int temperature, FluidStack liquid) { + if (mMethodCache.get("addMelting") == null) { + Method m = ReflectionUtils.getMethod(mClass_Smeltery, "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 addMelting(Object type, ItemStack input, int temperatureDifference, int fluidAmount) { + if (mMethodCache.get("addMelting") == null) { + Method m = ReflectionUtils.getMethod(mClass_Smeltery, "addMelting", mClass_FluidType, ItemStack.class, int.class, int.class); + mMethodCache.put("addMelting", m); + } + try { + mMethodCache.get("addMelting").invoke(null, type, input, temperatureDifference, fluidAmount); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + 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; + } + } + + + + + + + + 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"), "addCastingRecipe", 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; + } + } + + + + + + + + /** + * 0 For Table, 1 For Basin. + * @param aType - Casting Type + * @return - The casting instance. + */ + public static Object getCastingInstance(int aType) { + + setTiConDataInstance(); + + Method m = null; + if (aType == 0) { + m = ReflectionUtils.getMethod(mTinkersRegistryInstance, "getTableCasting", new Class[] {}); + //return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getTableCasting", new Class[] {}, new Object[] {}); + } + else if (aType == 1) { + m = ReflectionUtils.getMethod(mTinkersRegistryInstance, "getBasinCasting", new Class[] {}); + //return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getBasinCasting", new Class[] {}, new Object[] {}); + } + else { + //return null; + } + + if (m != null) { + try { + return m.invoke(mTinkersRegistryInstance, new Object[] {}); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + } + return null; + } + + + private static Item mTinkerMetalPattern; + public static ItemStack getPattern(int aType) { + if (mTinkerMetalPattern == null) { + Field m = ReflectionUtils.getField(mClass_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 = mClass_ToolMaterial.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) { + if (mMethodCache.get("addToolMaterial") == null) { + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addtoolMaterial", int.class, mClass_ToolMaterial); + mMethodCache.put("addToolMaterial", m); + } + try { + mMethodCache.get("addToolMaterial").invoke(mClass_TConstructRegistry, id, aToolMaterial); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + + } + } + + public static void addDefaultToolPartMaterial(int id) { + if (mMethodCache.get("addDefaultToolPartMaterial") == null) { + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addDefaultToolPartMaterial", int.class); + mMethodCache.put("addDefaultToolPartMaterial", m); + } + try { + mMethodCache.get("addDefaultToolPartMaterial").invoke(mClass_TConstructRegistry, id); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + + public static void addBowMaterial(int id, int drawspeed, float maxSpeed) { + if (mMethodCache.get("addBowMaterial") == null) { + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addBowMaterial", int.class, int.class, float.class); + mMethodCache.put("addBowMaterial", m); + } + try { + mMethodCache.get("addBowMaterial").invoke(mClass_TConstructRegistry, id, drawspeed, maxSpeed); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + + public static void addArrowMaterial(int id, float mass, float fragility) { + if (mMethodCache.get("addArrowMaterial") == null) { + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addArrowMaterial", int.class, float.class, float.class); + mMethodCache.put("addArrowMaterial", m); + } + try { + mMethodCache.get("addArrowMaterial").invoke(mClass_TConstructRegistry, id, mass, fragility); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + + public static List getTableCastingRecipes(){ + Object aCastingTableHandlerInstance = getCastingInstance(0); + List aTemp; + try { + aTemp = (List) mMethod_getCastingRecipes.invoke(aCastingTableHandlerInstance, new Object[] {}); + return aTemp; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + return new ArrayList(); + } + + public static boolean generateCastingRecipes(Material aMaterial, int aID) { + + List newRecipies = new LinkedList(); + + + Iterator iterator1 = getTableCastingRecipes().iterator(); + Fluid aMoltenIron = null; + if (aMoltenIron == null) { + try { + aMoltenIron = (Fluid) mField_MoltenIronFluid.get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + aMoltenIron = Materials.Iron.getMolten(0).getFluid(); + } + } + while (iterator1.hasNext()) { + CastingRecipeHandler recipe = new CastingRecipeHandler(iterator1.next()); + if (recipe == null || !recipe.valid) { + continue; + } + try { + if (recipe.castingMetal.getFluid() == aMoltenIron && recipe.cast != null + && mClass_IPattern.isInstance(recipe.cast.getItem()) && mClass_DynamicToolPart.isInstance(recipe.getResult().getItem())) { + newRecipies.add(recipe); + } + } catch (IllegalArgumentException e) { + e.printStackTrace(); + return false; + } + } + + + Object ft; + try { + ft = mMethod_getFluidType.invoke(null, aMaterial.getLocalizedName()); + Iterator iterator2 = newRecipies.iterator(); + while (iterator2.hasNext()) { + CastingRecipeHandler recipe = new CastingRecipeHandler(iterator2.next()); + if (!recipe.valid){ + continue; + } + //CastingRecipe recipe = (CastingRecipe) i$.next(); + ItemStack output = recipe.getResult().copy(); + output.setItemDamage(aID); + FluidStack liquid2 = new FluidStack(aMaterial.getFluid(0).getFluid(), recipe.castingMetal.amount); + addCastingTableRecipe(output, liquid2, recipe.cast, recipe.consumeCast, recipe.coolTime); + addMelting(ft, output, 0, liquid2.amount / 2); + } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + return false; + } + + return true; + } + + private static class CastingRecipeHandler { + + public ItemStack output; + public FluidStack castingMetal; + public ItemStack cast; + public boolean consumeCast; + public int coolTime; + + public boolean valid; + + public CastingRecipeHandler(Object aCastingRecipe) { + if (mClass_CastingRecipe.isInstance(aCastingRecipe)) { + try { + Field aF_output = ReflectionUtils.getField(mClass_CastingRecipe, "output"); + Field aF_castingMetal = ReflectionUtils.getField(mClass_CastingRecipe, "castingMetal"); + Field aF_cast = ReflectionUtils.getField(mClass_CastingRecipe, "cast"); + Field aF_consumeCast = ReflectionUtils.getField(mClass_CastingRecipe, "consumeCast"); + Field aF_coolTime = ReflectionUtils.getField(mClass_CastingRecipe, "coolTime"); + + output = (ItemStack) aF_output.get(aCastingRecipe); + castingMetal = (FluidStack) aF_castingMetal.get(aCastingRecipe); + cast = (ItemStack) aF_cast.get(aCastingRecipe); + consumeCast = (boolean) aF_consumeCast.get(aCastingRecipe); + coolTime = (int) aF_coolTime.get(aCastingRecipe); + valid = true; + } + catch (Throwable t) { + t.printStackTrace(); + valid = false; + } + } + else { + valid = false; + } + } + + public boolean matches(FluidStack metal, ItemStack inputCast) { + return this.castingMetal.isFluidEqual(metal) && (this.cast != null && this.cast.getItemDamage() == 32767 + && inputCast.getItem() == this.cast.getItem() || ItemStack.areItemStacksEqual(this.cast, inputCast)); + } + + public ItemStack getResult() { + return this.output.copy(); + } + } } |