This is an old revision of the document!
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
{ "mixins": [ "modid.mixins.json", { "environment": "client", "config": "modid.client.mixins.json" } ] }
Providing a String "<modid>.mixins.json"
inside the mixins array tells Fabric to load the mixins defined inside the file <modid>.mixins.json
on both client and server.
Providing an Object allows for deeper customization.
Taking a closer look at the Object from lines 4 to 7:
{ "environment": "client", "config": "modid.client.mixins.json" }
The environment
field is set to 'client'. Which lets Fabric know we want these mixins to only be loaded on the client.
The config
field should point to the file where all the mixins for that environment
are defined.
Register Mixins
In the previous section, you learned about registering your client/server <modid>.mixins.json
and environment specific <modid>.<environment>.mixins.json
files.
We still have to define which mixins to load and where these mixins are located.
Inside your registered <modid>.<environment>.mixins.json
:
{ "required": true, "minVersion": "0.8", "package": "net.fabricmc.example.mixin", "compatibilityLevel": "JAVA_8", "mixins": [], "client": [ "TitleScreenMixin" ], "injectors": { "defaultRequire": 1 } }
The 2 main fields you should worry about when getting started with mixins are the package
field and client
array.
The package
field defines which folder (package) to find the Mixins in.
The client
array defines which classes should be loaded.
Following that logic: net.fabricmc.example.mixin.TitleScreenMixin
is the mixin.