Class RuntimeEnumExtender
java.lang.Object
net.neoforged.fml.common.asm.enumextension.RuntimeEnumExtender
- All Implemented Interfaces:
ILaunchPluginService
Transforms enums implementing
IExtensibleEnum
to add additional entries loaded from files provided by mods-
Nested Class Summary
Nested classes/interfaces inherited from interface cpw.mods.modlauncher.serviceapi.ILaunchPluginService
ILaunchPluginService.ComputeFlags, ILaunchPluginService.ITransformerLoader, ILaunchPluginService.Phase
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final org.objectweb.asm.Type
private static final int
private static final org.objectweb.asm.Type
private static final org.objectweb.asm.Type
private static final String
private static final int
private static final String
private static final org.objectweb.asm.Type
private static final org.objectweb.asm.Type
private static final org.objectweb.asm.Type
private static final org.objectweb.asm.Type
private static final EnumSet
<ILaunchPluginService.Phase> private static final org.objectweb.asm.Type
private static final org.objectweb.asm.Type
private static Map
<String, List<EnumPrototype>> private static final org.objectweb.asm.Type
private static final EnumSet
<ILaunchPluginService.Phase> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
appendValuesArray
(org.objectweb.asm.Type classType, ListGeneratorAdapter generator, List<org.objectweb.asm.tree.FieldNode> enumEntries) 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) private static void
clearMethod
(org.objectweb.asm.tree.MethodNode mth) 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) private static org.objectweb.asm.tree.FieldNode
findField
(org.objectweb.asm.tree.ClassNode classNode, Predicate<org.objectweb.asm.tree.FieldNode> predicate) 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 searchstatic 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 descriptorprivate static org.objectweb.asm.tree.MethodNode
findMethod
(org.objectweb.asm.tree.ClassNode classNode, Predicate<org.objectweb.asm.tree.MethodNode> predicate) private static org.objectweb.asm.tree.AbstractInsnNode
findValuesArrayCreation
(org.objectweb.asm.Type classType, org.objectweb.asm.tree.MethodNode clinit) 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) private static int
getParameterIndexFromAnnotation
(org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.Type annoType) private static int
getVanillaEntryCount
(org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.Type classType) handlesClass
(org.objectweb.asm.Type classType, boolean isEmpty) If this plugin wants to receive theClassNode
intoILaunchPluginService.processClass(cpw.mods.modlauncher.serviceapi.ILaunchPluginService.Phase, org.objectweb.asm.tree.ClassNode, org.objectweb.asm.Type)
private static boolean
isAllowedConstructor
(org.objectweb.asm.tree.MethodNode mth) private static void
loadConstructorParams
(ListGeneratorAdapter generator, int idParamIdx, int nameParamIdx, int ordinal, EnumPrototype proto) static void
loadEnumPrototypes
(Map<IModInfo, Path> paths) name()
The name of this plugin.boolean
processClass
(ILaunchPluginService.Phase phase, org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.Type classType) Each class loaded is offered to the plugin for processing.private static void
returnValuesToExtender
(org.objectweb.asm.Type classType, ListGeneratorAdapter generator, List<EnumPrototype> protos, List<org.objectweb.asm.tree.FieldNode> entries) private static Optional
<org.objectweb.asm.tree.MethodNode> tryFindMethod
(org.objectweb.asm.tree.ClassNode classNode, Predicate<org.objectweb.asm.tree.MethodNode> predicate) static String
validateNameParameter
(String fieldName, String owningMod) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface cpw.mods.modlauncher.serviceapi.ILaunchPluginService
addResources, customAuditConsumer, getExtension, handlesClass, initializeLaunch, offerResource, processClass, processClassWithFlags
-
Field Details
-
YAY
-
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
-
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
-
-
Constructor Details
-
RuntimeEnumExtender
public RuntimeEnumExtender()
-
-
Method Details
-
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 interfaceILaunchPluginService
- Returns:
- the name of the plugin
-
handlesClass
public EnumSet<ILaunchPluginService.Phase> handlesClass(org.objectweb.asm.Type classType, boolean isEmpty) Description copied from interface:ILaunchPluginService
If this plugin wants to receive theClassNode
intoILaunchPluginService.processClass(cpw.mods.modlauncher.serviceapi.ILaunchPluginService.Phase, org.objectweb.asm.tree.ClassNode, org.objectweb.asm.Type)
- Specified by:
handlesClass
in interfaceILaunchPluginService
- Parameters:
classType
- the class to considerisEmpty
- 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 ofILaunchPluginService.processClass(Phase, ClassNode, Type)
,ILaunchPluginService.processClass(Phase, ClassNode, Type, String)
orILaunchPluginService.processClassWithFlags(Phase, ClassNode, Type, String)
must be implemented.- Specified by:
processClass
in interfaceILaunchPluginService
- Parameters:
phase
- The phase of the supplied class nodeclassNode
- the classnode to processclassType
- 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 inowner
- the method call's owner to search forname
- the method call's namedescriptor
- 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 inopCode
- the opcode to search forstartIndex
- the index at which to start searching (inclusive)- Returns:
- the found instruction node or null if none matched before the given startIndex
-
tryFindMethod
-
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
-
validateNameParameter
-