Class RuntimeEnumExtender

java.lang.Object
net.neoforged.fml.common.asm.enumextension.RuntimeEnumExtender
All Implemented Interfaces:
ILaunchPluginService

@Internal public class RuntimeEnumExtender extends Object implements ILaunchPluginService
Transforms enums implementing IExtensibleEnum to add additional entries loaded from files provided by mods
  • Field Details

    • YAY

      private static final EnumSet<ILaunchPluginService.Phase> YAY
    • NAY

      private static final EnumSet<ILaunchPluginService.Phase> NAY
    • MARKER_IFACE

      private static final org.objectweb.asm.Type MARKER_IFACE
    • INDEXED_ANNOTATION

      private static final org.objectweb.asm.Type INDEXED_ANNOTATION
    • NAMED_ANNOTATION

      private static final org.objectweb.asm.Type NAMED_ANNOTATION
    • RESERVED_ANNOTATION

      private static final org.objectweb.asm.Type RESERVED_ANNOTATION
    • ENUM_PROXY

      private static final org.objectweb.asm.Type ENUM_PROXY
    • NET_CHECK

      private static final org.objectweb.asm.Type NET_CHECK
    • EXT_INFO

      private static final org.objectweb.asm.Type EXT_INFO
    • EXT_INFO_GETTER_DESC

      private static final String EXT_INFO_GETTER_DESC
    • EXT_INFO_CTOR_DESC

      private static final String EXT_INFO_CTOR_DESC
    • NETWORKED_ANNOTATION

      private static final org.objectweb.asm.Type NETWORKED_ANNOTATION
    • EXTENDER

      private static final org.objectweb.asm.Type EXTENDER
    • ARRAYS

      private static final org.objectweb.asm.Type ARRAYS
    • ENUM_FLAGS

      private static final int ENUM_FLAGS
      See Also:
    • ARRAY_FLAGS

      private static final int ARRAY_FLAGS
      See Also:
    • EXT_INFO_FLAGS

      private static final int EXT_INFO_FLAGS
      See Also:
    • prototypes

      private static Map<String,List<EnumPrototype>> prototypes
  • Constructor Details

    • RuntimeEnumExtender

      public RuntimeEnumExtender()
  • Method Details

    • name

      public String name()
      Description copied from interface: ILaunchPluginService
      The name of this plugin. Must be unique. Multiple plugins by the same name will result in a hard exit. Launcher and other systems will rely on this name to find services provided by this plugin, so it should be stable.
      Specified by:
      name in interface ILaunchPluginService
      Returns:
      the name of the plugin
    • handlesClass

      public EnumSet<ILaunchPluginService.Phase> handlesClass(org.objectweb.asm.Type classType, boolean isEmpty)
      Description copied from interface: ILaunchPluginService
      Specified by:
      handlesClass in interface ILaunchPluginService
      Parameters:
      classType - the class to consider
      isEmpty - if the class is empty at present (indicates no backing file found)
      Returns:
      the set of Phases the plugin wishes to be called back with
    • processClass

      public boolean processClass(ILaunchPluginService.Phase phase, org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.Type classType)
      Description copied from interface: ILaunchPluginService
      Each class loaded is offered to the plugin for processing. Ordering between plugins is not known. One of ILaunchPluginService.processClass(Phase, ClassNode, Type), ILaunchPluginService.processClass(Phase, ClassNode, Type, String) or ILaunchPluginService.processClassWithFlags(Phase, ClassNode, Type, String) must be implemented.
      Specified by:
      processClass in interface ILaunchPluginService
      Parameters:
      phase - The phase of the supplied class node
      classNode - the classnode to process
      classType - the name of the class
      Returns:
      true if the classNode needs rewriting using COMPUTE_FRAMES or false if it needs no NO_REWRITE
    • findFirstStaticMethodCall

      public static org.objectweb.asm.tree.MethodInsnNode findFirstStaticMethodCall(org.objectweb.asm.tree.MethodNode method, String owner, String name, String descriptor)
      Finds the first static method call in the given method matching the given owner, name and descriptor
      Parameters:
      method - the method to search in
      owner - the method call's owner to search for
      name - the method call's name
      descriptor - the method call's descriptor
      Returns:
      the found method call node, null if none matched after the given index
    • findFirstInstructionBefore

      public static org.objectweb.asm.tree.AbstractInsnNode findFirstInstructionBefore(org.objectweb.asm.tree.MethodNode method, int opCode, int startIndex)
      Finds the first instruction with matching opcode before the given index in reverse search
      Parameters:
      method - the method to search in
      opCode - the opcode to search for
      startIndex - the index at which to start searching (inclusive)
      Returns:
      the found instruction node or null if none matched before the given startIndex
    • tryFindMethod

      private static Optional<org.objectweb.asm.tree.MethodNode> tryFindMethod(org.objectweb.asm.tree.ClassNode classNode, Predicate<org.objectweb.asm.tree.MethodNode> predicate)
    • findMethod

      private static org.objectweb.asm.tree.MethodNode findMethod(org.objectweb.asm.tree.ClassNode classNode, Predicate<org.objectweb.asm.tree.MethodNode> predicate)
    • findField

      private static org.objectweb.asm.tree.FieldNode findField(org.objectweb.asm.tree.ClassNode classNode, Predicate<org.objectweb.asm.tree.FieldNode> predicate)
    • clearMethod

      private static void clearMethod(org.objectweb.asm.tree.MethodNode mth)
    • getVanillaEntryCount

      private static int getVanillaEntryCount(org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.Type classType)
    • getParameterIndexFromAnnotation

      private static int getParameterIndexFromAnnotation(org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.Type annoType)
    • isAllowedConstructor

      private static boolean isAllowedConstructor(org.objectweb.asm.tree.MethodNode mth)
    • findValuesArrayCreation

      private static org.objectweb.asm.tree.AbstractInsnNode findValuesArrayCreation(org.objectweb.asm.Type classType, org.objectweb.asm.tree.MethodNode clinit)
    • findValuesArrayStore

      private static org.objectweb.asm.tree.FieldInsnNode findValuesArrayStore(org.objectweb.asm.Type classType, org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.tree.MethodNode mth, String owner)
    • createEnumEntries

      private static List<org.objectweb.asm.tree.FieldNode> createEnumEntries(org.objectweb.asm.Type classType, ListGeneratorAdapter generator, Set<String> ctors, int idParamIdx, int nameParamIdx, int vanillaEntryCount, List<EnumPrototype> prototypes)
    • loadConstructorParams

      private static void loadConstructorParams(ListGeneratorAdapter generator, int idParamIdx, int nameParamIdx, int ordinal, EnumPrototype proto)
    • buildExtensionInfo

      private static void buildExtensionInfo(org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.Type classType, ListGeneratorAdapter generator, org.objectweb.asm.tree.FieldNode infoField, int vanillaCount, int moddedCount)
    • returnValuesToExtender

      private static void returnValuesToExtender(org.objectweb.asm.Type classType, ListGeneratorAdapter generator, List<EnumPrototype> protos, List<org.objectweb.asm.tree.FieldNode> entries)
    • appendValuesArray

      private static void appendValuesArray(org.objectweb.asm.Type classType, ListGeneratorAdapter generator, List<org.objectweb.asm.tree.FieldNode> enumEntries)
    • loadEnumPrototypes

      public static void loadEnumPrototypes(Map<IModInfo,Path> paths)
    • validateNameParameter

      public static String validateNameParameter(String fieldName, String owningMod)