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 23:07] – [Third Party APIs] layl | tutorial:introduction [2023/01/24 19:15] – [Overwrite] remove some strong language surrounding overwrites miir | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Introduction to Modding with Fabric | + | ====== Introduction to Modding with Fabric ====== |
This is a quick introduction to some common techniques you can use while making Fabric mods. | This is a quick introduction to some common techniques you can use while making Fabric mods. | ||
Line 11: | Line 11: | ||
Mixins can be fragile, and at times can cause conflicts. | Mixins can be fragile, and at times can cause conflicts. | ||
Therefore, some common functionality has already been implemented by the Fabric API for you. | Therefore, some common functionality has already been implemented by the Fabric API for you. | ||
- | If it doesn' | + | If it doesn' |
- | In almost every situation it's preferable to use either the Fabric API, or a third party library over implementing a mixin yourself. | + | In almost every situation it's preferable to use either the Fabric API or a third party library over implementing a mixin yourself. |
Sometimes though, you don't need any of that. | Sometimes though, you don't need any of that. | ||
Line 23: | Line 23: | ||
If Minecraft already lets you do something, don't re-invent the wheel. | If Minecraft already lets you do something, don't re-invent the wheel. | ||
- | A good example of this is the "Registry" class, which lets you add blocks and items without any modifications to Minecraft' | + | A good example of this is the "<yarn class_2378> |
- | 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 41: | Line 40: | ||
You can find out what's included in the Fabric API by looking over [[https:// | You can find out what's included in the Fabric API by looking over [[https:// | ||
- | The Fabric API contains a lot of common event hooks, and general utilities for things like networking and rendering. | + | The Fabric API contains a lot of common event hooks and general utilities for things like networking and rendering. |
Line 48: | Line 47: | ||
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 | + | You should use these instead of writing your own mixins where possible to minimize the possibility |
- | You can find an incomplete | + | You can find an incomplete |
===== Mixins ===== | ===== Mixins ===== | ||
Finally, you can use mixins. | Finally, you can use mixins. | ||
- | Mixins are a powerful feature that let you change any of Minecraft' | + | Mixins are a powerful feature that lets you change any of Minecraft' |
- | Some mixins can cause conflict, but used responsibly these are key to adding unique behavior to your mod. | + | Some mixins can cause conflict but used responsibly these are key to adding unique behavior to your mod. |
Mixins come in a variety of flavors, in rough order of preference: | Mixins come in a variety of flavors, in rough order of preference: | ||
Line 62: | Line 61: | ||
* Callback Injectors | * Callback Injectors | ||
* Redirect Injectors | * Redirect Injectors | ||
- | * Overwrites, you should never use these | + | * Overwrites |
This is not a complete list, but rather a quick overview. | This is not a complete list, but rather a quick overview. | ||
Line 68: | Line 67: | ||
==== Adding Interfaces ==== | ==== Adding Interfaces ==== | ||
- | This is probably the safest | + | This is probably |
New interface implementations can be added to any Minecraft class. | New interface implementations can be added to any Minecraft class. | ||
You can then access the interface by casting the class to it. | You can then access the interface by casting the class to it. | ||
This doesn' | This doesn' | ||
+ | |||
+ | One caveat is that the function signature (name + parameter types) you inject must be unique. So if you use common parameter types, be sure to give it a very unique name. | ||
Line 91: | Line 92: | ||
==== Overwrite ==== | ==== Overwrite ==== | ||
- | Avoid overwrites completely. | + | Be very careful with how you use Overwrites. |
They replace a method entirely, removing all existing code and conflicting with any other types of mixins on the method. | They replace a method entirely, removing all existing code and conflicting with any other types of mixins on the method. | ||
They are extremely likely to conflict not just with other mods, but also with changes to Minecraft itself. | They are extremely likely to conflict not just with other mods, but also with changes to Minecraft itself. | ||
- | You most likely do not need an overwrite to do what you want to do, please use something else. | + | You most likely do not need an overwrite to do what you want to do. |
tutorial/introduction.txt · Last modified: 2023/09/13 21:20 by 2001:8a0:f4d2:c700:98c:bb27:6ad8:1dab