Skip to content

Getting Started

MehVahdJukaar edited this page Jul 25, 2026 · 1 revision

Getting Started

How to add Moonlight to your mod.

It's a multiloader library for NeoForge, Forge and Fabric. Most of the API lives in the common source set, so you write your feature once and it works everywhere.

Adding the dependency

repositories {
    maven { url = uri("https://registry.somethingcatchy.net/repository/maven-public/") }
}

One artifact per source set:

// common
modCompileOnly("net.mehvahdjukaar:moonlight-common:$moonlight_version")
accessTransformers("net.mehvahdjukaar:moonlight-common:$moonlight_version")

// fabric
modImplementation("net.mehvahdjukaar:moonlight-fabric:$moonlight_version")
modRuntimeOnly("net.mehvahdjukaar:codecui-fabric:$codecui_version")

// neoforge
modImplementation("net.mehvahdjukaar:moonlight-neoforge:$moonlight_version")
modRuntimeOnly("net.mehvahdjukaar:codecui-neoforge:$codecui_version")

moonlight_version is the full <mc version>-<mod version> string, like 1.21.1-3.1.4d. codecui_version looks the same, like 1.21.1-1.0.1.

Important

codecui is required. Moonlight bundles it with JiJ, so players never need to install it, but that also means it isn't on the dev runtime classpath. Without the modRuntimeOnly lines above your dev game crashes with a NoClassDefFoundError on a schema codec class. Runtime only is enough unless you declare schemas yourself, in which case make it modImplementation.

Mod init

The one bit of architecture the library expects. From your loader entry point (Forge: mod constructor, Fabric: main entry point):

public static void init() {
    // Forge/NeoForge only, must be first
    // RegHelper.startRegisteringFor(modEventBus);

    PlatHelper.addCommonSetup(MyMod::setup);

    if (PlatHelper.getPhysicalSide().isClient()) {
        MyModClient.init();
    }
}

That's it. Registration happens in static fields, so make sure your init touches those classes. See Registration and Platform Helpers.

Examples

The repo has small example classes, one per system, kept compiling against the current branch: common/src/example/java. Each wiki page links the one that matches it.

Clone this wiki locally