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/07/24 13:08] – added "Applying changes without restarting Minecraft" fudgetutorial: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 22: Line 20:
   * Packets always begin execution on the **network thread**, however accesses to most Minecraft things are not thread-safe. In general, if you're not exactly sure what you're doing, you want to parse the packet on the network thread (read all the values out), then use the **task queue** to perform additional operations on the **main server/client thread**.   * Packets always begin execution on the **network thread**, however accesses to most Minecraft things are not thread-safe. In general, if you're not exactly sure what you're doing, you want to parse the packet on the network thread (read all the values out), then use the **task queue** to perform additional operations on the **main server/client thread**.
  
 +===== Pitfalls =====
  
-===== Applying changes without restarting 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.
-Restarting Minecraft can take a hefty amount of time. Thankfully, there are tools that allow you to some apply changes while the game is running.  +
-==== Reload changed classes ==== +
-In Eclipse or Intellij IDEA, run Minecraft in debug mode. To apply changes in code, +
-do ''run -> reload changes classes'' in Intellij or save in Eclipse. +
-Note: this only allows you to change method bodies. If you do any other kind of change, You will have to restart. +
-However, if you use [[http://dcevm.github.io/|DCEVM]], you will be able to do most changes, including adding and removing methods and classes.  +
-==== Reload textures ==== +
-After you make a change in a texture (''.png'') asset, you can press ''F3 + T''  to apply the change without restarting Minecraft. +
tutorial/modding_tips.1563973739.txt.gz · Last modified: 2019/07/24 13:08 by fudge