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:18] – [Capturing local values] solidblocktutorial:mixin_examples [2024/01/13 15:02] (current) arkosammy12
Line 272: Line 272:
  
 ==== 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.
  
 Mixin: Mixin:
Line 296: Line 298:
 </code> </code>
  
-==== Capturing locals from multiple locals of a type ====+==== Capturing one of multiple locals of a type ====
 Mixin: Mixin:
 <code java> <code java>
Line 314: Line 316:
     doSomething();     doSomething();
 +   injected(new CallbackInfo("foo", false), arg3); +   injected(new CallbackInfo("foo", false), arg3);
 +  }
 +</code>
 +
 +===== Modifying locals =====
 +This requires MixinExtras.
 +
 +Mixin:
 +<code java>
 +  @Inject(method = "foo()V", at = @At(value = "INVOKE", target = "doSomething()V", shift = At.Shift.AFTER))
 +  private static void injected(CallbackInfo ci, @Local LocalRef<String> localRef) {
 +    localRef.set(localRef.get() + " - modified")
 +  }
 +</code>
 +
 +Result:
 +<code diff>
 +  public void foo() {
 +    String s = "example string";
 +    doSomething();
 ++   s = s + " - modified";
 +    doSomething2(s);
   }   }
 </code> </code>
tutorial/mixin_examples.1702865909.txt.gz · Last modified: 2023/12/18 02:18 by solidblock