User Tools

Site Tools


tutorial:modding_tips

Modding Tips

Here's a collection of assorted Fabric-related modding tips gleaned from experiences on advising users of the API.

Basics (API)

  • 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
    • EntityType.Builder → FabricEntityTypeBuilder
  • 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.

Mixins

  • 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 (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).
  • 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.

Networking

  • 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

  • Avoid using the java.awt package and its subpackages. AWT does not work well on all systems. Several users have reported that it hangs Minecraft.
tutorial/modding_tips.txt · Last modified: 2021/04/06 20:27 by florens