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
tutorial:mixin_injects [2025/12/08 17:43] – Edit example where WrapOp is preferrable to have it capture an expression rather than just a local, suggested by EarthComputer gauntreclusetutorial:mixin_injects [2026/01/01 13:03] (current) – Remove now generally unnecessary warning header, fix monospaced consistency on MExtras injector refs gauntrecluse
Line 1: Line 1:
-FIXME //This page is due rewrites because of inaccuracies. This page may change very suddenly and should be taken with a grain of salt.// 
- 
 ====== @Inject ====== ====== @Inject ======
  
Line 23: Line 21:
  
 === Cancelling, Modifying or Diverting individual operations === === Cancelling, Modifying or Diverting individual operations ===
-It is important to not use ''@Inject'', and in particular its cancelling, if the goal can be achieved with a more precise and less intrusive changes. Injectors such as ''[[https://github.com/LlamaLad7/MixinExtras/wiki/WrapOperation|@WrapOperation]]'', [[https://github.com/LlamaLad7/MixinExtras/wiki/ModifyExpressionValue|@ModifyExpressionValue]], [[https://github.com/LlamaLad7/MixinExtras/wiki/ModifyReturnValue|@ModifyReturnValue]] or ''@ModifyArg'' are better-suited for preventing, modifying or diverting individual calls or operations, without cancelling the entire method; or applying modifications to a return value.+It is important to not use ''@Inject'', and in particular its cancelling, if the goal can be achieved with a more precise and less intrusive changes. Injectors such as ''[[https://github.com/LlamaLad7/MixinExtras/wiki/WrapOperation|@WrapOperation]]'', ''[[https://github.com/LlamaLad7/MixinExtras/wiki/ModifyExpressionValue|@ModifyExpressionValue]]''''[[https://github.com/LlamaLad7/MixinExtras/wiki/ModifyReturnValue|@ModifyReturnValue]]'' or ''@ModifyArg'' are better-suited for preventing, modifying or diverting individual calls or operations, without cancelling the entire method; or applying modifications to a return value.
  
 === Context-Sensitive Injections === === Context-Sensitive Injections ===
Line 39: Line 37:
 } }
 </code> </code>
-if we wished to inject right after the ''slap'' call, we could use a [[#shifting|Shift]] to inject after the call with ''@Inject''. However, if we needed to also get the ''force'' variable, it would be instead preferable to use a ''@WrapOperation'' to get the ''force / haykam.resistance'' parameter's value without needing to use ''@Local'' on ''force'' to then recalculate it.\\+if we wished to inject right after the ''slap'' call, we could use a [[#shifting|Shift]] to inject after the call with ''@Inject''. However, if we needed to also get the ''force / haykam.resistance'' value, it would be instead preferable to use a ''@WrapOperation'' to get it without needing to use ''@Local'' on ''force'' to then recalculate it.\\
 For the sake of showing how to appropriately add our new operations after the original method call outside of void returns, we'll say ''slap'' has a ''boolean'' return value. For the sake of showing how to appropriately add our new operations after the original method call outside of void returns, we'll say ''slap'' has a ''boolean'' return value.
 <code java> <code java>
Line 134: Line 132:
 The only common form of shifting comes in the form of using ''shift = At.Shift.AFTER'' within the ''@At''. This shifts the injection point to after the target. The syntax for shifting looks as follows: The only common form of shifting comes in the form of using ''shift = At.Shift.AFTER'' within the ''@At''. This shifts the injection point to after the target. The syntax for shifting looks as follows:
 <code java> <code java>
-@Inject(method = "...", at = @At(value = "...", target = "...", shift = At.Shift.AFTER)+@Inject(method = "...", at = @At(value = "...", target = "...", shift = At.Shift.AFTER))
 </code> </code>
tutorial/mixin_injects.1765215823.txt.gz · Last modified: 2025/12/08 17:43 by gauntrecluse