Creating Mods for Manic Digger

Over time I’ve been asked multiple times how to write a mod for Manic Digger but had no example at my hands.
So here is a basic mod that should help getting started with modding in Manic Digger.

Starting simple

The most simple (and useless) mod possible would be this:

Now what does that do?
The answer is simple: Nothing. Nothing at all.

Now to explain this a little more:
Every mod must have the two methods PreStart and Start. These are required as they are called by the game when loading the mod.
If these are not present, mod loading will fail.

If you’re more familiar with programming: We’re implementing the interface IMod here, which specifies these 2 methods.
If you don’t have any clue what the previous sentence was about, you’re still fine. No need to worry about that nerdy stuff 😉


The two default methods

As I just mentioned, PreStart and Start are strictly required when creating a mod.
When you’re developing a mod, it’s quite useful to know when exactly these get executed.

Well, you will see it’s quite simple:

  • PreStart() as the name indicates is called before the mod is actually loaded. Typically you specify mod requirements here.
    This piece of code tells the server to load the mod “Default” before this one as we depend on it.
    Okay, not really, but it’s a nice example of what is done here usually.
  • Start() will be called when the Server is loading the mod. This is where you want to put your initialization code.
    This little piece of code will print the message “Hello World!” in the server console when the mod is loaded.

The Mod Manager

Having seen the code snippets so far you might wonder what that ModManager thing is about.
It’s quite simple: Everytime you want to interact with the game you ask the ModManager to do it for you.
That way you don’t have to worry about technical stuff and just get things done quickly.

A good example for it’s usage is sending a message to all players. I’m sure you don’t want to do all the network stuff when you can simply write it like this:

You can have a look at all available methods including a brief usage description here:
https://github.com/manicdigger/manicdigger/blob/master/ScriptingApi/ModManager.cs


The example mod

After reading all this here’s the source for a working example mod that adds a new block to the game.
Feel free to mess around with is as you like.


Should you have any further questions regarding this tutorial or found something I missed feel free to tell me in the comments below.

Happy coding 🙂


Leave a Comment