How to Write your First Minetest Mod

I am a big fan of Minecraft. I remember buying it in 2011 from Mojang for 15 euros. It’s one of the few games I bought. It’s also one of those games I visit once in a while. My recent experiments with it has been using Minecraft pi and Minecraft API mostly around the concept of teaching programming using games. It’s free (as in beer)1 and comes with API to play. On a non-Pi installations you need setup plugins to get access. Also since the license is unclear, I am not sure if I can use it liberally like I would use a Free and Open Source Software. Hence the exploration began and I found Minetest.

Minetest

Minetest is an open source voxel game engine. Play one of our many games, mod a game to your liking, make your own game, or play on a multiplayer server. Available for Windows, macOS, GNU/Linux, FreeBSD, OpenBSD, and Android.

Minetest – An open source voxel game engine.

Its FOSS, meant for moding and runs on all platforms. Everything I wanted. So quickly I started playing Minetest. It’s not bad. You will face an issue here and there 2 but on my Ubuntu it felt great. Next thing was to test how easy it is to mod 3 and introduce a new feature. I started by coding a new type of block. Here are the notes from that exercise.

Installation and Running

On Ubuntu installation is straight forward. It’s not difficult for other platforms too.

#install
sudo apt-get install minetest
#run by just calling
minetest

Minetest can host a server where you and your friends can share games and save work. But here we are going to play a local game in creative mode with no damages. You can create a world if there are no worlds. By clicking on New.

Create a world and start a local game.

Once you start. You can play like usual. At any point you can exit by pressing ESC key. You can restart by selecting the same world.

Mod structure

On Ubuntu, Minetest configurations are stored under users home folder – ~/.minetest. The mods are stored inside the mod folder i.e ~/.minetest/mods/ each mod will have its own folder under mods. Usually installing mod means copying the mod code to this folder. With expanded mods folder with two mods mod_1 and mod_2 this is how your ~/.minetest folder will look

init.lua – This is the only REQUIRED file. This will run as soon as the game loads.

mod.conf – Not a must but it’s good to have. It will contain the configuration

depends.txt – To be compatible with 0.4.x you need to mention other mods your mod depends on. It’s just a listing. For modern version he dependency is part of mod.conf

functions.lua – Functions

textures folder with images – If you want images as part of your game

models folder with models

sounds folder with sound – if you want sound files

Your first mode

Before you start writing your first mod, please do know all the mods are written in Lua Scripting language. It’s easy to learn and code. You can try this 15 mins tutorial if you are short on time. With that let’s start our first mod which is just an introduction of a new block type into the game.

We will create a new mod called ‘thej’, so start with creating a folder called ‘thej’ under mods folder, i.e ~/.minetest/mods/thej and then create a mod.conf file to define our mod. mod.conf is a simple key value configuration file. Add name, description and depends. Our module is dependent only on ‘default’ mod. The contents of mod.conf will look like this

Here as you can see we are defining an item 4 for the mod thej and name of it is squares. Then we are defining images for the tiles. That’s it, the block is ready to be used.

Block

But wait we have used minetest_block.png in our tiles set. A block has six sides and hence one has to define six images in the tiles. The order is shown below. To keep it simple, I have used the same image on all sides. I created the image using an online tool called piskelapp. I created a 16×16 pixel art and then exported into 100px X 100px png image. Then added it under the folder called textures. At this point my folder structure looks like this

Archives

Archives

Copyright and Disclosure

(C) Thejesh GN.The views expressed on this site are mine (Thejesh GN) alone and do not necessarily reflect the views of my employer. Please read the terms and conditions before reading or commenting on this blog.