Table of Contents

Registering Mixins

Introduction

In this tutorial, you will learn how to register your Mixins through the resources/fabric.mod.json.

Inside your resources folder is where your fabric.mod.json should be.

Use this link to view the Fabric Example Mod's resources folder: Fabric Example Mod Resources

Inside your fabric.mod.json is where you define where Fabric should look for your mixins.json.

Register Mixins with Fabric

To register a mixin you have to tell Fabric where to look. To tell Fabric where to look you need to add elements to the mixins array inside fabric.mod.json

  1. {
  2. "mixins": [
  3. "modid.mixins.json"
  4. ]
  5. }

Providing a String "<modid>.mixins.json" inside the mixins array tells Fabric to load the mixins defined inside the file <modid>.mixins.json.

Register Mixins

In the previous section, you learned about registering your <modid>.mixins.json files.

We still have to define which mixins to load and where these mixins are located.

A typical mixins.json file for 1.21.x development might look like this:

{
  "required": true,
  "minVersion": "0.8",
  "package": "net.fabricmc.example.mixin",
  "compatibilityLevel": "JAVA_21",
  "mixins": [],
  "client": [
    "TitleScreenMixin"
  ],
  "server": [],
  "injectors": {
    "defaultRequire": 1
  },
  "overwrites": {
    "requireAnnotations": true
  }
}

The 4 main fields you should worry about when getting started with mixins are the package field, and the mixins, client, server arrays.

Following that logic: net.fabricmc.example.mixin.TitleScreenMixin is the mixin class that will be loaded on the client.

The other fields' rough function should also be kept in mind to understand when to change them from their defaults, and to understand what happens when another mod you're inspecting changes them:

There are other fields that can optionally be added, most of which only serve specific purposes that are outside of the scope of a general explanation. There is, however, one that is relevant for MixinExtras:

:!: It is fine, especially if you are a beginner, to not necessarily understand the above fields fully. You should ask in the Fabric or SpongePowered Discord about clarifications on any of the concepts or fields you do not understand from this page. It may help improve your overall Mixin comprehension, and will help you have a more complete understanding of the Mixin subsystem.


For further reading, check out the Mixin Javadoc, given specifics here can vary based on version, it may be best to read the JavaDoc from your specific build. (On IntelliJ IDEa) you can middle click on a field in the settings to be taken to the corresponding class that handles that field. See Reading the Minecraft source for general setup for reading external source code, including both MC and libraries, APIs or subsystems like Mixin.