tutorial:mixin_introduction
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:mixin_introduction [2025/09/23 18:19] – [Major Edit] Add a first version of a proper introduction to Mixins as a subsystem rather than relying purely on other internal and external pages to give an introduction to the concept. This introduction it WIP, and the title has been marked as such. Due gauntrecluse | tutorial:mixin_introduction [2025/11/21 13:26] (current) – ↷ Links adapted because of a move operation gauntrecluse | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | FIXME //The Mixin related pages of the Fabric Wiki are undergoing a more thorough review, and are subject to change, rewrites or being replaced. Many pages may be outdated, inaccurate, inactive or incomplete. It is strongly recommended to use the Fabric wiki and linked resources to get a rudimentary Mixin understanding, | + | FIXME //The Mixin related pages of the Fabric Wiki are undergoing a more thorough review, and are subject to change, rewrites or being replaced. Many pages may be outdated, inaccurate, inactive or incomplete. It is strongly recommended to use the Fabric wiki and linked resources to get a rudimentary Mixin understanding, |
| - | //This page specifically is under heavy revisions, and may change in large ways almost overnight as a result. Always prioritize learning from the dedicated external Wikis and asking questions in support channels when in doubt// | + | |
| ====== Introduction to Mixins (WIP) ====== | ====== Introduction to Mixins (WIP) ====== | ||
| Mixins are a powerful and important tool used in the Fabric ecosystem and other modding frameworks for Minecraft. Their primary use case is modifying existing code in the base game, | Mixins are a powerful and important tool used in the Fabric ecosystem and other modding frameworks for Minecraft. Their primary use case is modifying existing code in the base game, | ||
| - | whether it be through injecting custom logic, removing mechanics, or modifying values. Note that **only Mixins written in Java are directly supported**, even if you use Kotlin or another language running on the Java Virtual Machine for the rest of your mod. It may technically | + | whether it be through injecting custom logic, removing mechanics, or modifying values. Note that **only Mixins written in Java are directly supported**.((This applies |
| - | Mixin is a complex subsystem which merges | + | Mixin is a complex subsystem which uses a mod' |
| - | ((Mixin classes are not classes in the same way as " | + | ((Mixin classes are not classes in the same way as " |
| - | into the targeted classes' | + | to transform |
| - | It is not recommended to try and learn how Mixin works or how to use it without having some notion of what Bytecode is, as that may lead to unexpected behavior and misunderstandings. It is also recommended to know how to read Java Bytecode for your IDE of choice, as reading portions of the Bytecode may sometimes be necessary to use Mixin properly, notably when targeting anonymous classes, lambdas or code with a lot of '' | + | |
| - | Similarly, Mixin and this documentation expects the user to already be familiar with [[tutorial: | + | |
| - | Mixin does its work very early in the overall Fabric launching process, | + | It is not recommended to try and learn how Mixin works or how to use it without prior knowledge of what Java bytecode |
| + | Similarly, Mixin and this documentation expects the user to already | ||
| + | It is recommended to leverage the [[https:// | ||
| - | There are different kinds of tools Mixin and MixinExtras | + | Mixin can do its work throughout the game's lifecycle, however, a Mixin's transformations must be applied before the targeted class has loaded. For the majority |
| - | ((Since Fabric Loader 0.15, MixinExtras is bundled with Fabric. Since Loader version 0.17.0, MixinExtras major version 0.5.0 is included, and allows access to [[https:// | + | |
| - | provide for modifying source code. Those tools come in the form of Java annotations, those annotations decorate((AKA annotate, are attached to)) members of the Mixin class and are passed arguments which are used to associate the necessary information so that Mixin knows how to process | + | |
| - | FIXME //There ought to be dedicated pages going more in depth about the different tools annotations later on. This segment as it is edited should be kept to an introductory level to Mixin annotations and features.// | + | |
| - | * The '' | + | There are different tools Mixin and MixinExtras |
| - | * Injector Mixin annotations decorate a handler method((In the context of Mixins, handler methods are the methods that are merged into the target class, and invoked at the relevant point the decorating annotation specifies as a target. For most cases, think of them are the methods decorated by injector or redirector annotations.)) | + | ((Since Fabric Loader 0.15, MixinExtras is bundled with Fabric. Since Loader version 0.17.0, MixinExtras major version 0.5.0 is included, and allows access to [[https:// |
| - | * Redirector Mixin annotations | + | provide for modifying source |
| - | * Overwriting, | + | |
| - | //For more complete and thorough information on Mixin functionality, | + | As to make reading |
| + | FIXME //There ought to be dedicated pages going more in depth about the different tools annotations later on. This segment as it is edited should | ||
| - | The Fabric Wiki offers several articles that provide practical examples and explanations of some areas of the Mixin and MixinExtras | + | ^ Feature ^ Overview ^ Notes ^ |
| + | | '' | ||
| + | | Merging | Mixin merges a Mixin class' | ||
| + | | Injectors | An injector typically refers to an annotation and an associated " | ||
| + | | Redirectors(rarely called Redirect Injectors) | Similar to injectors as described above, with the important difference that redirectors replace the target instructions with the callback, rather than only injecting new instructions. This makes it impossible for more than on Redirector to apply to the same target, making them impractical unless a hard incompatibility is intended. | Redirectors include mainly '' | ||
| + | | Overwriting | Done explicitly via '' | ||
| + | |||
| + | //For more complete information on Mixin functionality and usage view the [[https:// | ||
| + | |||
| + | The Fabric Wiki offers several articles that provide practical examples and explanations of some areas of Mixin and MixinExtras: | ||
| + | * [[tutorial: | ||
| * [[tutorial: | * [[tutorial: | ||
| * [[tutorial: | * [[tutorial: | ||
| Line 36: | Line 42: | ||
| * [[tutorial: | * [[tutorial: | ||
| * [[tutorial: | * [[tutorial: | ||
| - | * [[tutorial:accesswideners | + | * [[tutorial:accesswidening|Access |
| * [[tutorial: | * [[tutorial: | ||
| * [[tutorial: | * [[tutorial: | ||
| * [[tutorial: | * [[tutorial: | ||
tutorial/mixin_introduction.1758651563.txt.gz · Last modified: 2025/09/23 18:19 by gauntrecluse