A mod template for LunarCore with Fabric Loader.
- Source code injection with Mixin (and MixinExtras)
- Easy widen access modifiers with access-widener
- Run/Debug your mod with a single task
Requires JDK 17
- Click on the to create a new repo starting from this template.
- Clone your repo and open it in your IDE (IntelliJ IDEA with Minecraft Dev plugin is recommended).
- Run the gradle task named
runServer
to generate server files torun
dir. (You can stop the task after LunarCore has been started.) - Put LunarCore resources into the
run
dir. - Just write some code.
- Run
runServer
to test your mod.
You can just run the server in run
dir by java "@args.txt"
but with these steps you can run the server without setting up development environment.
Requires Java 17
- Setup standard LunarCore by following these steps.
- Make sure that LunarCore server starts up properly.
- Download build.zip from LunarCoreGameProvider GitHub Actions or directly download here.
- Unzip the build.zip and put the files into your LunarCore folder.
- Run
java "@args.txt"
instead ofjava -jar LunarCore.jar
to launch your server with mods.
Fabric Loader is a lightweight mod loader, usually used for Minecraft. Fabric Loader provides much useful features for creating mods. It recognizes a jar in the mods
folder with a fabric.mod.json as a mod and loads it at startup.
References
Mixin is a framework for Java which makes it easy to inject/hook into the runtime classloading with ASM. Mixin's config is usually named *.mixins.json
(examplemod.mixins.json for this template) and specified by fabric.mod.json with Fabric Loader.
MixinExtras is a plugin of Mixin which provides many useful injectors, and got bundled in Fabric Loader 0.15 or later.
References
access-widener is a tool to widen access modifiers of classes, fields, and methods. You may need to use a private
(or protected
) class, field, or method from your dependency. In that case, you can use access-widener to access it by modifying the access modifier to public
.
This can also be done by Mixin, but access-widener is much easier to use and more efficient, and provides more clean code.
Tip
With Minecraft Dev plugin, you can easily get the access widener entry.
Write code which accesses to the private declaration. Then, press Alt + Enter
and just select Copy AW entry
.
References