Package net.neoforged.neoforge.coremods
Class ReplaceFieldComparisonWithInstanceOf
java.lang.Object
net.neoforged.neoforge.coremods.ReplaceFieldComparisonWithInstanceOf
- All Implemented Interfaces:
cpw.mods.modlauncher.api.ITransformer<org.objectweb.asm.tree.MethodNode>
public class ReplaceFieldComparisonWithInstanceOf
extends Object
implements cpw.mods.modlauncher.api.ITransformer<org.objectweb.asm.tree.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.-
Nested Class Summary
Nested classes/interfaces inherited from interface cpw.mods.modlauncher.api.ITransformer
cpw.mods.modlauncher.api.ITransformer.Target<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String
private final String
private static final org.slf4j.Logger
private final String
private final Set
<cpw.mods.modlauncher.api.ITransformer.Target<org.objectweb.asm.tree.MethodNode>> Fields inherited from interface cpw.mods.modlauncher.api.ITransformer
DEFAULT_LABEL
-
Constructor Summary
ConstructorsConstructorDescriptionReplaceFieldComparisonWithInstanceOf
(String fieldOwner, String fieldName, String replacementClassName, List<cpw.mods.modlauncher.api.ITransformer.Target<org.objectweb.asm.tree.MethodNode>> methodsToScan) -
Method Summary
Modifier and TypeMethodDescriptioncpw.mods.modlauncher.api.TransformerVoteResult
castVote
(cpw.mods.modlauncher.api.ITransformerVotingContext context) cpw.mods.modlauncher.api.TargetType
<org.objectweb.asm.tree.MethodNode> Set
<cpw.mods.modlauncher.api.ITransformer.Target<org.objectweb.asm.tree.MethodNode>> targets()
org.objectweb.asm.tree.MethodNode
transform
(org.objectweb.asm.tree.MethodNode methodNode, cpw.mods.modlauncher.api.ITransformerVotingContext votingContext) 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.api.ITransformer
labels
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
targets
private final Set<cpw.mods.modlauncher.api.ITransformer.Target<org.objectweb.asm.tree.MethodNode>> targets -
fieldOwner
-
fieldName
-
replacementClassName
-
-
Constructor Details
-
ReplaceFieldComparisonWithInstanceOf
public ReplaceFieldComparisonWithInstanceOf(String fieldOwner, String fieldName, String replacementClassName, List<cpw.mods.modlauncher.api.ITransformer.Target<org.objectweb.asm.tree.MethodNode>> methodsToScan) - Parameters:
fieldOwner
- The class that ownsfieldName
fieldName
- The name of a field infieldOwner
replacementClassName
- Reference comparisons againstfieldName
infieldOwner
are replaced by instanceof checks against this class.methodsToScan
- The methods to scan
-
-
Method Details
-
getTargetType
public cpw.mods.modlauncher.api.TargetType<org.objectweb.asm.tree.MethodNode> getTargetType()- Specified by:
getTargetType
in interfacecpw.mods.modlauncher.api.ITransformer<org.objectweb.asm.tree.MethodNode>
-
targets
public Set<cpw.mods.modlauncher.api.ITransformer.Target<org.objectweb.asm.tree.MethodNode>> targets()- Specified by:
targets
in interfacecpw.mods.modlauncher.api.ITransformer<org.objectweb.asm.tree.MethodNode>
-
transform
public org.objectweb.asm.tree.MethodNode transform(org.objectweb.asm.tree.MethodNode methodNode, cpw.mods.modlauncher.api.ITransformerVotingContext votingContext) - Specified by:
transform
in interfacecpw.mods.modlauncher.api.ITransformer<org.objectweb.asm.tree.MethodNode>
-
castVote
public cpw.mods.modlauncher.api.TransformerVoteResult castVote(cpw.mods.modlauncher.api.ITransformerVotingContext context) - Specified by:
castVote
in interfacecpw.mods.modlauncher.api.ITransformer<org.objectweb.asm.tree.MethodNode>
-