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:20] – [Mixins] layl | tutorial:introduction [2019/11/03 23:11] – [Native Minecraft APIs] layl | ||
---|---|---|---|
Line 25: | Line 25: | ||
A good example of this is the " | A good example of this is the " | ||
- | Minecraft | + | Minecraft also uses JSON data files for various data-driven features. |
- | These JSON files are injected by the Fabric API (not the loader!). | + | You can add JSON files to your mod, which are then injected by the Fabric API. |
- | 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 47: | Line 46: | ||
Because the Fabric API is intentionally kept small and focused, third party APIs exist to fill in the gaps. | Because the Fabric API is intentionally kept small and focused, third party APIs exist to fill in the gaps. | ||
- | Mixins allow any third party library to affect Minecraft' | + | Mixins allow any third party library to affect Minecraft' |
You should use these instead of writing your own mixins where possible to minimize the possibility for conflicts. | You should use these instead of writing your own mixins where possible to minimize the possibility for conflicts. | ||
- | A good example | + | You can find an incomplete lists of [[documentation:libraries|third party libraries]] on this wiki. |
+ | ===== Mixins ===== | ||
+ | Finally, you can use mixins. | ||
+ | Mixins are a powerful feature that let you change any of Minecraft' | ||
+ | Some mixins can cause conflict, but used responsibly these are key to adding unique behavior to your mod. | ||
- | ===== Mixins | + | Mixins come in a variety of flavors, in rough order of preference: |
+ | |||
+ | * Adding Interfaces | ||
+ | * Callback Injectors | ||
+ | * Redirect Injectors | ||
+ | * Overwrites, you should never use these | ||
+ | |||
+ | This is not a complete list, but rather a quick overview. | ||
+ | Some mixin types are omitted here. | ||
+ | ==== 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, and return early. | ||
+ | Callback injects can stack, and are therefore unlikely to cause conflicts between mods. | ||
+ | |||
+ | |||
+ | ==== Redirect Injectors | ||
- | Finally, if all other methods have failed, | + | Redirects let you wrap method calls or variable access within a target method with your own code. |
- | These are not to be taken lightly, they can make debugging a lot harder and increase the risk of conflicts. | + | Use these very sparingly, a target call or access |
- | But, if you need to affect Minecraft' | + | If two mods redirect the same value, that will cause a conflict. |
+ | Consider callback injects first. | ||
- | Mixins allow you to add any code you want to existing Minecraft classes and methods. | ||
- | 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. | + | ==== Overwrite ==== |
- | This will let you access the class in ways not previously allowed by casting an instance of it to your interface. | + | |
- | By preferring adding interfaces, you minimize the risk of conflicts by purely adding something to the class rather than changing it. | + | |
- | If you do have to use method | + | Avoid overwrites completely. |
- | Overwrites | + | They replace a method entirely, removing all existing code and conflicting with any other types of mixins on the method. |
- | You can inject code into any part of a method, including wrapping inner method calls and canceling them. | + | 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