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:
1 2 3 4 5 6 7 8 9 |
using System; namespace ManicDigger.Mods { public class AUselessMod : IMod { public void PreStart(ModManager manager) { } public void Start(ModManager manager) { } } } |
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.
1234public void PreStart(ModManager manager){m.RequireMod("Default");}
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.
1234public void Start(ModManager manager){Console.WriteLine("Hello World!");}
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:
1 |
m.SendMessageToAll("Hey there!"); |
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 🙂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
using System; namespace ManicDigger.Mods { //You should replace ExampleBlock with your Mods name. //This has to be unique among all loaded mods! public class ExampleBlock : IMod { //This is a local reference to the ModManager. Every interaction with the game is done using this object. ModManager m; public void PreStart(ModManager manager) { //Stuff that has to be checked BEFORE the mod is loaded goes here //Best example for this would be a mod requirement: //m.RequireMod("Default"); } public void Start(ModManager manager) { //This just sets the variable defined above to the instance given by the game m = manager; //SoundSets are used to determine the sounds that are played when a player interacts with a block in the game SoundSet sounds = new SoundSet() { Walk = new string[] { "walk1", "walk2", "walk3", "walk4" }, Break = new string[] { "destruct" }, Build = new string[] { "build" }, Clone = new string[] { "clone" }, //3 more are used for weapons but not included here }; //This is a block definition. What you see here is the absolute minimum required. //The block ID and the name of the block. Both need to be unique. ID has to be between 0 and 1024 m.SetBlockType(1000, "Example", new BlockType() { AllTextures = "Unknown", //Sets all textures to be the same DrawType = DrawType.Solid, WalkableType = WalkableType.Solid, Sounds = sounds, //Sets the block sounds to the ones defined above //If you want the block to have some special behaviour, you'll have to add some extra options here. }); /*All available DrawTypes: * Empty, * Solid, * Transparent, * Fluid, * Torch, * Plant, * OpenDoorLeft, * OpenDoorRight, * ClosedDoor, * Ladder, * Fence, * HalfHeight, */ /*All available WalkableTypes: * Empty, * Fluid, * Solid, */ /*All available block options: //Texture stuff * string AllTextures; //Sets all 7 textures to be the same * string SideTextures; //Sets all 4 side textures of the block to be the same * string TopBottomTextures; //Sets top/bottom texture of the block to be the same * string TextureIdTop = "Unknown"; * string TextureIdBottom = "Unknown"; * string TextureIdFront = "Unknown"; * string TextureIdBack = "Unknown"; * string TextureIdLeft = "Unknown"; * string TextureIdRight = "Unknown"; * string TextureIdForInventory = "Unknown"; //General options * DrawType DrawType; //The DrawType to use for the block. Available options listed above * WalkableType WalkableType; //The WalkableType to use for the block. Available options listed above * float WalkSpeed = 1; //The speed of the player when having this block selected * bool IsSlipperyWalk; //Slippery walking when on the block (see Ice) * SoundSet Sounds; //The SoundSet to use. See above for an example * int LightRadius; //If != 0 the block emits light. * bool IsUsable; //If true the block can be used by pressing the E key on it * int DamageToPlayer = 0; //This determines the amount of damage a player receives when inside the block * int WhenPlayerPlacesGetsConvertedTo; //Convert to other block when placed/picked up by a player //Weapon options are not included here! */ //Generally speaking all mod-relevant stuff can be found inside ModManager.cs in source code //This line will add the block to the player's inventory in creative mode m.AddToCreativeInventory("Example"); //These lines add recipes for crafting. Depending on the material requirements you want to choose one. m.AddCraftingRecipe("Example", 1, "Grass", 2); m.AddCraftingRecipe2("Example", 1, "Grass", 3, "Stone", 2); } } } |