Class ReplaceFieldComparisonWithInstanceOf

java.lang.Object
net.neoforged.neoforge.coremods.ReplaceFieldComparisonWithInstanceOf
All Implemented Interfaces:
cpw.mods.modlauncher.api.ITransformer<MethodNode>

public class ReplaceFieldComparisonWithInstanceOf extends Object implements cpw.mods.modlauncher.api.ITransformer<MethodNode>
Replaces code such as itemstack.getItem() == Items.CROSSBOW with instanceof checks such as itemstack.getItem() instanceof CrossbowItem. This transformer targets a set of methods to replace the occurrence of a single field-comparison.
  • Field Details

    • LOG

      private static final org.slf4j.Logger LOG
    • targets

      private final Set<cpw.mods.modlauncher.api.ITransformer.Target<MethodNode>> targets
    • fieldOwner

      private final String fieldOwner
    • fieldName

      private final String fieldName
    • replacementClassName

      private final String replacementClassName
  • Constructor Details

    • ReplaceFieldComparisonWithInstanceOf

      public ReplaceFieldComparisonWithInstanceOf(String fieldOwner, String fieldName, String replacementClassName, List<cpw.mods.modlauncher.api.ITransformer.Target<MethodNode>> methodsToScan)
      Parameters:
      fieldOwner - The class that owns fieldName
      fieldName - The name of a field in fieldOwner
      replacementClassName - Reference comparisons against fieldName in fieldOwner are replaced by instanceof checks against this class.
      methodsToScan - The methods to scan
  • Method Details

    • getTargetType

      public cpw.mods.modlauncher.api.TargetType<MethodNode> getTargetType()
      Specified by:
      getTargetType in interface cpw.mods.modlauncher.api.ITransformer<MethodNode>
    • targets

      public Set<cpw.mods.modlauncher.api.ITransformer.Target<MethodNode>> targets()
      Specified by:
      targets in interface cpw.mods.modlauncher.api.ITransformer<MethodNode>
    • transform

      public MethodNode transform(MethodNode methodNode, cpw.mods.modlauncher.api.ITransformerVotingContext votingContext)
      Specified by:
      transform in interface cpw.mods.modlauncher.api.ITransformer<MethodNode>
    • castVote

      public cpw.mods.modlauncher.api.TransformerVoteResult castVote(cpw.mods.modlauncher.api.ITransformerVotingContext context)
      Specified by:
      castVote in interface cpw.mods.modlauncher.api.ITransformer<MethodNode>