User Tools

Site Tools


tutorial:mixin_examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:mixin_examples [2023/12/18 02:24] – [Capturing locals from multiple locals of a type] solidblocktutorial:mixin_examples [2025/10/12 09:21] (current) – Mark page as having a planned rewrite gauntrecluse
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, presenting your intention in detail in a Mixin support channel on the Fabric or SpongePowered Discord servers and discussing with experienced devs there.//
 +
 +
 +:!: //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 272: Line 277:
  
 ==== Capture locals with MixinExtras ==== ==== Capture locals with MixinExtras ====
 +:!: See the oficial MixinExtra's [[https://github.com/LlamaLad7/MixinExtras/wiki/Local|Wiki]].
 +
 :!: MixinExtras required Fabric Loader 0.15 or above, or you have to manually specify it in ''build.gradle''. :!: MixinExtras required Fabric Loader 0.15 or above, or you have to manually specify it in ''build.gradle''.
  
-:!: If ther are multiple locals with that type, you have to specify ''ordinal'' or it will throw an error.+:!: If there are multiple locals with that type, you have to specify ''ordinal'' or it will throw an error. 
 + 
 +:!: the use of ''@Local'' is recommended over ''LocalCapture''
  
 Mixin: Mixin:
Line 280: Line 289:
 @Inject(method = "foo()V", at = @At(value = "TAIL")) @Inject(method = "foo()V", at = @At(value = "TAIL"))
 private void injected(CallbackInfo ci, @Local TypeArg2 arg2) { private void injected(CallbackInfo ci, @Local TypeArg2 arg2) {
-  arg1.doSomething4();+  arg2.doSomething4();
 } }
 </code> </code>
Line 301: Line 310:
 @Inject(method = "foo()V", at = @At(value = "TAIL")) @Inject(method = "foo()V", at = @At(value = "TAIL"))
 private void injected(CallbackInfo ci, @Local(ordinal = 2) TypeArg arg) { private void injected(CallbackInfo ci, @Local(ordinal = 2) TypeArg arg) {
-  arg1.doSomething4();+  arg.doSomething4();
 } }
 </code> </code>
tutorial/mixin_examples.1702866271.txt.gz · Last modified: 2023/12/18 02:24 by solidblock