diff options
Diffstat (limited to 'src')
4 files changed, 83 insertions, 109 deletions
diff --git a/src/Java/gtPlusPlus/core/recipe/RECIPES_General.java b/src/Java/gtPlusPlus/core/recipe/RECIPES_General.java index c2fd4adc41..54380306cc 100644 --- a/src/Java/gtPlusPlus/core/recipe/RECIPES_General.java +++ b/src/Java/gtPlusPlus/core/recipe/RECIPES_General.java @@ -178,7 +178,7 @@ public class RECIPES_General { ItemUtils.getSimpleStack(ModItems.dustTumbagaMix), ItemUtils.getSimpleStack(ModItems.dustTumbagaMix), ItemUtils.getSimpleStack(ModItems.dustTumbagaMix), - "dustCopper" + "dustGold" }, ALLOY.TUMBAGA.getDust(10))){ Logger.INFO("Added shapeless recipe for Tumbaga Dust."); diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 827ffbf5fb..617728cdec 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -9,6 +9,8 @@ import java.lang.reflect.Modifier; import java.util.LinkedHashMap; import java.util.Map; +import org.apache.commons.lang3.ArrayUtils; + import com.google.common.reflect.ClassPath; import gtPlusPlus.api.objects.Logger; @@ -77,9 +79,9 @@ public class ReflectionUtils { return false; } boolean isStatic = Modifier.isStatic(aMethod.getModifiers()); - CachedMethod y = mCachedMethods.get(aClass.getName()+"."+aMethod.getName()+"."+aMethod.getParameterTypes().toString()); + CachedMethod y = mCachedMethods.get(aClass.getName()+"."+aMethod.getName()+"."+ArrayUtils.toString(aMethod.getParameterTypes())); if (y == null) { - mCachedMethods.put(aClass.getName()+"."+aMethod.getName()+"."+aMethod.getParameterTypes().toString(), new CachedMethod(aMethod, isStatic)); + mCachedMethods.put(aClass.getName()+"."+aMethod.getName()+"."+ArrayUtils.toString(aMethod.getParameterTypes()), new CachedMethod(aMethod, isStatic)); return true; } return false; @@ -138,7 +140,8 @@ public class ReflectionUtils { * @return - Valid, non-final, {@link Method} object, or {@link null}. */ public static Method getMethod(Class aClass, String aMethodName, Class... aTypes) { - String aMethodKey = aTypes.toString(); + String aMethodKey = ArrayUtils.toString(aTypes); + //Logger.REFLECTION("Looking up method in cache: "+(aClass.getName()+"."+aMethodName + "." + aMethodKey)); CachedMethod y = mCachedMethods.get(aClass.getName()+"."+aMethodName + "." + aMethodKey); if (y == null) { Method u = getMethod_Internal(aClass, aMethodName, aTypes); @@ -169,7 +172,7 @@ public class ReflectionUtils { try { u = getField_Internal(aClass, aFieldName); if (u != null) { - Logger.REFLECTION("Caching Field '"+aFieldName+"' from "+aClass.getCanonicalName()); + Logger.REFLECTION("Caching Field '"+aFieldName+"' from "+aClass.getName()); cacheField(aClass, u); return u; } @@ -426,16 +429,20 @@ public class ReflectionUtils { private static Field getField_Internal(final Class<?> clazz, final String fieldName) throws NoSuchFieldException { try { + Logger.REFLECTION("Field: Internal Lookup: "+fieldName); Field k = clazz.getDeclaredField(fieldName); makeFieldAccessible(k); //Logger.REFLECTION("Got Field from Class. "+fieldName+" did exist within "+clazz.getCanonicalName()+"."); return k; } catch (final NoSuchFieldException e) { + Logger.REFLECTION("Field: Internal Lookup Failed: "+fieldName); final Class<?> superClass = clazz.getSuperclass(); if (superClass == null) { + Logger.REFLECTION("Unable to find field '"+fieldName+"'"); //Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+"."); throw e; } + Logger.REFLECTION("Method: Recursion Lookup: "+fieldName+" - Checking in "+superClass.getName()); //Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+". Trying super class."); return getField_Internal(superClass, fieldName); } @@ -511,7 +518,7 @@ public class ReflectionUtils { } private static void dumpClassInfo(Class aClass) { - Logger.INFO("We ran into an error processing reflection in "+aClass.getCanonicalName()+", dumping all data for debugging."); + Logger.INFO("We ran into an error processing reflection in "+aClass.getName()+", dumping all data for debugging."); // Get the methods Method[] methods = aClass.getDeclaredMethods(); Field[] fields = aClass.getDeclaredFields(); diff --git a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java index 0585eeafd8..6f47909a01 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -30,7 +30,7 @@ public class BaseTinkersMaterial { private final Material mMaterial; static { - aNextFreeID = Short.MAX_VALUE+420; + aNextFreeID = (Short.MAX_VALUE/2)+420; } public BaseTinkersMaterial(Material aMaterial) { diff --git a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index d8c773c014..f0c6d76b7c 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -11,6 +11,7 @@ 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; @@ -23,40 +24,41 @@ 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; - + 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; + + private static Object mSmelteryInstance; + private static Object mTinkersRegistryInstance; private static final HashMap<String, Method> mMethodCache = new LinkedHashMap<String, Method>(); - static { - setRegistries(); - mToolMaterialClass = ReflectionUtils.getClass("tconstruct.library.tools.ToolMaterial"); + 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(mSmelteryClassInstance, "moltenIronFluid"); + 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[] {}); - + mMethod_getCastingRecipes = ReflectionUtils.getMethod(getCastingInstance(0), "getCastingRecipes", new Class[] {}); } @@ -67,65 +69,23 @@ public class TinkersUtils { private static void setTiConDataInstance() { if (!LoadedMods.TiCon) { return; - } - else { - - if (mTinkersRegistryClass == null || mSmelteryClassInstance == null) { - setRegistries(); - } - - // getSmelteryInstance - - //Set Smeltery Instance - if (mSmelteryInstance == null || mSmelteryClassInstance == null) { - if (mSmelteryClassInstance == null) { - mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); + } else { + if (mSmelteryInstance == null) { + if (mClass_Smeltery != null) { + try { + mSmelteryInstance = ReflectionUtils.getField(mClass_Smeltery, "instance").get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { } - if (mSmelteryClassInstance != null) { - try { - mSmelteryInstance = ReflectionUtils.getField(mSmelteryClassInstance, "instance").get(null); - } - catch (IllegalArgumentException | IllegalAccessException e) { - } - } - } - - //Return Smeltery Instance - if (mSmelteryInstance != null) { - //return mSmelteryInstance; } - - - // getTableCastingInstance || getBasinCastingInstance - if (mTinkersRegistryClass == null || mTinkersRegistryInstance == null) { - if (mTinkersRegistryClass == null) { - mTinkersRegistryClass = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); + } + if (mTinkersRegistryInstance == null) { + if (mClass_TConstructRegistry != null) { + try { + mTinkersRegistryInstance = ReflectionUtils.getField(mClass_TConstructRegistry, "instance").get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { } - 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; - } - - } - } - - private static void setRegistries() { - if (mTinkersRegistryClass == null) { - mTinkersRegistryClass = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); - } - if (mSmelteryClassInstance == null) { - mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); + } } } @@ -224,7 +184,7 @@ public class TinkersUtils { 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); + Method m = ReflectionUtils.getMethod(mClass_Smeltery, "addMelting", ItemStack.class, Block.class, int.class, int.class, FluidStack.class); mMethodCache.put("addMelting", m); } try { @@ -237,7 +197,7 @@ public class TinkersUtils { public static boolean addMelting(Object type, ItemStack input, int temperatureDifference, int fluidAmount) { if (mMethodCache.get("addMelting") == null) { - Method m = ReflectionUtils.getMethod(mSmelteryClassInstance, "addMelting", mClass_FluidType, ItemStack.class, int.class, int.class); + Method m = ReflectionUtils.getMethod(mClass_Smeltery, "addMelting", mClass_FluidType, ItemStack.class, int.class, int.class); mMethodCache.put("addMelting", m); } try { @@ -341,7 +301,7 @@ public class TinkersUtils { private static Item mTinkerMetalPattern; public static ItemStack getPattern(int aType) { if (mTinkerMetalPattern == null) { - Field m = ReflectionUtils.getField(ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"), "metalPattern"); + Field m = ReflectionUtils.getField(mClass_TinkerSmeltery, "metalPattern"); if (m != null) { try { mTinkerMetalPattern = (Item) m.get(null); @@ -380,7 +340,7 @@ public class TinkersUtils { */ 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); + 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) { @@ -399,51 +359,47 @@ public class TinkersUtils { - public static void addToolMaterial(int id, Object aToolMaterial) { - setRegistries(); + public static void addToolMaterial(int id, Object aToolMaterial) { if (mMethodCache.get("addToolMaterial") == null) { - Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addtoolMaterial", int.class, mToolMaterialClass); + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addtoolMaterial", int.class, mClass_ToolMaterial); mMethodCache.put("addToolMaterial", m); } try { - mMethodCache.get("addToolMaterial").invoke(mTinkersRegistryClass, id, aToolMaterial); + mMethodCache.get("addToolMaterial").invoke(mClass_TConstructRegistry, id, aToolMaterial); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } } - public static void addDefaultToolPartMaterial(int id) { - setRegistries(); + public static void addDefaultToolPartMaterial(int id) { if (mMethodCache.get("addDefaultToolPartMaterial") == null) { - Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addDefaultToolPartMaterial", int.class); + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addDefaultToolPartMaterial", int.class); mMethodCache.put("addDefaultToolPartMaterial", m); } try { - mMethodCache.get("addDefaultToolPartMaterial").invoke(mTinkersRegistryClass, id); + mMethodCache.get("addDefaultToolPartMaterial").invoke(mClass_TConstructRegistry, id); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } } - public static void addBowMaterial(int id, int drawspeed, float maxSpeed) { - setRegistries(); + public static void addBowMaterial(int id, int drawspeed, float maxSpeed) { if (mMethodCache.get("addBowMaterial") == null) { - Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addBowMaterial", int.class, int.class, float.class); + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addBowMaterial", int.class, int.class, float.class); mMethodCache.put("addBowMaterial", m); } try { - mMethodCache.get("addBowMaterial").invoke(mTinkersRegistryClass, id, drawspeed, maxSpeed); + mMethodCache.get("addBowMaterial").invoke(mClass_TConstructRegistry, id, drawspeed, maxSpeed); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } } - public static void addArrowMaterial(int id, float mass, float fragility) { - setRegistries(); + public static void addArrowMaterial(int id, float mass, float fragility) { if (mMethodCache.get("addArrowMaterial") == null) { - Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addArrowMaterial", int.class, float.class, float.class); + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addArrowMaterial", int.class, float.class, float.class); mMethodCache.put("addArrowMaterial", m); } try { - mMethodCache.get("addArrowMaterial").invoke(mTinkersRegistryClass, id, mass, fragility); + mMethodCache.get("addArrowMaterial").invoke(mClass_TConstructRegistry, id, mass, fragility); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } } @@ -464,29 +420,40 @@ public class TinkersUtils { List newRecipies = new LinkedList(); - if (true) { - Iterator i$ = getTableCastingRecipes().iterator(); - while (i$.hasNext()) { - CastingRecipeHandler recipe = new CastingRecipeHandler(i$.next()); + + Iterator iterator1 = getTableCastingRecipes().iterator(); + Fluid aMoltenIron = null; + if (aMoltenIron == null) { try { - if (recipe.valid && recipe.castingMetal.getFluid() == mField_MoltenIronFluid.get(null) && recipe.cast != null + 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 | IllegalAccessException e) { + } catch (IllegalArgumentException e) { e.printStackTrace(); return false; } } - } - - if (true) { + + Object ft; try { ft = mMethod_getFluidType.invoke(null, aMaterial.getLocalizedName()); - Iterator i$ = newRecipies.iterator(); - while (i$.hasNext()) { - CastingRecipeHandler recipe = new CastingRecipeHandler(i$.next()); + Iterator iterator2 = newRecipies.iterator(); + while (iterator2.hasNext()) { + CastingRecipeHandler recipe = new CastingRecipeHandler(iterator2.next()); if (!recipe.valid){ continue; } @@ -501,7 +468,7 @@ public class TinkersUtils { e.printStackTrace(); return false; } - } + return true; } |