Here's a collection of assorted Fabric-related modding tips gleaned from experiences on advising users of the API.
This segment will likely be removed from this page once it is ensured the information contained within it is detailed upon on more specialized pages.
It should be kept in mind whenever learning about Mixin in any capacity that any example is limited to its own situation. No example should be directly copied, and you should prioritize using examples as ways to better understand syntax and general principles, rather than a tutorial to achieve your specific goal. Every Mixin you make should be tailored to its isolated use-case.
Refer to relevant wikis and Discord help channels mentioned further in this section when you are in doubt or encounter an issue, getting direct help and asking questions is a natural and expected part of learning Mixins and should be prioritized when there is no obvious Wiki answer. This being kept in mind, the following are loose, general advice for using Mixin in your project.
this directly, as your Mixin class is not yet of the type of the target class. Instead, you must first cast to Object and then to the target class: (TargetClass) (Object) this. This should not be used as a way to access the target class's fields or methods, as those can be accessed through @Shadow.@Redirect and @ModifyConstant mixins cannot chain(that is, only one @Redirect or @ModifyConstant can be applied to the same target at a time, meaning that the second to be applied will fail, likely throwing a crash). Alongside @Overwrite, which is incredibly incompatible as it replaces the method outright, please avoid them if possible and prioritize using options provided by MixinExtras:@WrapOperation and @ModifyExpressionValue can be used instead of @Redirect and @ModifyConstant for all cases which do not involve intentionally clashing with another mod. @Overwrite should almost never be used over more precise modifications using injectors. See the official MixinExtras wiki for more details on the library's features.$ or _ and annotate them with @Unique. Such that addedField is instead named mymodid$addedField. This is to avoid conflicts between mods adding a field or method named the same way. This applies both to fields you add to the Mixin class, and to accessor methods which are not static.
To learn more on Mixins and how to use them, refer to the introduction page, the official Mixin Wiki, the MixinExtras Wiki and most importantly frequently ask questions in the Fabric Discord's dedicated #mod-dev-mixin channel, or the SpongePowered Discord's #mixin channel.
java.awt or javax.swing package and their subpackages. AWT does not work well on all systems. Several users have reported that it hangs Minecraft.