tutorial:introduction
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:introduction [2019/11/03 14:06] – [Mixins] layl | tutorial:introduction [2019/11/03 14:55] – [Mixins] layl | ||
---|---|---|---|
Line 26: | Line 26: | ||
Minecraft will also load in the JSON data files from your mod. | Minecraft will also load in the JSON data files from your mod. | ||
- | These files are used for anything data-driven, | + | These JSON files are injected by the Fabric API (not the loader!). |
+ | They' | ||
For example, block models and loot tables are implemented through JSON files. | For example, block models and loot tables are implemented through JSON files. | ||
Line 54: | Line 55: | ||
===== Mixins ===== | ===== Mixins ===== | ||
- | Finally, if all other methods have failed, you can use mixins. | + | Finally, you can use mixins. |
- | These are not to be taken lightly, they can make debugging | + | Mixins |
- | But, if you need to affect Minecraft' | + | Some mixins can cause conflict, but used responsibly these are key to adding unique behavior |
- | Mixins | + | Mixins |
- | The example project already comes with an example mixin that injects itself into the " | + | |
- | If you can, prefer adding interfaces to classes over injecting into existing methods. | + | * Adding Interfaces |
- | This will let you access the class in ways not previously allowed by casting an instance of it to your interface. | + | * Callback Injectors |
- | By preferring adding interfaces, you minimize the risk of conflicts by purely adding something to the class rather than changing it. | + | * Redirect Injectors |
+ | * Overwrites, you should never use these | ||
- | If you do have to use method | + | This is not a complete list, but rather a quick overview. |
- | Overwrites are the most likely to conflict with other mods and in most situations you do not need them. | + | Some mixin types are omitted here. |
- | You can inject code into any part of a method, including wrapping inner method calls and canceling them. | + | ==== Adding Interfaces ==== |
+ | |||
+ | This is probably the safest way to use mixins. | ||
+ | New interface implementations can be added to any Minecraft class. | ||
+ | You can then access the interface by casting the class to it. | ||
+ | This doesn' | ||
+ | |||
+ | |||
+ | ==== Callback Injectors ==== | ||
+ | |||
+ | Callback injectors let you add callback hooks to existing methods, as well as on specific method calls within that method. | ||
+ | They also let you intercept and change the return value of a method, | ||
+ | Callback injects can stack, and are therefore unlikely to cause conflicts between mods. | ||
+ | |||
+ | |||
+ | ==== Redirect Injectors ==== | ||
+ | |||
+ | Redirects let you wrap method calls or variable access within a target method with your own code. | ||
+ | Use these very sparingly, a target call or access can only be redirected once between all mods. | ||
+ | If two mods redirect the same value, that will cause a conflict. | ||
+ | Consider callback injects first. | ||
+ | |||
+ | |||
+ | ==== Overwrite ==== | ||
+ | |||
+ | Never use overwrites. | ||
+ | Overwrites | ||
+ | They are extremely | ||
+ | You most likely |
tutorial/introduction.txt · Last modified: 2023/09/13 21:20 by 2001:8a0:f4d2:c700:98c:bb27:6ad8:1dab