User Tools

Site Tools


tutorial:mixin_injects

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_injects [2020/02/07 01:46] – final cleanup draylartutorial:mixin_injects [2020/02/07 01:58] draylar
Line 2: Line 2:
  
 ===== Introduction ===== ===== Introduction =====
-Injects allows you to place custom code at a specified position inside an existing method. For a functional example, view the example section at the bottom of this page. The standard form of an inject is as shown:+Injects allows you to place custom code at a specified position inside an existing method. For a working example, view the [[https://fabricmc.net/wiki/tutorial:mixin_injects#practical_example|Practical Example]] category at the bottom of this page. The standard form of an inject is as shown:
  
 <code java> <code java>
Line 24: Line 24:
  
 === Returning & Cancelling from Inject === === Returning & Cancelling from Inject ===
-To cancel or return early inside a method, use ''CallbackInfo#cancel'' or ''CallbackInfoReturnable<T>#setReturnValue(T)''. In both instances, ''cancellable'' will have to be set to true in the inject annotation:+To cancel or return early inside a method, use ''CallbackInfo#cancel'' or ''CallbackInfoReturnable<T>#setReturnValue(T)''. Note that ''cancel'' does not have to be called after ''setReturnValue''. In both instances, ''cancellable'' will have to be set to true in the inject annotation:
 <code java> <code java>
 @Inject(method = "...", at = @At("..."), cancellable = true) @Inject(method = "...", at = @At("..."), cancellable = true)
Line 30: Line 30:
  
  
 +=== Injecting into Constructors ===
 +To inject into a constructor, use ''<init>()V'' as the method target, with ''()'' containing the constructor argument descriptors. When injecting into constructors, ''@At'' must be set to either ''TAIL'' or ''RETURN''.
  
 ===== Practical Example ===== ===== Practical Example =====
tutorial/mixin_injects.txt · Last modified: 2022/08/05 19:19 by clomclem