Package cpw.mods.modlauncher.api
Interface ITransformer<T>
- All Known Implementing Classes:
MethodRedirector
,ReplaceFieldComparisonWithInstanceOf
,ReplaceFieldWithGetterAccess
,TransformerHolder
public interface ITransformer<T>
A transformer is injected into the modding ClassLoader. It can manipulate any item
it is designated to target.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final record
Simple data holder indicating where theITransformer
can target. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptioncastVote
(ITransformerVotingContext context) Return theTransformerVoteResult
for this transformer.default String[]
labels()
targets()
Return a set ofITransformer.Target
identifying which elements this transformer wishes to try and apply to.transform
(T input, ITransformerVotingContext context) Transform the input to the ITransformer's desire.
-
Field Details
-
DEFAULT_LABEL
-
-
Method Details
-
transform
Transform the input to the ITransformer's desire. The context from the last vote is provided as well.- 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
Return theTransformerVoteResult
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:- 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>)
transform(Object, ITransformerVotingContext)
method called. It is then removed from the set of transformers and another round is performed.- 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
-
targets
Set<ITransformer.Target<T>> targets()Return a set ofITransformer.Target
identifying which elements this transformer wishes to try and apply to. ThegetTargetType()
must match the T variable for the transformer as documented inTargetType
, other combinations will be rejected.- Returns:
- The set of targets this transformer wishes to apply to
-
getTargetType
TargetType<T> getTargetType() -
labels
- Returns:
- A string array for uniquely identifying this transformer instance within the service.
-