tutorial:mixin_injects
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:mixin_injects [2020/06/10 23:05] – Clarify injection example pyrofab | tutorial:mixin_injects [2025/09/24 12:13] (current) – Mark page as WIP in preparation for major review and edits upcoming gauntrecluse | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Mixin Injects ====== | + | FIXME //This page is under heavy rewrites due to prior edits being from 2022, and it thus contains seriously outdated advice. This page may change very suddenly and should only be taken with a grain of salt.// |
| + | |||
| + | ====== Mixin Injects | ||
| ===== Introduction ===== | ===== Introduction ===== | ||
| - | Injects allows you to place custom code at a specified position inside an existing method. For a working example, view the [[https:// | + | Injects allows you to place custom code at a specified position inside an existing method. For a working example, view the [[tutorial: |
| <code java> | <code java> | ||
| - | @Inject(method = "", | + | @Inject(method = "METHOD NAME OR SIGNATURE", at = @At(" |
| private void injectMethod(METHOD ARGS, CallbackInfo info) { | private void injectMethod(METHOD ARGS, CallbackInfo info) { | ||
| Line 28: | Line 30: | ||
| | D | double | double-precision floating-point value | | | D | double | double-precision floating-point value | | ||
| | F | float | single-precision floating-point value | | | F | float | single-precision floating-point value | | ||
| - | | I | int | integer | | + | | I | int | signed |
| - | | J | long | long integer | | + | | J | long | signed |
| | L// | | L// | ||
| | S | short | signed short | | | S | short | signed short | | ||
| Line 35: | Line 37: | ||
| | [ | reference | one array dimension | | | [ | reference | one array dimension | | ||
| - | A method descriptor is comprised of the method name, followed by a set of parentheses containing the input types, followed by the output | + | A method descriptor is comprised of the method name, followed by a set of parentheses containing the parameter |
| - | //@Inject// methods always have a void return type. The method name does not matter; using something that describes what the inject does is best. The target method' | + | In the case that the return type is void, you need to use V (Void Descriptor Type) as the type (for example, '' |
| + | |||
| + | Generics' | ||
| + | |||
| + | '' | ||
| === Returning & Cancelling from Inject === | === Returning & Cancelling from Inject === | ||
| Line 47: | Line 53: | ||
| === Injecting into Constructors === | === Injecting into Constructors === | ||
| - | To inject into a constructor, | + | To inject into a constructor, |
| + | |||
| + | To inject into a static constructor, | ||
| ===== Practical Example ===== | ===== Practical Example ===== | ||
| Line 62: | Line 70: | ||
| </ | </ | ||
| - | For more information on this particular example, view its usage in the [[Fabric Example Mod repo]]. | + | For more information on this particular example, view its usage in the [[https:// |
tutorial/mixin_injects.1591830352.txt.gz · Last modified: 2020/06/10 23:05 by pyrofab