Package net.neoforged.neoforge.coremods
Class ReplaceFieldWithGetterAccess
java.lang.Object
net.neoforged.neoforge.coremods.ReplaceFieldWithGetterAccess
- All Implemented Interfaces:
ITransformer<ClassNode>
Replaces direct field access in a class with access to the getter.
The field specified by fieldName must be private and non-static. The method-call the field-access is redirected to does not take any parameters and returns an object of the same type as the field. If no methodName is passed, any method matching the described signature will be used as callable method.
-
Nested Class Summary
Nested classes/interfaces inherited from interface cpw.mods.modlauncher.api.ITransformer
ITransformer.Target<T> -
Field Summary
FieldsFields inherited from interface cpw.mods.modlauncher.api.ITransformer
DEFAULT_LABEL -
Constructor Summary
ConstructorsConstructorDescriptionReplaceFieldWithGetterAccess(String className, Map<String, String> fieldToMethod) -
Method Summary
Modifier and TypeMethodDescriptioncastVote(ITransformerVotingContext context) Return theTransformerVoteResultfor this transformer.private static voidredirectFieldToMethod(ClassNode classNode, String fieldName, @Nullable String methodName) targets()Return a set ofITransformer.Targetidentifying which elements this transformer wishes to try and apply to.transform(ClassNode input, ITransformerVotingContext context) Transform the input to the ITransformer's desire.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface cpw.mods.modlauncher.api.ITransformer
labels
-
Field Details
-
fieldToMethod
-
targets
-
-
Constructor Details
-
ReplaceFieldWithGetterAccess
-
-
Method Details
-
getTargetType
- Specified by:
getTargetTypein interfaceITransformer<ClassNode>
-
targets
Description copied from interface:ITransformerReturn a set ofITransformer.Targetidentifying which elements this transformer wishes to try and apply to. TheITransformer.getTargetType()must match the T variable for the transformer as documented inTargetType, other combinations will be rejected.- Specified by:
targetsin interfaceITransformer<ClassNode>- Returns:
- The set of targets this transformer wishes to apply to
-
transform
Description copied from interface:ITransformerTransform the input to the ITransformer's desire. The context from the last vote is provided as well.- Specified by:
transformin interfaceITransformer<ClassNode>- Parameters:
input- The ASM input node, which can be mutated directlycontext- The voting context- Returns:
- An ASM node of the same type as that supplied. It will be used for subsequent rounds of voting.
-
castVote
Description copied from interface:ITransformerReturn theTransformerVoteResultfor this transformer. The transformer should evaluate whether or not is is a candidate to apply during the round of voting in progress, represented by the context parameter. How the vote works:- If the transformer wishes to be a candidate, it should return
TransformerVoteResult.YES. - If the transformer wishes to exit the voting (the transformer has already
has its intended change applied, for example), it should return
TransformerVoteResult.NO - If the transformer wishes to wait for future rounds of voting it should return
TransformerVoteResult.DEFER. Note that if there is no YES candidate, but DEFER candidates remain, this is a DEFERRAL stalemate and the game will crash. - If the transformer wishes to crash the game, it should return
TransformerVoteResult.REJECT. This is extremely frowned upon, and should not be used except in extreme circumstances. If an incompatibility is present, it should detect and handle it in theITransformationService.onLoad(cpw.mods.modlauncher.api.IEnvironment, java.util.Set<java.lang.String>)
ITransformer.transform(Object, ITransformerVotingContext)method called. It is then removed from the set of transformers and another round is performed.- Specified by:
castVotein interfaceITransformer<ClassNode>- Parameters:
context- The context of the vote- Returns:
- A TransformerVoteResult indicating the desire of this transformer
- If the transformer wishes to be a candidate, it should return
-
redirectFieldToMethod
-