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 revision Previous revision
Next revision
Previous revision
tutorial:mixin_injects [2020/02/07 01:58]
draylar
tutorial:mixin_injects [2020/06/15 21:00] (current)
lvanderzande fixed the Fabric Example Mod repo link
Line 19: Line 19:
 | TAIL | Before the final return statement | | TAIL | Before the final return statement |
  
-In the case of injection points that reference statements or members, the target value can be set inside //@At//.+In the case of injection points that reference statements or members, the target value can be set inside //@At//. Target value is specified using JVM bytecode descriptors. 
 + 
 +Oracle defines the following [[https://​docs.oracle.com/​javase/​specs/​jvms/​se14/​html/​jvms-4.html#​jvms-4.3.2|field descriptors]]:​ 
 + 
 +^ Descriptor ^ Primitive ^ Description ^ 
 +| B | byte | signed byte | 
 +| C | char | Unicode character code point in the Basic Multilingual Plane, encoded with UTF-16 | 
 +| D | double | double-precision floating-point value | 
 +| F | float | single-precision floating-point value | 
 +| I | int | integer | 
 +| J | long | long integer | 
 +| L//​ClassName//;​ | reference | an instance of //​ClassName//​ | 
 +| S | short | signed short | 
 +| Z | boolean | ''​true''​ or ''​false''​ | 
 +| [ | 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 type. A method defined in Java as ''​Object m(int i, double[] d, Thread t)''​ would have the method descriptor ''​m(I[DLjava/​lang/​Thread;​)Ljava/​lang/​Object;''​.
  
 //@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'​s arguments are placed first in the method'​s header, followed by a ''​CallbackInfo''​ object. If the target method has a return type (T), ''​CallbackInfoReturnable<​T>''​ is used instead of ''​CallbackInfo''​. //@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'​s arguments are placed first in the method'​s header, followed by a ''​CallbackInfo''​ object. If the target method has a return type (T), ''​CallbackInfoReturnable<​T>''​ is used instead of ''​CallbackInfo''​.
Line 34: Line 50:
  
 ===== Practical Example ===== ===== Practical Example =====
-The following example injects a print statement at the top of ''​TitleScreen#​init''​.+The following example injects a print statement at the top of ''​TitleScreen#​init'' ​(note: the method ''​init''​ is a normal method and not a constructor).
  
 <code java [enable_line_numbers="​false"​]>​ <code java [enable_line_numbers="​false"​]>​
Line 46: Line 62:
 </​code>​ </​code>​
  
-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://​github.com/​FabricMC/​fabric-example-mod/​blob/​master/​src/​main/​java/​net/​fabricmc/​example/​mixin/​ExampleMixin.java|Fabric Example Mod repo]].
tutorial/mixin_injects.1581040709.txt.gz · Last modified: 2020/02/07 01:58 by draylar