Class RuntimeEnumExtender
java.lang.Object
net.neoforged.fml.common.asm.enumextension.RuntimeEnumExtender
- All Implemented Interfaces:
ClassProcessor
Transforms enums implementing
IExtensibleEnum to add additional entries loaded from files provided by mods-
Nested Class Summary
Nested classes/interfaces inherited from interface net.neoforged.neoforgespi.transformation.ClassProcessor
ClassProcessor.AfterProcessingContext, ClassProcessor.ComputeFlags, ClassProcessor.LinkContext, ClassProcessor.OrderingHint, ClassProcessor.SelectionContext, ClassProcessor.TransformationContext -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final Typeprivate static final intprivate static final Typeprivate static final Typeprivate static final Stringprivate static final intprivate static final Stringprivate static final Typeprivate static final Typeprivate static final Typeprivate static final Typeprivate static final Typeprivate static final Typeprivate static Map<String, List<EnumPrototype>> private static final TypeFields inherited from interface net.neoforged.neoforgespi.transformation.ClassProcessor
GENERATED_PACKAGE_MODULE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidappendValuesArray(Type classType, ListGeneratorAdapter generator, List<FieldNode> enumEntries) private static voidbuildExtensionInfo(ClassNode classNode, Type classType, ListGeneratorAdapter generator, FieldNode infoField, int vanillaCount, int moddedCount) private static voidclearMethod(MethodNode mth) createEnumEntries(Type classType, ListGeneratorAdapter generator, Set<String> ctors, int idParamIdx, int nameParamIdx, int vanillaEntryCount, List<EnumPrototype> prototypes) private static FieldNodestatic AbstractInsnNodefindFirstInstructionBefore(MethodNode method, int opCode, int startIndex) Finds the first instruction with matching opcode before the given index in reverse searchstatic MethodInsnNodefindFirstStaticMethodCall(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 MethodNodefindMethod(ClassNode classNode, Predicate<MethodNode> predicate) private static AbstractInsnNodefindValuesArrayCreation(Type classType, MethodNode clinit) private static FieldInsnNodefindValuesArrayStore(Type classType, ClassNode classNode, MethodNode mth, String owner) private static intgetParameterIndexFromAnnotation(ClassNode classNode, Type annoType) private static intgetVanillaEntryCount(ClassNode classNode, Type classType) booleanReturns whether the processor wants to recieve the class.private static booleanprivate static voidloadConstructorParams(ListGeneratorAdapter generator, int idParamIdx, int nameParamIdx, int ordinal, EnumPrototype proto) static voidloadEnumPrototypes(Map<IModInfo, JarResource> paths) name()Returns a unique identifier for this processor.Returns a hint for how this processor should be ordered relative to other processors.Each class that the processor has opted to recieve is passed to this method for processing.private static voidreturnValuesToExtender(Type classType, ListGeneratorAdapter generator, List<EnumPrototype> protos, List<FieldNode> entries) Returns processors that this processor must run before.private static Optional<MethodNode> tryFindMethod(ClassNode classNode, Predicate<MethodNode> predicate) static StringvalidateNameParameter(String fieldName, String owningMod) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.neoforged.neoforgespi.transformation.ClassProcessor
afterProcessing, generatesPackages, link, runsAfter
-
Field Details
-
MARKER_IFACE
-
INDEXED_ANNOTATION
-
NAMED_ANNOTATION
-
RESERVED_ANNOTATION
-
ENUM_PROXY
-
NET_CHECK
-
EXT_INFO
-
EXT_INFO_GETTER_DESC
-
EXT_INFO_CTOR_DESC
-
NETWORKED_ANNOTATION
-
EXTENDER
-
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:ClassProcessorReturns a unique identifier for this processor.- Specified by:
namein interfaceClassProcessor- Returns:
- a unique identifier for this processor
-
runsBefore
Description copied from interface:ClassProcessorReturns processors that this processor must run before.- Specified by:
runsBeforein interfaceClassProcessor- Returns:
- processors that this processor must run before
-
orderingHint
Description copied from interface:ClassProcessorReturns a hint for how this processor should be ordered relative to other processors. Note that this is a comparatively weak hint;ClassProcessor.runsBefore()andClassProcessor.runsAfter()take precedence, and processors don't have "phases" of any sort.- Specified by:
orderingHintin interfaceClassProcessor- Returns:
- a hint for how this processor should be ordered relative to other processors
-
handlesClass
Description copied from interface:ClassProcessorReturns whether the processor wants to recieve the class.- Specified by:
handlesClassin interfaceClassProcessor- Parameters:
context- the context of the class to consider- Returns:
- whether the processor wants to recieve the class
-
processClass
Description copied from interface:ClassProcessorEach class that the processor has opted to recieve is passed to this method for processing.- Specified by:
processClassin interfaceClassProcessor- Parameters:
context- the context of the class to process- Returns:
- the
ClassProcessor.ComputeFlagsindicating how the class should be rewritten.
-
findFirstStaticMethodCall
public static MethodInsnNode findFirstStaticMethodCall(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 AbstractInsnNode findFirstInstructionBefore(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
private static Optional<MethodNode> tryFindMethod(ClassNode classNode, Predicate<MethodNode> predicate) -
findMethod
-
findField
-
clearMethod
-
getVanillaEntryCount
-
getParameterIndexFromAnnotation
-
isAllowedConstructor
-
findValuesArrayCreation
-
findValuesArrayStore
private static FieldInsnNode findValuesArrayStore(Type classType, ClassNode classNode, MethodNode mth, String owner) -
createEnumEntries
private static List<FieldNode> createEnumEntries(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(ClassNode classNode, Type classType, ListGeneratorAdapter generator, FieldNode infoField, int vanillaCount, int moddedCount) -
returnValuesToExtender
private static void returnValuesToExtender(Type classType, ListGeneratorAdapter generator, List<EnumPrototype> protos, List<FieldNode> entries) -
appendValuesArray
private static void appendValuesArray(Type classType, ListGeneratorAdapter generator, List<FieldNode> enumEntries) -
loadEnumPrototypes
-
validateNameParameter
-