User Tools

Site Tools


tutorial:modding_tips

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
tutorial:modding_tips [2025/09/22 12:38] – [Mixins] Add cautionary paragraph on copying examples, link extra help resources, add mention of MixinExtras tools for compatibility purposes. Emphasize importance of asking questions in help channels. gauntreclusetutorial:modding_tips [2025/09/22 16:23] (current) – [Mixins] Readjust some phrasing gauntrecluse
Line 12: Line 12:
 ===== Mixins ===== ===== Mixins =====
  
- 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 copied, and you should privilege 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.\\ + 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 privileged when there is no obvious Wiki answer. This being kept in mind, the following are loose, general advice for using Mixin in your project.+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.
  
   * To cast a class to an interface it doesn't implement, or cast a final class, or cast the mixin to your target class, you can use the "(TargetClass) (Object) sourceClassObject" trick.   * To cast a class to an interface it doesn't implement, or cast a final class, or cast the mixin to your target class, you can use the "(TargetClass) (Object) sourceClassObject" trick.
-  * @Redirect and @ModifyConstant mixins cannot currently be nested (applied by more than one mod in the same area at the same time). This might change later in development - however, for now, alongside @Overwrite, please avoid them if possible and privilege using options provided by MixinExtras: +  * @Redirect and @ModifyConstant mixins cannot currently be nested (applied by more than one mod in the same area at the same time). This might change later in development - however, for now, alongside @Overwrite, please avoid them if possible and prioritize using options provided by MixinExtras: 
-    * MixinExtras, a library for Mixin bundled with Fabric, provides alternatives to the aforementioned options that can chain when used in the same place as another Mixin, and should be privileged by default. Namely, @WrapOperation and @ModifyExpressionValue can be used rather than @Redirect and @ModifyConstant for most applications, and @Overwrite should almost //never// be used over @WrapMethod. The less compatible annotations may still be preferable if you specifically wish for the game to crash if another mod tries to replace the same target with a non-chaining Mixin, but otherwise should not be used. To understand basic usage of MixinExtras tools see the [[https://github.com/LlamaLad7/MixinExtras/wiki|MixinExtras wiki]].+    * MixinExtras, a library for Mixin bundled with Fabric, provides alternatives to the aforementioned options that can chain when used in the same place as another Mixin. Namely, @WrapOperation and @ModifyExpressionValue can be used rather than @Redirect and @ModifyConstant for most applications, and @Overwrite should almost //never// be used over @WrapMethod. The less compatible annotations may still be preferable if you specifically wish for the game to crash if another mod tries to replace the same target with a non-chaining Mixin, but otherwise should not be used. To understand basic usage of MixinExtras tools see the [[https://github.com/LlamaLad7/MixinExtras/wiki|MixinExtras wiki]].
  
   * If you're adding non-private custom fields or methods to a target class, prefix them with "[modid]$" or another unique string and annotate them with @Unique. Essentially, "mymod$secretValue" instead of "secretValue". This is to avoid conflicts between mods adding a field or method named the same way.   * If you're adding non-private custom fields or methods to a target class, prefix them with "[modid]$" or another unique string and annotate them with @Unique. Essentially, "mymod$secretValue" instead of "secretValue". This is to avoid conflicts between mods adding a field or method named the same way.
tutorial/modding_tips.txt · Last modified: 2025/09/22 16:23 by gauntrecluse