🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for:
1.21
This page is written for:
1.21
This page will go over the structure of a Fabric mod project, and the purpose of each file and folder in the project.
fabric.mod.json
The fabric.mod.json
file is the main file that describes your mod to Fabric Loader. It contains information such as the mod's ID, version, and dependencies.
The most important fields in the fabric.mod.json
file are:
id
: The mod's ID, which should be unique.name
: The mod's name.environment
: The environment that your mod runs in, such as client
, server
, or *
for both.entrypoints
: The entrypoints that your mod provides, such as main
or client
.depends
: The mods that your mod depends on.mixins
: The mixins that your mod provides.You can see an example fabric.mod.json
file below - this is the fabric.mod.json
file for the reference project that powers this documentation site.
fabric.mod.json
{
"schemaVersion": 1,
"id": "fabric-docs-reference",
"version": "1.0.0",
"name": "Fabric docs reference",
"icon": "assets/fabric-docs-reference/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"com.example.docs.FabricDocsReference",
"com.example.docs.event.FabricDocsReferenceEvents",
"com.example.docs.command.FabricDocsReferenceCommands",
"com.example.docs.effect.FabricDocsReferenceEffects",
"com.example.docs.potion.FabricDocsReferencePotions",
"com.example.docs.sound.FabricDocsReferenceSounds",
"com.example.docs.damage.FabricDocsReferenceDamageTypes",
"com.example.docs.item.FabricDocsReferenceItems",
"com.example.docs.block.FabricDocsReferenceBlocks",
"com.example.docs.component.FabricDocsReferenceComponents"
],
"client": [
"com.example.docs.FabricDocsReferenceClient",
"com.example.docs.client.command.FabricDocsReferenceClientCommands"
],
"fabric-datagen": [
"com.example.docs.FabricDocsReferenceDataGenerator",
"com.example.docs.damage.FabricDocsReferenceDamageTypesDataGenerator"
]
},
"mixins": [
"fabric-docs-reference.mixins.json",
{
"config": "fabric-docs-reference.client.mixins.json",
"environment": "client"
}
],
"depends": {}
}
As mentioned before, the fabric.mod.json
file contains a field called entrypoints
- this field is used to specify the entrypoints that your mod provides.
The template mod generator creates both a main
and client
entrypoint by default - the main
entrypoint is used for common code, and the client
entrypoint is used for client-specific code. These entrypoints are called respectively when the game starts.
public class FabricDocsReference implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final String MOD_ID = "fabric-docs-reference";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
LOGGER.info("Hello Fabric world!");
}
}
The above is an example of a simple main
entrypoint that logs a message to the console when the game starts.
src/main/resources
The src/main/resources
folder is used to store the resources that your mod uses, such as textures, models, and sounds.
It's also the location of fabric.mod.json
and any mixin configuration files that your mod uses.
Assets are stored in a structure that mirrors the structure of resource packs - for example, a texture for a block would be stored in assets/modid/textures/block/block.png
.
src/client/resources
The src/client/resources
folder is used to store client-specific resources, such as textures, models, and sounds that are only used on the client side.
src/main/java
The src/main/java
folder is used to store the Java source code for your mod - it exists on both the client and server environments.
src/client/java
The src/client/java
folder is used to store client-specific Java source code, such as rendering code or client-side logic - such as block color providers.