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
Next revision
Previous revision
tutorial:modding_tips [2019/09/16 16:46] – [Pitfalls] changed code to be surrounded by monospace block manxboytutorial:modding_tips [2024/04/15 02:25] (current) solidblock
Line 6: Line 6:
  
   * Due to the injection-based approach of Fabric's API development, we don't tend to patch classes outright in a way visible to the end user. As such, you may occasionally find Fabric extensions of vanilla classes when you run into something you cannot do. For example:   * Due to the injection-based approach of Fabric's API development, we don't tend to patch classes outright in a way visible to the end user. As such, you may occasionally find Fabric extensions of vanilla classes when you run into something you cannot do. For example:
-    * Block.Settings -> FabricBlockSettings+    * Block.Settings -> FabricBlockSettings (except 1.20.5)
     * EntityType.Builder -> FabricEntityTypeBuilder     * EntityType.Builder -> FabricEntityTypeBuilder
-  * While an official configuration system is being worked on, one replacement for now is to use Java .properties or JSON. 
   * For a built-in resource pack or data pack, please ensure that an "assets/[mod id]" or "data/[mod id]" directory path is present, respectively! IDEA users might find themselves accidentally creating an "assets.[mod id]" directory - this won't work.   * For a built-in resource pack or data pack, please ensure that an "assets/[mod id]" or "data/[mod id]" directory path is present, respectively! IDEA users might find themselves accidentally creating an "assets.[mod id]" directory - this won't work.
  
Line 14: Line 13:
  
   * 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.
-  * To modify a constructor, use "<init>" (or "<clinit>" for static constructors) as the method name. Please note that @Inject on constructors only works with @At("RETURN") - no other forms of injection are officially supported! +  * @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 (or discuss bringing the hook over to Fabric's API, or - for more niche things - consider putting it in a small JAR-in-JAR API). 
-  * @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 (or discuss bringing the hook over to Fabric's API, or - for more niche things - consider putting it in a JAR-in-JAR once that's out). +  * If you're adding non-private custom fields or methods, 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 custom fields or methods, especially if they're not attached to an interface - prefix them with "[modid]_" or another unique string. Essentially, "mymod_secretValue" instead of "secretValue". This is to avoid conflicts between mods adding a field or method named the same way!+
  
 ===== Networking ===== ===== Networking =====
Line 24: Line 22:
 ===== Pitfalls ===== ===== Pitfalls =====
  
-  * Avoid using the ''java.awt'' package and its subpackages. AWT does not work well on all systems. Several users have reported that it tends to hang Minecraft.+  * Avoid using the ''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.
tutorial/modding_tips.1568652365.txt.gz · Last modified: 2019/09/16 16:46 by manxboy