tutorial:mixin_injects
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:mixin_injects [2025/11/30 14:20] – Usages segment renamed to Utility gauntrecluse | tutorial:mixin_injects [2025/12/15 16:52] (current) – Added an extra bracket to show that it has to be inside @At more clearly mcgambingpro | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| In the context of Mixins, when talking about injects, it is typically in reference to the specific '' | In the context of Mixins, when talking about injects, it is typically in reference to the specific '' | ||
| - | Inject is included in " | + | '' |
| - | It is arguably the most intuitively understandable injector, and a detailed example can be found [[tutorial: | ||
| - | + | ===== Effects & Use-Cases | |
| - | ===== Utility | + | |
| '' | '' | ||
| This makes '' | This makes '' | ||
| - | * Listening to a specific method' | + | * Listening to a specific method' |
| * Note that depending on the specific operation, some injectors able to get more context about individual operations may be more suitable. | * Note that depending on the specific operation, some injectors able to get more context about individual operations may be more suitable. | ||
| * Adding a consistent operation at a part of a target method, without the intent of replacing any of the existing operations. | * Adding a consistent operation at a part of a target method, without the intent of replacing any of the existing operations. | ||
| - | * Populating fields added by the Mixin class used, via an injection at the tail of the target class' | + | * Populating fields added by a Mixin class, via an injection at the tail of the target class' |
| + | * Adding new operations at the head or tail of a method body. | ||
| + | |||
| + | |||
| + | ==== Limitations and Alternatives ==== | ||
| + | |||
| + | === Cancelling, Modifying or Diverting individual operations === | ||
| + | It is important to not use '' | ||
| + | |||
| + | === Context-Sensitive Injections === | ||
| + | FIXME //This section should use a more concrete example.// | ||
| + | |||
| + | '' | ||
| + | For example, say we had the following code snippet: | ||
| + | <code java> | ||
| + | public void calculateSlap(int quantity, Person haykam) { | ||
| + | /*...*/ | ||
| + | float force = complexCalculation(quantity); | ||
| + | haykam.slap(quantity, | ||
| + | |||
| + | /*...*/ | ||
| + | } | ||
| + | </ | ||
| + | if we wished to inject right after the '' | ||
| + | For the sake of showing how to appropriately add our new operations after the original method call outside of void returns, we'll say '' | ||
| + | <code java> | ||
| + | @WrapOperation(method = " | ||
| + | private boolean onHaykamSlapped(Person instance, int quantity, float forceOverResistance, | ||
| + | boolean originalValue = original.call(instance, | ||
| + | newOperations(forceOverResistance, | ||
| + | return originalValue; | ||
| + | } | ||
| + | </ | ||
| + | This allows us to get the returned value of the '' | ||
| - | It is important to not use '' | + | :!: Note that '' |
| + | In summary of this subsection, '' | ||
| ===== Structure ===== | ===== Structure ===== | ||
| A barebones structure of '' | A barebones structure of '' | ||
| Line 92: | Line 124: | ||
| - | ==== Cancelling ==== | + | ==== Cancelling |
| '' | '' | ||
| This is also possible for other injectors via MixinExtras' | This is also possible for other injectors via MixinExtras' | ||
| + | |||
| + | ===== Shifting ===== | ||
| + | '' | ||
| + | |||
| + | The only common form of shifting comes in the form of using '' | ||
| + | <code java> | ||
| + | @Inject(method = " | ||
| + | </ | ||
tutorial/mixin_injects.1764512401.txt.gz · Last modified: 2025/11/30 14:20 by gauntrecluse