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
Next revisionBoth sides next revision
tutorial:mixin_examples [2020/09/26 16:02] – minor improvement siglongtutorial:mixin_examples [2021/08/07 07:08] – Add "modifying a constant" example fracturedcode
Line 111: Line 111:
   at = @At(   at = @At(
     value = "INVOKE",     value = "INVOKE",
-    target = "La/b/c/Something;doSomething()V"), +    target = "La/b/c/Something;doSomething()V" 
-    slice = @Slice( +  ), 
-      from = @At(value = "INVOKE", target = "La/b/c/Something;doSomething2()V"), +  slice = @Slice( 
-      to = @At(value = "INVOKE", target = "La/b/c/Something;doSomething3()V")))+    from = @At(value = "INVOKE", target = "La/b/c/Something;doSomething2()V"), 
 +    to = @At(value = "INVOKE", target = "La/b/c/Something;doSomething3()V") 
 +  ) 
 +)
 private void injected(CallbackInfo ci) { private void injected(CallbackInfo ci) {
   doSomething5();   doSomething5();
Line 356: Line 359:
 +   double d1 = injected(doSomething3() + 0.8D); +   double d1 = injected(doSomething3() + 0.8D);
     double d2 = doSomething4();     double d2 = doSomething4();
 +  }
 +</code>
 +
 +===== Modifying a constant =====
 +Mixin:
 +<code java>
 +@ModifyConstant(method = "foo()V", constant = @Constant(intValue = 4))
 +private int injected(int value) {
 +  return ++value;
 +}
 +</code>
 +
 +Result:
 +<code diff>
 +  public void foo() {
 +-   for (int i = 0; i < 4; i++) {
 ++   for (int i = 0; i < 5; i++) {
 +      doSomething(i);
 +    }
   }   }
 </code> </code>
tutorial/mixin_examples.txt · Last modified: 2024/01/13 15:02 by arkosammy12