Class ReplaceFieldWithGetterAccess

java.lang.Object
net.neoforged.neoforge.coremods.ReplaceFieldWithGetterAccess
All Implemented Interfaces:
ITransformer<org.objectweb.asm.tree.ClassNode>

public class ReplaceFieldWithGetterAccess extends Object implements ITransformer<org.objectweb.asm.tree.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.

  • Field Details

  • Constructor Details

    • ReplaceFieldWithGetterAccess

      public ReplaceFieldWithGetterAccess(String className, Map<String,String> fieldToMethod)
  • Method Details

    • getTargetType

      public TargetType<org.objectweb.asm.tree.ClassNode> getTargetType()
      Specified by:
      getTargetType in interface ITransformer<org.objectweb.asm.tree.ClassNode>
    • targets

      public Set<ITransformer.Target<org.objectweb.asm.tree.ClassNode>> targets()
      Description copied from interface: ITransformer
      Return a set of ITransformer.Target identifying which elements this transformer wishes to try and apply to. The ITransformer.getTargetType() must match the T variable for the transformer as documented in TargetType, other combinations will be rejected.
      Specified by:
      targets in interface ITransformer<org.objectweb.asm.tree.ClassNode>
      Returns:
      The set of targets this transformer wishes to apply to
    • transform

      public org.objectweb.asm.tree.ClassNode transform(org.objectweb.asm.tree.ClassNode input, ITransformerVotingContext context)
      Description copied from interface: ITransformer
      Transform the input to the ITransformer's desire. The context from the last vote is provided as well.
      Specified by:
      transform in interface ITransformer<org.objectweb.asm.tree.ClassNode>
      Parameters:
      input - The ASM input node, which can be mutated directly
      context - 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: ITransformer
      Return the TransformerVoteResult for 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: After all votes from candidate transformers are collected, the NOs are removed from the current set of voters, one from the set of YES voters is selected and it's ITransformer.transform(Object, ITransformerVotingContext) method called. It is then removed from the set of transformers and another round is performed.
      Specified by:
      castVote in interface ITransformer<org.objectweb.asm.tree.ClassNode>
      Parameters:
      context - The context of the vote
      Returns:
      A TransformerVoteResult indicating the desire of this transformer
    • redirectFieldToMethod

      private static void redirectFieldToMethod(org.objectweb.asm.tree.ClassNode classNode, String fieldName, @Nullable @Nullable String methodName)