Skip to content

Making mods #1: Basics & setting up the SDK

MCMrARM edited this page Sep 17, 2018 · 4 revisions

First you should obtain the ModLoader SDK, You should go to the GitHub downloads page: https://github.com/minecraft-linux/server-modloader/releases, download mod_sdk.zip and extract it somewhere, making sure to write down the path, as you'll need it.

A very simple Example Mod

CoreMod provides us with a simple callback called when the server has been started: void modloader_on_server_start(ServerInstance* serverInstance).

The ModLoader also provides us with several logging functions, check out the log.h header for the list: https://github.com/minecraft-linux/server-modloader/blob/master/include/modloader/log.h. The easiest way to log something from a C mod is to use the modloader_log*() function family - the letter following the function name determines the log level.

The mod loader provides both a C and a C++ API. The C++ API is the recommended way to get started.

Writing mods in C

While you'll most likely want to write mods in C++, here's an example in C:

#include <modloader/log.h>
  
void modloader_on_server_start(void* serverInstance) {
  modloader_logv("TestMod", "Server has been started!");
}

You can compile it using gcc main.c -I ${MODLOADER_SDK}/include/ -L ${MODLOADER_SDK}/lib -lserver_modloader -shared -o libTestMod.so. Make sure to define MODLOADER_SDK before running this command.

Writing mods in C++

The following example uses the C++ logging API instead of the C one:

#include <modloader/log.h>
using namespace modloader;
  
extern "C" void modloader_on_server_start(void* serverInstance) {
  modloader::Log::verbose("TestMod", "Server has been started!");
}

You can compile it using g++ main.cpp -std=c++11 -I ${MODLOADER_SDK}/include/ -L ${MODLOADER_SDK}/lib -lserver_modloader -shared -o libTestMod.so. Make sure to define MODLOADER_SDK before running this command.

Clone this wiki locally