Creating a minecraft mod

in #minecraft6 years ago

I'm working on a small mod for a friend who is doing a daily Minecraft Let's Play (over 2000 episodes, in german) and I bashed my head on the desk a couple times when I started and still do occasionally when a new version is released. To spare you some of the headaches, I think it would be nice to have a small series of posts about minecraft modding. You are reading the very first post of that series now. 😉

Alternatives to creating a mod on your own

Minecraft supports modding from a very early date and to me the modding community is a big part of the success story. But if you want to modify your game experience, there are a lot of things you can do before you have to dive deep into development.

Custom behavior can be created via command blocks and people created amazing things with those alone. The game also supports different game modes including a spectator, the world border has been used in surprising ways.

Modifing recipes, changing loot drops and a lot more crazy things got a lot easier with v1.12. You can distribute your recipes in a bundle called datapacks now and I wouldn't be surprised if we see modpack-alternatives which do not rely on new blocks or items purely based on datapacks soon.

Develop a minecraft mod with MinecraftForge

Minecraft Forge is the defacto standard of modding. There is not a lot of structured documentation out there and the forums are a pretty toxic environment for beginners, but as a seasoned Java Developer it was not too hard to hack my way through the MinecraftForge and figure a couple things out purely by looking at other mods code. Most of the mods are open source projects living on Github, so there is a very large set of code available to read. I recommend doing just that when you have an issue with your mod and you can not ask a knowledgable friend in person.

Download the Java Development Kit (JDK)

First of all, modding is only available for the PC version of Minecraft called the "java edition". There are several other editions on Xbox, Mobile and native Windows, but as far as I know you can not mod them. So, this whole description is for the java edition - and we do need the Java Development Kit to write code for it. The development kit is a set of classes and tools that is common for all java applications.

Download the JDK with the following terminal commands:

curl -o jdk.tar.gz -LH "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz

Extract the archive:

tar xvzf jdk.tar.gz

You now have a directory called jdk1.8.0_161 with all the necessary tools to develop java applications.

Download the MinecraftForge Development Kit (MDK)

I recommend using the recommended version from http://files.minecraftforge.net/ - Look for the link to the MDK, you can copy it right from the page. But make sure to remove the adfly stuff from the copied URL before you try to download the file. 🤐

Download the MDK:

curl -o forge-mdk.zip http://files.minecraftforge.net/maven/net/minecraftforge/forge/1.12.2-14.23.1.2555/forge-1.12.2-14.23.1.2555-mdk.zip

Extract the MDK:

unzip -d forge forge-mdk.zip

You now have a directory called forge with a skeleton mod.

Prepare the development environment

Before we can dive into the development of a mod, let's make sure that we setup the development environment. Luckily with Java and MinecraftForge there is not much we have to do, the whole process is automated.

Run the following terminal commands inside the directory forge:

# set the path to the JDK
export JAVA_HOME=/jdk1.8.0_161
# download & set up development tools for MinecraftForge
./gradlew setupDecompWorkspace

It will take a couple minutes depending on your internet connection, because the build tool gradle is downloading the internet (I'm joking, it's downloading all kinds of dependencies that MinecraftForge is build on). I won't dive into gradle as a build tool, because it's not really relevant to this guide, but if you want to read more, the documentation for Java applications is a good place to start.

Modify the name of the mod

We are now ready to build our first mod from the extracted skeleton. But let's at least modify the name of the mod. Open the file build.gradle in your editor and look for the following lines:

version = "1.0"
group = "com.yourname.modid"
archivesBaseName = "modid"

Modify them like this:

def nameOfTheMod = "mysupermod"
version = "1.0"
group = "com.yourname." + nameOfTheMod
archivesBaseName = nameOfTheMod

Now open the file src/main/resources/mcmod.info and edit replace this line:

"modid": "examplemod",

with the following:

"modid": "mysupermod",

Now we will modify another file, but this is the last one. Open src/main/java/com/example/examplemod/ExampleMod.java and replace the line:

public static final String MODID = "examplemod";

with the following line:

public static final String MODID = "mysupermod";

The modid is a central element of MinecraftForge mods, and I will describe it in a later post. For the moment, just think of this modification as "we are renaming our mod".

Please not that I skip a couple things that we definitely should do, but are slightly out of scope for this introduction article. We will get to it later in the series.

Build and run the mod

That's all we need to compile the mod and run it in a Minecraft client.

# build the JAR for the mod skeleton
./gradlew build
# run Minecraft with the mod
./gradlew runClient

After a while you should see a Minecraft window pop up. Check the loaded mods for an entry like this:

minecraft_loaded_mods.png

Get the Mod JAR

After building the mod, you can find the JAR file in directory build/libs/, it's probably called mysupermod-1.0.jar if you modified the files like described.

Grab that JAR file and drop it into your regular modded minecraft client in directory mods and you should be able to play with your mod.

What's next

In the next posts, I'll show you how to

  • add a new block
  • modify the world generator to spawn your new block
  • add a smelting recipe to process the block

If you liked this post, please upvote, share and comment! I'd like to hear what you'd like to see in this series of post.

Coin Marketplace

STEEM 0.20
TRX 0.13
JST 0.029
BTC 67402.68
ETH 3481.04
USDT 1.00
SBD 2.65