Class ReflectHelper

java.lang.Object
me.tamkungz.nilkit.helper.ReflectHelper

public final class ReflectHelper extends Object
ReflectHelper — utility wrapper for common reflection operations. Reduces repeated use of getField/invoke patterns across mods.
  • Method Details

    • getField

      public static Object getField(Object target, String name) throws Exception
      Gets a field value from an object (searches superclass hierarchy).
      Throws:
      Exception
    • getIntField

      public static int getIntField(Object target, String name) throws Exception
      Throws:
      Exception
    • getDoubleField

      public static double getDoubleField(Object target, String name) throws Exception
      Throws:
      Exception
    • getFloatField

      public static float getFloatField(Object target, String name) throws Exception
      Throws:
      Exception
    • getBooleanField

      public static boolean getBooleanField(Object target, String name) throws Exception
      Throws:
      Exception
    • getFieldSafe

      public static Object getFieldSafe(Object target, String name)
      Safe field access — returns null on error.
    • getIntFieldSafe

      public static int getIntFieldSafe(Object target, String name, int fallback)
    • getDoubleFieldSafe

      public static double getDoubleFieldSafe(Object target, String name)
    • setField

      public static void setField(Object target, String name, Object value) throws Exception
      Throws:
      Exception
    • setIntField

      public static void setIntField(Object target, String name, int value) throws Exception
      Throws:
      Exception
    • setBooleanField

      public static void setBooleanField(Object target, String name, boolean value) throws Exception
      Throws:
      Exception
    • setFieldMulti

      public static void setFieldMulti(Object target, Object value, String... names)
      Attempts to set a field using multiple possible names. Useful for handling obfuscated field name variations.
    • setIntFieldMulti

      public static void setIntFieldMulti(Object target, int value, String... names)
    • invoke

      public static Object invoke(Object target, String name, Object... args) throws Exception
      Invokes a method on the target object using varargs. Matches by method name and parameter count.
      Throws:
      Exception
    • invokeSafe

      public static Object invokeSafe(Object target, String name, Object... args)
      Safe method invocation — returns null on error.
    • isInstanceOf

      public static boolean isInstanceOf(Object obj, String... classNames)
      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

      public static Object findFieldByClassHint(Object target, String... hints)
      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

      public static Field findField(Class<?> type, String name) throws NoSuchFieldException
      Throws:
      NoSuchFieldException