Package me.tamkungz.nilkit.helper
Class ReflectHelper
java.lang.Object
me.tamkungz.nilkit.helper.ReflectHelper
ReflectHelper — utility wrapper for common reflection operations.
Reduces repeated use of getField/invoke patterns across mods.
-
Method Summary
Modifier and TypeMethodDescriptioncollectFieldValuesByType(Object target, Class<?> assignableFrom, boolean skipStatic) Collects field values whose type is assignable to the given class.static Fieldstatic ObjectfindFieldByClassHint(Object target, String... hints) Finds a field value whose type matches any of the given class name hints.static booleangetBooleanField(Object target, String name) static doublegetDoubleField(Object target, String name) static doublegetDoubleFieldSafe(Object target, String name) static ObjectGets a field value from an object (searches superclass hierarchy).static ObjectgetFieldSafe(Object target, String name) Safe field access — returns null on error.static floatgetFloatField(Object target, String name) static intgetIntField(Object target, String name) static intgetIntFieldSafe(Object target, String name, int fallback) static ObjectInvokes a method on the target object using varargs.static ObjectinvokeSafe(Object target, String name, Object... args) Safe method invocation — returns null on error.static booleanisInstanceOf(Object obj, String... classNames) Checks if the object is an instance of any given class names (including superclass hierarchy).static voidsetBooleanField(Object target, String name, boolean value) static voidstatic voidsetFieldMulti(Object target, Object value, String... names) Attempts to set a field using multiple possible names.static voidsetIntField(Object target, String name, int value) static voidsetIntFieldMulti(Object target, int value, String... names)
-
Method Details
-
getField
Gets a field value from an object (searches superclass hierarchy).- Throws:
Exception
-
getIntField
- Throws:
Exception
-
getDoubleField
- Throws:
Exception
-
getFloatField
- Throws:
Exception
-
getBooleanField
- Throws:
Exception
-
getFieldSafe
Safe field access — returns null on error. -
getIntFieldSafe
-
getDoubleFieldSafe
-
setField
- Throws:
Exception
-
setIntField
- Throws:
Exception
-
setBooleanField
- Throws:
Exception
-
setFieldMulti
Attempts to set a field using multiple possible names. Useful for handling obfuscated field name variations. -
setIntFieldMulti
-
invoke
Invokes a method on the target object using varargs. Matches by method name and parameter count.- Throws:
Exception
-
invokeSafe
Safe method invocation — returns null on error. -
isInstanceOf
Checks if the object is an instance of any given class names (including superclass hierarchy). Useful for obfuscated class names (e.g. "qx" = EntityPlayer). -
findFieldByClassHint
Finds a field value whose type matches any of the given class name hints. -
collectFieldValuesByType
public static List<Object> collectFieldValuesByType(Object target, Class<?> assignableFrom, boolean skipStatic) Collects field values whose type is assignable to the given class. -
findField
- Throws:
NoSuchFieldException
-