From 9fe3f693f1d6d015f45898818b7958b3a57a9f4a Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Fri, 26 Jul 2019 04:23:36 +0100 Subject: + Added config option to adjust ingame BGM delays. (Should be working) + Added a Pest Killer for quick removal of Butterflies and Bats. + Added Hydrogen Cyanide. % Replaced existing assets for the Bat King. % Replaced Bat King Logic, it's now an offensive mob. $ Fixed Bat King model scaling. --- .../core/util/reflect/ReflectionUtils.java | 38 +++++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/reflect') diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 2371753fe6..efc86122e2 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -25,7 +25,7 @@ import gtPlusPlus.core.util.data.StringUtils; public class ReflectionUtils { - public static Map mCachedClasses = new LinkedHashMap(); + public static Map> mCachedClasses = new LinkedHashMap>(); public static Map mCachedMethods = new LinkedHashMap(); public static Map mCachedFields = new LinkedHashMap(); @@ -69,11 +69,11 @@ public class ReflectionUtils { } - private static boolean cacheClass(Class aClass) { + private static boolean cacheClass(Class aClass) { if (aClass == null) { return false; } - Class y = mCachedClasses.get(aClass.getCanonicalName()); + Class y = mCachedClasses.get(aClass.getCanonicalName()); if (y == null) { mCachedClasses.put(aClass.getCanonicalName(), aClass); return true; @@ -81,7 +81,7 @@ public class ReflectionUtils { return false; } - private static boolean cacheMethod(Class aClass, Method aMethod) { + private static boolean cacheMethod(Class aClass, Method aMethod) { if (aMethod == null) { return false; } @@ -94,7 +94,7 @@ public class ReflectionUtils { return false; } - private static boolean cacheField(Class aClass, Field aField) { + private static boolean cacheField(Class aClass, Field aField) { if (aField == null) { return false; } @@ -113,11 +113,11 @@ public class ReflectionUtils { * @param aClassCanonicalName - The canonical name of the underlying class. * @return - Valid, {@link Class} object, or {@link null}. */ - public static Class getClass(String aClassCanonicalName) { + public static Class getClass(String aClassCanonicalName) { if (aClassCanonicalName == null || aClassCanonicalName.length() <= 0) { return null; } - Class y = mCachedClasses.get(aClassCanonicalName); + Class y = mCachedClasses.get(aClassCanonicalName); if (y == null) { y = getClass_Internal(aClassCanonicalName); if (y != null) { @@ -149,7 +149,7 @@ public class ReflectionUtils { * @param aTypes - Varags Class Types for {@link Method}'s constructor. * @return - Valid, non-final, {@link Method} object, or {@link null}. */ - public static Method getMethod(Class aClass, String aMethodName, Class... aTypes) { + public static Method getMethod(Class aClass, String aMethodName, Class... aTypes) { if (aClass == null || aMethodName == null || aMethodName.length() <= 0) { return null; } @@ -178,7 +178,7 @@ public class ReflectionUtils { * @param aFieldName - Field name in {@link String} form. * @return - Valid, non-final, {@link Field} object, or {@link null}. */ - public static Field getField(final Class aClass, final String aFieldName) { + public static Field getField(final Class aClass, final String aFieldName) { if (aClass == null || aFieldName == null || aFieldName.length() <= 0) { return null; } @@ -662,7 +662,7 @@ public class ReflectionUtils { return m; } - private static Method getMethod_Internal(Class aClass, String aMethodName, Class... aTypes) { + private static Method getMethod_Internal(Class aClass, String aMethodName, Class... aTypes) { Method m = null; try { Logger.REFLECTION("Method: Internal Lookup: "+aMethodName); @@ -704,7 +704,7 @@ public class ReflectionUtils { } } - private static void dumpClassInfo(Class aClass) { + private static void dumpClassInfo(Class aClass) { Logger.INFO("We ran into an error processing reflection in "+aClass.getName()+", dumping all data for debugging."); // Get the methods Method[] methods = aClass.getDeclaredMethods(); @@ -720,7 +720,7 @@ public class ReflectionUtils { System.out.println(f.getName()); } Logger.INFO("Dumping all Constructors."); - for (Constructor c : consts) { + for (Constructor c : consts) { System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+StringUtils.getDataStringFromArray(c.getParameterTypes())); } } @@ -800,4 +800,18 @@ public class ReflectionUtils { } + public static boolean doesFieldExist(String clazz, String string) { + return doesFieldExist(ReflectionUtils.getClass(clazz), string); + } + + public static boolean doesFieldExist(Class clazz, String string) { + if (clazz != null) { + if (ReflectionUtils.getField(clazz, string) != null) { + return true; + } + } + return false; + } + + } -- cgit From 800119d6a1e75ffd0201a9dfc44c53a7604a9f37 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 12 Aug 2019 20:48:13 +0100 Subject: + Added Reliquary support. $ Fixed #527. $ Fixed Sugar Coke Recipe. --- src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/Java/gtPlusPlus/core/util/reflect') diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index efc86122e2..19e42735d7 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -813,5 +813,17 @@ public class ReflectionUtils { return false; } + public static Object getFieldValue(Field field) { + return getFieldValue(field, null); + } + + public static Object getFieldValue(Field field, Object instance) { + try { + return field.get(instance); + } catch (IllegalArgumentException | IllegalAccessException e) { + } + return null; + } + } -- cgit From 8308ff274b114193fed038daf139c9c94329a666 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 15 Aug 2019 01:32:23 +0100 Subject: $ Fixed Dehydrator not properly importing Tinkers drying rack recipes. Fixes #487. $ Fixed Pest Killer not detecting butterflies properly. --- .../core/util/reflect/ReflectionUtils.java | 61 +++++++++++++++++----- 1 file changed, 49 insertions(+), 12 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/reflect') diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 19e42735d7..b52c13c563 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -293,7 +293,7 @@ public class ReflectionUtils { return loaded > 0; } - + public static boolean setField(final Object object, final String fieldName, final Object fieldValue) { Class clazz = object.getClass(); @@ -313,8 +313,8 @@ public class ReflectionUtils { } } return false; - - + + } public static boolean setField(final Object object, final Field field, final Object fieldValue) { @@ -484,11 +484,11 @@ public class ReflectionUtils { * Internal Magic that probably should not get exposed. */ - - - - - + + + + + @@ -767,15 +767,52 @@ public class ReflectionUtils { } private static Class getClass_Internal(String string) { + Class aClass = null; if (ReflectionUtils.doesClassExist(string)) { try { - return Class.forName(string); + aClass = Class.forName(string); } catch (ClassNotFoundException e) { - return getNonPublicClass(string); + aClass = getNonPublicClass(string); } } - return null; + + if (aClass == null) { + String aClassName = ""; + Logger.REFLECTION("Splitting "+string+" to try look for hidden classes."); + String[] aData = string.split("\\."); + Logger.REFLECTION("Obtained "+aData.length+" pieces."); + for (int i=0;i<(aData.length-1);i++) { + aClassName += (i > 0) ? "."+aData[i] : ""+aData[i]; + Logger.REFLECTION("Building: "+aClassName); + } + Logger.REFLECTION("Trying to search '"+aClassName+"' for inner classes."); + Class clazz = ReflectionUtils.getClass(aClassName); + + Class[] y = clazz.getDeclaredClasses(); + if (y == null || y.length <= 0) { + Logger.REFLECTION("No hidden inner classes found."); + return null; + } + else { + boolean found = false; + for (Class h : y) { + Logger.REFLECTION("Found hidden inner class: "+h.getCanonicalName()); + if (h.getSimpleName().toLowerCase().equals(aData[aData.length-1].toLowerCase())) { + Logger.REFLECTION("Found correct class. ["+aData[aData.length-1]+"] Caching at correct location: "+string); + Logger.REFLECTION("Found at location: "+h.getCanonicalName()); + ReflectionUtils.mCachedClasses.put(string, h); + aClass = h; + found = true; + break; + } + } + if (!found) { + return null; + } + } + } + return aClass; } /** @@ -803,7 +840,7 @@ public class ReflectionUtils { public static boolean doesFieldExist(String clazz, String string) { return doesFieldExist(ReflectionUtils.getClass(clazz), string); } - + public static boolean doesFieldExist(Class clazz, String string) { if (clazz != null) { if (ReflectionUtils.getField(clazz, string) != null) { -- cgit From ab84b1d95f8c4880891debc594a41f57941de78a Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 10 Oct 2019 17:45:37 +0100 Subject: + Added some new functions to ReflectionUtils.java. + Added an alternative way to Obtain Blizz rods, dust and Cryotheum dust if GalaxySpace is loaded. Closes #557. $ Fixed bug in DecayableRecipeHandler.java. $ Fixed instance where I was directly referencing forestry code. $ Rewrote how canning/uncanning recipes are handled, hopefully fixes the corruption of the recipe map. > I potentially broke some of my own canning recipes, so be aware of any missing and let me know. --- .../core/util/reflect/ReflectionUtils.java | 44 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/reflect') diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index b52c13c563..7ef9ef6632 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -169,6 +169,17 @@ public class ReflectionUtils { return y.get(); } } + + public static boolean isStaticMethod(Class aClass, String aMethodName, Class... aTypes) { + return isStaticMethod(ReflectionUtils.getMethod(aClass, aMethodName, aTypes)); + } + + public static boolean isStaticMethod(Method aMethod) { + if (aMethod != null && Modifier.isStatic(aMethod.getModifiers())) { + return true; + } + return false; + } @@ -381,13 +392,34 @@ public class ReflectionUtils { public static boolean invoke(Object objectInstance, String methodName, Class[] parameters, Object[] values){ if (objectInstance == null || methodName == null || parameters == null || values == null){ - //Logger.REFLECTION("Null value when trying to Dynamically invoke "+methodName+" on an object of type: "+objectInstance.getClass().getName()); return false; } Class mLocalClass = (objectInstance instanceof Class ? (Class) objectInstance : objectInstance.getClass()); Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+mLocalClass.getCanonicalName()+"."); try { Method mInvokingMethod = mLocalClass.getDeclaredMethod(methodName, parameters); + if (mInvokingMethod != null){ + return invoke(objectInstance, mInvokingMethod, values); + } + } + catch (NoSuchMethodException | SecurityException | IllegalArgumentException e) { + Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+mLocalClass.getName()); + } + + Logger.REFLECTION("Invoke failed or did something wrong."); + return false; + } + + public static boolean invoke(Object objectInstance, Method method, Object[] values){ + if (method == null || values == null || (!ReflectionUtils.isStaticMethod(method) && objectInstance == null)){ + //Logger.REFLECTION("Null value when trying to Dynamically invoke "+methodName+" on an object of type: "+objectInstance.getClass().getName()); + return false; + } + String methodName = method.getName(); + String classname = objectInstance != null ? objectInstance.getClass().getCanonicalName() : method.getDeclaringClass().getCanonicalName(); + Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+classname+"."); + try { + Method mInvokingMethod = method; if (mInvokingMethod != null){ Logger.REFLECTION(methodName+" was not null."); if ((boolean) mInvokingMethod.invoke(objectInstance, values)){ @@ -398,14 +430,10 @@ public class ReflectionUtils { Logger.REFLECTION("Invocation failed for "+methodName+"."); } } - else { - Logger.REFLECTION(methodName+" is null."); - } } - catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+mLocalClass.getName()); - } - + catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+classname); + } Logger.REFLECTION("Invoke failed or did something wrong."); return false; } -- cgit From 1fe377e10ef32f3e54e0d152f64c67eaebef1993 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 24 Oct 2019 02:09:32 +0100 Subject: + Added burn times for Wooden Pellets & Bricks. % Many minor Bio recipe adjustments. $ Fixed Oredict name of some Fluid Cells, advise if this breaks existing recipes. (Probably look at Alkalus ingots) --- src/Java/gtPlusPlus/core/util/reflect/OreDictUtils.java | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/Java/gtPlusPlus/core/util/reflect/OreDictUtils.java (limited to 'src/Java/gtPlusPlus/core/util/reflect') diff --git a/src/Java/gtPlusPlus/core/util/reflect/OreDictUtils.java b/src/Java/gtPlusPlus/core/util/reflect/OreDictUtils.java deleted file mode 100644 index 6d34733545..0000000000 --- a/src/Java/gtPlusPlus/core/util/reflect/OreDictUtils.java +++ /dev/null @@ -1,7 +0,0 @@ -package gtPlusPlus.core.util.reflect; - -public class OreDictUtils { - - - -} -- cgit From b8069dc5a8c0c8c2cfd5e4ec2401f28d6a84e626 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 12 Dec 2019 02:26:10 +0000 Subject: + Added Pellet Mold. + Added Clean Aluminium Mix. $ 5.08 Compliance. And looooots of it. $ Fixed most, if not all Fluid Canning & Extraction recipes that I broke previously. % Adjusted Textures for Particles. New textures thanks to Discord User Никита#8621. % Adjusted Aluminium Processing Chain. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/util/reflect/ReflectionUtils.java | 113 ++++++++++++++++++++- 1 file changed, 110 insertions(+), 3 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/reflect') diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 7ef9ef6632..135f98dd17 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -28,7 +28,22 @@ public class ReflectionUtils { public static Map> mCachedClasses = new LinkedHashMap>(); public static Map mCachedMethods = new LinkedHashMap(); public static Map mCachedFields = new LinkedHashMap(); + public static Map mCachedConstructors = new LinkedHashMap(); + private static class CachedConstructor { + + private final Constructor METHOD; + + public CachedConstructor(Constructor aCons) { + METHOD = aCons; + } + + public Constructor get() { + return METHOD; + } + + } + private static class CachedMethod { private final boolean STATIC; @@ -107,6 +122,49 @@ public class ReflectionUtils { return false; } + private static boolean cacheConstructor(Class aClass, Constructor aConstructor) { + if (aConstructor == null) { + return false; + } + CachedConstructor y = mCachedConstructors.get(aClass.getName()+"."+ArrayUtils.toString(aConstructor.getParameterTypes())); + if (y == null) { + mCachedConstructors.put(aClass.getName()+"."+ArrayUtils.toString(aConstructor.getParameterTypes()), new CachedConstructor(aConstructor)); + return true; + } + return false; + } + + + /** + * Returns a cached {@link Constructor} object. + * @param aClass - Class containing the Constructor. + * @param aTypes - Varags Class Types for objects constructor. + * @return - Valid, non-final, {@link Method} object, or {@link null}. + */ + public static Constructor getConstructor(Class aClass, Class... aTypes) { + if (aClass == null || aTypes == null) { + return null; + } + + String aMethodKey = ArrayUtils.toString(aTypes); + //Logger.REFLECTION("Looking up method in cache: "+(aClass.getName()+"."+aMethodName + "." + aMethodKey)); + CachedConstructor y = mCachedConstructors.get(aClass.getName() + "." + aMethodKey); + if (y == null) { + Constructor u = getConstructor_Internal(aClass, aTypes); + if (u != null) { + Logger.REFLECTION("Caching Constructor: "+aClass.getName() + "." + aMethodKey); + cacheConstructor(aClass, u); + return u; + } else { + return null; + } + } else { + return y.get(); + } + } + + + /** * Returns a cached {@link Class} object. @@ -716,6 +774,55 @@ public class ReflectionUtils { } return m; } + + private static Constructor getConstructor_Internal(Class aClass, Class... aTypes) { + Constructor c = null; + try { + Logger.REFLECTION("Constructor: Internal Lookup: "+aClass.getName()); + c = aClass.getDeclaredConstructor(aTypes); + if (c != null) { + c.setAccessible(true); + int modifiers = c.getModifiers(); + Field modifierField = c.getClass().getDeclaredField("modifiers"); + modifiers = modifiers & ~Modifier.FINAL; + modifierField.setAccessible(true); + modifierField.setInt(c, modifiers); + } + } + catch (Throwable t) { + Logger.REFLECTION("Constructor: Internal Lookup Failed: "+aClass.getName()); + try { + c = getConstructorRecursively(aClass, aTypes); + } catch (Exception e) { + Logger.REFLECTION("Unable to find method '"+aClass.getName()+"'"); + e.printStackTrace(); + dumpClassInfo(aClass); + } + } + return c; + } + + private static Constructor getConstructorRecursively(Class aClass, Class... aTypes) throws Exception { + try { + Logger.REFLECTION("Constructor: Recursion Lookup: "+aClass.getName()); + Constructor c = aClass.getConstructor(aTypes); + if (c != null) { + c.setAccessible(true); + int modifiers = c.getModifiers(); + Field modifierField = c.getClass().getDeclaredField("modifiers"); + modifiers = modifiers & ~Modifier.FINAL; + modifierField.setAccessible(true); + modifierField.setInt(c, modifiers); + } + return c; + } catch (final NoSuchMethodException | IllegalArgumentException | IllegalAccessException e) { + final Class superClass = aClass.getSuperclass(); + if (superClass == null || superClass == Object.class) { + throw e; + } + return getConstructor_Internal(superClass, aTypes); + } + } private static Method getMethodRecursively(final Class clazz, final String aMethodName) throws NoSuchMethodException { try { @@ -795,7 +902,7 @@ public class ReflectionUtils { } private static Class getClass_Internal(String string) { - Class aClass = null; + Class aClass = null; if (ReflectionUtils.doesClassExist(string)) { try { aClass = Class.forName(string); @@ -815,7 +922,7 @@ public class ReflectionUtils { Logger.REFLECTION("Building: "+aClassName); } Logger.REFLECTION("Trying to search '"+aClassName+"' for inner classes."); - Class clazz = ReflectionUtils.getClass(aClassName); + Class clazz = ReflectionUtils.getClass(aClassName); Class[] y = clazz.getDeclaredClasses(); if (y == null || y.length <= 0) { @@ -824,7 +931,7 @@ public class ReflectionUtils { } else { boolean found = false; - for (Class h : y) { + for (Class h : y) { Logger.REFLECTION("Found hidden inner class: "+h.getCanonicalName()); if (h.getSimpleName().toLowerCase().equals(aData[aData.length-1].toLowerCase())) { Logger.REFLECTION("Found correct class. ["+aData[aData.length-1]+"] Caching at correct location: "+string); -- cgit