User Tools

Site Tools


drafts:mixin_injectors

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
drafts:mixin_injectors [2026/01/24 01:26] gauntreclusedrafts:mixin_injectors [2026/02/20 20:39] (current) – [Injection Point, the value attribute] Add CTOR_HEAD injection point gauntrecluse
Line 66: Line 66:
 ^ String Form in Annotation  ^ Function                                                                                ^ ^ String Form in Annotation  ^ Function                                                                                ^
 | ''HEAD''                   | Inject at the earliest possible point in the method                                     | | ''HEAD''                   | Inject at the earliest possible point in the method                                     |
 +| ''CTOR_HEAD''              | For constructors, inject at the earliest possible point after the super call.           |
 | ''RETURN''                 | Inject before every ''RETURN'' instruction in the target method                         | | ''RETURN''                 | Inject before every ''RETURN'' instruction in the target method                         |
 | ''TAIL''                   | Inject before the very last ''RETURN'' instruction in the target method                 | | ''TAIL''                   | Inject before the very last ''RETURN'' instruction in the target method                 |
Line 130: Line 131:
  
 ==== Slice ==== ==== Slice ====
-A slice uses one or two additional ''@At''s to specify a range to include when searching for instructions matching the main ''@At'', it is usable for any injection point. Slicing is specified via the ''slice'' attribute, which takes a ''@Slice'' annotation (code differently formatted to distinguish between the different ''@At''s more clearly):+A slice uses one or two additional ''@At''s to specify a range to include when searching for instructions matching the main ''@At'', it is usable for any injection point. Slicing is specified via the ''slice'' attribute, which takes a ''@Slice'' annotation (code differently formatted to distinguish between the different ''@At''s more clearly), for example:
 <code java> <code java>
-@At+@InjectorAnnotation
-    value = "INJECTION POINT",+    method = "..."
 +    at = @At(...),
     slice = @Slice(     slice = @Slice(
-        from = @At(...)+        from = @At(...),
         to = @At(...)         to = @At(...)
     )     )
-   +)
 </code> </code>
- +''from'' defaults to ''@At("HEAD")'', and ''to'' defaults to ''@At("TAIL")'', you may only specify one's value if needed. They otherwise can be specified as normal ''@At''s.
-''from'' defaults to ''@At("HEAD")'', and ''to'' defaults to ''@At("TAIL")'', you may only specify one's value if needed.+
  
 :!: When slicing, the default [[#injection_point_specifiers|specifier]] behavior of the injection point shifts from '':ALL'' to '':FIRST''. This means you must explicitly use '':ALL'' for the injector to be able to target multiple instructions within a slice. :!: When slicing, the default [[#injection_point_specifiers|specifier]] behavior of the injection point shifts from '':ALL'' to '':FIRST''. This means you must explicitly use '':ALL'' for the injector to be able to target multiple instructions within a slice.
Line 212: Line 213:
 Mixins are able to merge new members into target classes and modify existing methods related to data management, which can theoretically be used to effectively add data to existing classes for your own use-cases. This, however, is not advised as it takes a great amount of work, and Fabric already provides a [[https://docs.fabricmc.net/develop/data-attachments|Data Attachment API]] for this purpose, along with other means to save data persistently such as [[https://docs.fabricmc.net/develop/saved-data|Saved Data]]. Using Mixins to do it manually can often result in unnecessary maintenance and a higher likelihood for bugs. Mixins are able to merge new members into target classes and modify existing methods related to data management, which can theoretically be used to effectively add data to existing classes for your own use-cases. This, however, is not advised as it takes a great amount of work, and Fabric already provides a [[https://docs.fabricmc.net/develop/data-attachments|Data Attachment API]] for this purpose, along with other means to save data persistently such as [[https://docs.fabricmc.net/develop/saved-data|Saved Data]]. Using Mixins to do it manually can often result in unnecessary maintenance and a higher likelihood for bugs.
  
-There are cases where Fabric may not provide a sufficient API for adding data for your goals. In those cases, using Mixin to merge methods and fields to store data for certain classes is a valid approach. In those cases, it is however wise to first ask for advice if you are not experienced with it yourself, as this requires to be very careful.+There are cases where Fabric may not provide a sufficient API for adding data for your goals. In those cases, using Mixin to merge methods and fields to store data for certain classes is a valid approach. In those cases, it is however wise to first ask for advice if you are not experienced with it yourself, as this requires you to be very careful.
  
 === Merging static blocks and Members === === Merging static blocks and Members ===
drafts/mixin_injectors.1769218003.txt.gz · Last modified: 2026/01/24 01:26 by gauntrecluse