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 [2024/01/12 23:26] – arkosammy12 | tutorial:mixin_examples [2026/05/16 08:25] (current) – Clarify that using shift by is discouraged. earthcomputer | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | FIXME //The Fabric Wiki's Mixin segments is under heavy reviews, pages on the topic are subject to major edits or rewrites. This page in particular is noted as being unreliable to learn Mixin as a tool from. Learning by example should be used sparingly, as it may lead to a lack of understanding. Prioritize, if you are unable to learn through documentation, | ||
| + | |||
| + | |||
| + | :!: //A rewrite of this page is planned and will be drafted in the foreseeable future, whilst some quicker changes and improvements may be applied to this page in the process, more fundamental structural changes will happen as part of a broader rewrite and replacement by a new version of the page// | ||
| + | |||
| ====== Mixin Examples ====== | ====== Mixin Examples ====== | ||
| This is a collection of frequently used mixins. | This is a collection of frequently used mixins. | ||
| Line 148: | Line 153: | ||
| ===== Injecting into the point with shift amount ===== | ===== Injecting into the point with shift amount ===== | ||
| + | :!: Using a shift amount is heavily discouraged, | ||
| + | |||
| Mixin: | Mixin: | ||
| <code java> | <code java> | ||
| Line 272: | Line 279: | ||
| ==== 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 there are multiple locals with that type, you have to specify '' | :!: If there are multiple locals with that type, you have to specify '' | ||
| - | :!: More information about MixinExtra' | + | :!: the use of '' |
| Mixin: | Mixin: | ||
| Line 282: | Line 291: | ||
| @Inject(method = " | @Inject(method = " | ||
| private void injected(CallbackInfo ci, @Local TypeArg2 arg2) { | private void injected(CallbackInfo ci, @Local TypeArg2 arg2) { | ||
| - | | + | |
| } | } | ||
| </ | </ | ||
| Line 303: | Line 312: | ||
| @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 342: | Line 351: | ||
| Mixin: | Mixin: | ||
| <code java> | <code java> | ||
| - | @Inject(method = "foo()I;", at = @At(" | + | @ModifyReturnValue(method = " |
| - | private | + | private |
| - | | + | |
| } | } | ||
| </ | </ | ||
| Line 350: | Line 359: | ||
| Result: | Result: | ||
| <code diff> | <code diff> | ||
| - | | + | public int foo() { |
| doSomething1(); | doSomething1(); | ||
| doSomething2(); | doSomething2(); | ||
| - | - | ||
| - | + int i = doSomething3() + 7; | + | + return this.exampleModifyReturnValue(doSomething3() + 7); |
| - | + | + | } |
| - | + | + | |
| - | + if (cir.isCancelled()) return cir.getReturnValue(); | + | |
| - | + | + | |
| - | | + | |
| </ | </ | ||
tutorial/mixin_examples.1705101994.txt.gz · Last modified: 2024/01/12 23:26 by arkosammy12