tutorial:mixin_choosing_the_right_mixin
Differences
This shows you the differences between two versions of the page.
| tutorial:mixin_choosing_the_right_mixin [2025/10/08 03:09] – created draft gauntrecluse | tutorial:mixin_choosing_the_right_mixin [2025/10/26 13:58] (current) – Restructured gauntrecluse | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| This page should be read after having already read [[tutorial: | This page should be read after having already read [[tutorial: | ||
| - | Mixins are a tool that is, by virtue of modifying potentially vastly different targets, a tool that changes its usage on a case-by-case basis. As such, which tool is right for the job, if Mixin is fitting in the first place, will change for every single case. This page will attempt to go over when to use different kinds of tools in Mixin and MixinExtras. | + | Mixins are a tool that is, by virtue of modifying potentially vastly different targets, a tool that changes its usage on a case-by-case basis. As such, which tool is right for the job, if Mixin is fitting in the first place, will change for every single case. This page will attempt to document the process of choosing which tool to use based on common situations encountered relating to Mixins. |
| ---- | ---- | ||
| - | ===== When not to use a Mixin ===== | + | ===== When not to use Mixin ===== |
| - | FIXME //Could not find any more specific things than " | + | |
| Sometimes, the goal to be fulfilled is simply not something Mixin is fit for. A good rule of thumb to avoid creating unnecessary Mixins is to only use them when other options such as existing events and other tools integrated into the modding framework are insufficient or greatly impractical. In other words, Mixin is not a first resort tool. | Sometimes, the goal to be fulfilled is simply not something Mixin is fit for. A good rule of thumb to avoid creating unnecessary Mixins is to only use them when other options such as existing events and other tools integrated into the modding framework are insufficient or greatly impractical. In other words, Mixin is not a first resort tool. | ||
| Line 21: | Line 19: | ||
| This is however not the only case where events are the better option. For instance, say you wanted to add functionality upon interacting (most often via right clicking) a block that is registered as a ''< | This is however not the only case where events are the better option. For instance, say you wanted to add functionality upon interacting (most often via right clicking) a block that is registered as a ''< | ||
| - | It may be unintuitive at first, however the reason this may be an approach to consider is that changing the class it is registered as can cause a lot of issues for other mods who may want to do a similar action, or for mods that may rely on that block being the class it is registered as. Changing the registration class via Mixin would have ripple effects and potentially have issues. At that point, it may not be worth using Mixins | + | It may be unintuitive at first, however the reason this may be an approach to consider is that changing the class it is registered as can cause a lot of issues for other mods who may want to do a similar action, or for mods that may rely on that block being the class it is registered as. Changing the registration class via Mixin would have ripple effects and likely cause issues. At that point, it may not be worth using Mixin anymore. |
| - | == As a conclusion of generally when to not use Mixins: | + | == To recap... |
| Do not use Mixins when there are ways for events or other non-Mixin tools to substitute them in a way that is less intrusive and/or incompatible. This fits into the broader principle that Mixins need to, when they must be used, be used in the most precise way as to cause the least potential issues. | Do not use Mixins when there are ways for events or other non-Mixin tools to substitute them in a way that is less intrusive and/or incompatible. This fits into the broader principle that Mixins need to, when they must be used, be used in the most precise way as to cause the least potential issues. | ||
| ---- | ---- | ||
| - | ===== Method Overwrites: Almost never the right tool ===== | + | ===== Tools with rare use-cases |
| - | Overwriting, | + | As Mixin's set of tools evolved |
| - | If you feel that you need to use '' | + | |
| - | ---- | + | ==== Method Overwrites ==== |
| - | ===== Redirectors: | + | A method overwrite, done via '' |
| - | Redirecting, | + | ==== Redirectors ==== |
| - | ==== Hard incompatibility | + | Redirectors, |
| + | This makes redirectors only useful if one wishes to specifically leverage the lack of chaining, such as causing a hard incompatibility | ||
| - | The fact that redirectors cannot chain means that Mixin will cause a hard crash if it tries to use two required redirectors on the same target. This, in most situations, simply makes them a worse alternative to the current set of injectors. The exception in that is when you //intend// to crash when another mod tries to redirect the same target as you, or when you want to leverage the hard incompatibility aspect of Redirectors. Do note that injectors such as '' | + | ---- |
| - | In short, redirectors should only be used when you directly intend to use the incompatibility aspect of it. Otherwise, injectors should be used. | + | ===== Choosing |
| - | + | ||
| - | ---- | + | |
| - | ===== @Inject: Adding | + | The primary use-case of Mixins is to modify something within |
| - | '' | + | ==== Adding new operations ==== |
| - | ==== Listening | + | A common use-case |
| - | Using '' | ||
tutorial/mixin_choosing_the_right_mixin.txt · Last modified: 2025/10/26 13:58 by gauntrecluse