How to create a Minecraft mod? - The Complete Tutorial | Accelerated Ideas
Home | News
Copyright © Accelerated Ideas 2005-2014

How to create a Minecraft mod? - The Complete Tutorial

How to create a Minecraft mod? - The Complete Tutorial
Tag: minecraft

This tutorial will guide you through the process of decompiling the Minecraft source code and editing particular sections of code to create your very own Minecraft mod. In fact it's not as hard as you might think to create your own Minecraft mod.

It's recommended that you have some programming experience, but it's not essential. Most people find it easy to look up Java commands online and enjoy the challenge of learning something new.

Java what!!?



In case you've never heard of Java, its an object oriented programming language, similar to the latest .NET development languages like C#. However, it's been around far longer and is widely consider the original true developer language of choice. Java code is separated into logical units called classes that make it easier to reuse pieces of code. They also make it easy to manage large projects such as Minecraft.

Don't let all that programming jargon put you off, Minecraft is actually really well structured making it easy to make modifications.

Applications you'll need to edit Minecraft source code



Before you can create a mod, you'll need to download the following applications:

1. Java SDK
The development kit that lets you compile Java code into executable programs.
Java SDK

2. MCP – The Minecraft Coder Pack
This is an awesome pack that contains a selection of folders and batch files to help you decompile java code, obfuscate code and run mods in a test environment. You've got no chance without this!
Minecraft Coder Pack

3. Notepad++ - A Source code editor with syntax highlighter
Notepad++ is a free application that makes editing source code much easier thanks to its syntax highlighter. It's far better than the bog standard notepad you get with Windows.
Notepad++

Step by step setup



1. Install the Java SDK (accept the defaults)

2. Install MCP, we recommend choosing C:\MCP as your installation folder

3. Install Notepad++ (again accept the defaults)

4. Create an environment PATH.

Just right click on My Computer and click Properties. Go to the Environment Variables section. Scroll down the list of System Variables and edit the PATH variable. Add a semi colon at the end and paste the full path to the bin folder of the Java SDK e.g.

C:\Program Files\Java\jdk1.6.0_24\bin

5. Copy the Minecraft bin and resources folders from your Minecraft installation folder into the jars folder of the MCP installation.

e.g. C:\Documents and Settings\User\Application Data\.minecraft\bin --> C:\MCP\jars

Decompiling the Minecraft source code



If you've ever had a dig around the minecraft.jar file you'll have seen a tonne of Java class files. It's no good opening these files up and attempting to change a few things because the code is compiled and obfuscated. Its just doesn't make any sense, even in coding terms! And that's the point of obfuscation, it's supposed to be compact and smaller in size.

To be able to view the original Minecraft source code you'll need to turn to our friend MCP and decompile it using their pre-built batch files.

The batch file (.bat) we're looking for is called decompile.bat and it's located in the root of the MCP installation folder. Just double click it to start running.

Creating a Minecraft mod

Ok, now we've got the full original Minecraft source code! Its saved in the MCP\sources folder. E.g.

C:\mcp\sources\minecraft\net\minecraft

If you open the src folder, you'll notice that all the original Minecraft class files are fully readable and the code actually makes some sense.

Editing a Minecraft class file



Ok, so you've got all the original source code..now what?

Now the fun begins, all the Minecraft class files are named appropriately. For example, we have an EntitySlime.java class that controls the Slime mod creature. It's got methods to control the mobs texture, the sound to play when it gets hurt and like other mobs the onUpdate method controls what the mob does on each update.

If we wanted to edit how the Slime mob behaves we would need to edit the EntitySlime.java file. To do this we turn to our next friend - Notepad++.

Just open Notepad++ and drag and drop the EntitySlime.java file onto the notepad text editor. It will look something like this:

Creating a Minecraft mod

In this example, we're going to just change the texture that the Slime mob uses (it's a good example if you wanted to copy the Slime mob, create a new minecraft mob and also use your own texture).

Ok, so just type into the text editor and change the texture. In this example, we'll just change it to use the cow texture because we're not going to create a whole new texture.

Creating a Minecraft mod

Recompiling the source code



Now that you've made your change its time to recompile the code. Just run the recompile.bat file and the code will be compiled again.

If there are any errors during compilation (if you have any syntax errors i.e. your coding is dodgy) you can find these in the MCP\logs folder in the minecraft_compile.log file.

If there are errors, you'll need to correct your mistakes before you can test your changes. Go back and review the code changes you made, did you type something by mistake?

Testing the new changes



After the codes compiled, you can run the new Minecraft code using the MCP file called test_game.bat. Just double click the file and Minecraft will run as usual.

Obfuscating your changes



If you want to distribute your changes to other Minecraft players and post them on the Minecraft Forum you'll need to perform a few more steps.

1. Firstly, open the MCP\conf folder and edit the client_obfuscation.txt file. Clear the text in this file and replace it with the names of the classes you have changed .e.g EntitySlime. It's one class per line. Now save the file and close it.

2. Run the reobf.bat file by double clicking it (its in the root of the mcp folder).

3. Your changed classes will be saved in the MCP\final_out\minecraft

4. These will look like the obfuscated files you find in the minecraft.jar file e.g. qm.class

5. These classes are ready to distribute as a new mod..congratulations!!

Tips



  • Don't expect success overnight, programming takes time. Get familiar with the Java language and learn from the code that Notch has created. It's taken him years to get this far, so respect his work and learn from it!
  • Start simple, change a single line of code, recompile and test the changes. The key to success is change little and test often. Its easier to find mistakes if you haven't changed tonnes of code before testing it.
  • If you want to distribute your new mod, don't make large changes to Minecraft class files as they could conflict with other mods. Try and separate your mod as a new class and hook into it with minimal code.
  • Once you've had a bit of practice using MCP and trying to create a mod, why not try using the test_mod.bat file? This allows you to enter commands into the Minecraft environment and test conditions and execute methods.
  • If you distribute mods, keep em clean! Others might want to expand your mod later so make it nice and readable like Notch has done.





Similar


Crafting Recipe for the Armour Stand in Minecraft 14w32a

Crafting Recipe for the Armour Stand in Minecraft 14w32a


Rather than my usual weekly snapshot post I wanted to give you a quick tuto..
How to Craft Minecraft Banners (Flags) including Colours and Patterns

How to Craft Minecraft Banners (Flags) including Colours and Patterns


Minecraft Banners (Flags) were added in Minecraft 1.8 (snapshot 14w30a). Th..
Whats New in Minecraft 14w30a - Banners and Flags

Whats New in Minecraft 14w30a - Banners and Flags


You can always tell when Jeb's been working on Minecraft because we usually..
Yogscast’s Yogsventures Cancelled - Kickstarter Backers Conned

Yogscast’s Yogsventures Cancelled - Kickstarter Backers Conned


Once again the crew over at Yogscast have upset a hell of a lot of people a..
Minecraft PE 0.9.0 - How to change modes from Creative to Survival

Minecraft PE 0.9.0 - How to change modes from Creative to Survival


With the latest version of Minecraft Pocket Edition there are now many new ..
Minecraft PE 0.9.0 - Running out of memory error FIX

Minecraft PE 0.9.0 - Running out of memory error FIX


MCPE 0.9.0 is finally available to download for iPhone, iPad and Android de..

Comments


GuestModgamer99
3/15/2011

Thank you so much I've been trying to recompile the minecraft code with eclipse but it wasn't working. Now I can finally start working towards making my first mod. What I was thinking was a portage mod which would go as follows: When you are in sneak mode (holding shift) then you could right click on a boat and it would go on your head. This would be useful if you want to go out and explore so you wouldn't need to bring a lot of boats. Once again I thank you for this amazing post!


GuestJulzso23
3/31/2011

I tried to recompile minecraft and it gives 31 errors :/


GuestMenoob
3/31/2011

thanks for this. but do you have to use the official JDK because using Eclipse doesnt work our for me. and when i ty to decompile the correct files you said it never does it and gives me a few errors.


GuestMe ofc
4/2/2011

Great Tutorial! Help'd me Alot Thanks ! :)


GuestMewMaster13
4/6/2011

When I tried to decompile it said it couldn't find the folder 'minecraft' in the sources folder. So I made it in there. Then it said it couldn't find 'minecraft_server.jar' what should I do???


GuestFootmen
4/8/2011

was wondering what you meant when u say "edit the PATH variable. Add a semi colon at the end and paste the full path to the bin folder of the Java SDK" since I can't paste that line of text into the bin folder, am i reading something wrong?


Guestadmin
4/9/2011

The windows PATH variable is configured via My Computer - Properties. You don't need to add anything to the Minecraft bin folder. Just copy the location (path) to your Minecraft bin folder and paste into the Environment Variables section.


Guestanon
4/9/2011

this is the only piece of information on this i can find on the internet, great post


GuestLacky86
4/10/2011

I love your tutorial :D
But when i went to recompile it gave me a bunch of errors >.>
Help please :}


Guestconnor
4/11/2011

i run decompile.bat and it finishes, then i go into the sources but theres nothing but a folders inside.
????????????
help plz



Guestecho
4/12/2011

keep expanding the folder you find until you get to a gigantic list of .java files.


Guesttirso daniel
8/4/2011

Owww god!

men this is a very good tutorial

you helped me too much
i will try to change the creeper's sound (when ''ignited'')

If i make it i will put the download link :D



GuestMonster Hunter
8/5/2011

THX A LOT! great tutorial))

P.S. for newbies: errors often found if only using minecraft with MODS..if its that, use ''clean'' one first, after recompiling you can add other mods which had given errors till decompiling

...or delete them before and\or after using MCP



Guestvaxivop
8/7/2011

I got 2 problems. FIrst Problem: Step number 4: I have NO idea where the Path is. I right click "computer" click "properties" But i cant find ANYTHING named even close to Environment Variables so therefore i skipped that step.

Second problem: When i decompile it finish it but when i go to Src folder the folder is empty. There is nothing in there. But again when i looked at the log in decompile it also said "Error: Detecting modified Jar. Unpredictible Results". Maybe it has something to do with 2 things: One: I have mods installed. Two: I skipped step 4


Guestpepi
8/12/2011

but how can I create a new block and item???


Guestunknown help
8/13/2011

for some others having problems with the server.jar download it at minecraft.net and multiplayer outdated but free then download extract or just open it copy the server.jar to your mcp jar folders then decompile look at the jar again minecraft minecraft until you see the src folder


GuestJekub
8/17/2011

I dont have the final_out folder. What shall I do?


GuestASSASSIN25
9/10/2011

I can't find client_obfuscation.txt in the conf folder. Help :(



GuestGage
9/15/2011

FML now that I did that environment variable thingy, I can't start MINECRAFT AT ALL!!!! I get the error Error: loading: G:\Java SDK\bin\jvm.dll


GuestAaron
10/10/2011

When i run decompile.bat it says it cannot find path specified.


GuestJens
10/17/2011

If you want to put a custom texture on one of the mobs, where do you place the file?



Post a Comment



Post as anonymous or connect with your favourite social network
Login to Twitter Login to Facebook






Html is not allowed!


Enter the characters shown in the image so we know you're human!









English English  |  Portuguese Portuguese