tutorial:mixin_examples
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:mixin_examples [2023/12/18 02:18] – [Capturing local values] solidblock | tutorial:mixin_examples [2024/11/18 15:52] (current) – fixed some of the argument names in mixinextra section bemoty | ||
---|---|---|---|
Line 272: | Line 272: | ||
==== Capture locals with MixinExtras ==== | ==== Capture locals with MixinExtras ==== | ||
+ | :!: See the oficial MixinExtra' | ||
+ | |||
:!: MixinExtras required Fabric Loader 0.15 or above, or you have to manually specify it in '' | :!: MixinExtras required Fabric Loader 0.15 or above, or you have to manually specify it in '' | ||
- | :!: If ther are multiple locals with that type, you have to specify '' | + | :!: If there are multiple locals with that type, you have to specify '' |
Mixin: | Mixin: | ||
Line 280: | Line 282: | ||
@Inject(method = " | @Inject(method = " | ||
private void injected(CallbackInfo ci, @Local TypeArg2 arg2) { | private void injected(CallbackInfo ci, @Local TypeArg2 arg2) { | ||
- | | + | |
} | } | ||
</ | </ | ||
Line 296: | Line 298: | ||
</ | </ | ||
- | ==== Capturing | + | ==== Capturing |
Mixin: | Mixin: | ||
<code java> | <code java> | ||
@Inject(method = " | @Inject(method = " | ||
private void injected(CallbackInfo ci, @Local(ordinal = 2) TypeArg arg) { | private void injected(CallbackInfo ci, @Local(ordinal = 2) TypeArg arg) { | ||
- | | + | |
} | } | ||
</ | </ | ||
Line 314: | Line 316: | ||
doSomething(); | doSomething(); | ||
+ | + | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Modifying locals ===== | ||
+ | This requires MixinExtras. | ||
+ | |||
+ | Mixin: | ||
+ | <code java> | ||
+ | @Inject(method = " | ||
+ | private static void injected(CallbackInfo ci, @Local LocalRef< | ||
+ | localRef.set(localRef.get() + " - modified" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Result: | ||
+ | <code diff> | ||
+ | public void foo() { | ||
+ | String s = " | ||
+ | doSomething(); | ||
+ | + s = s + " - modified"; | ||
+ | doSomething2(s); | ||
} | } | ||
</ | </ |
tutorial/mixin_examples.1702865909.txt.gz · Last modified: 2023/12/18 02:18 by solidblock