-
Notifications
You must be signed in to change notification settings - Fork 56
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.
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.
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.
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.
Basics Platform Helpers Registration Networking Events Configs Config Screen
Resources Runtime Resource Packs Texture Manipulation Resource Helpers Block Set API
Client Custom Models Item Rendering Rendered Textures Post Shaders GUI Toolkit Colors
World Block and Item Interfaces Additional Item Placements Improved Entities Fake Levels World Data Dispenser Behaviors
Utilities Codec Utilities Misc Helpers Commands
Datapacks Villagers Soft Fluids Map Markers Spawn Boxes Global Datapack Folder