darrenjsmooney

the home of me on the internet

Modifying Minecraft: The Source Code

If you have spent any time on Minecraft, you’ll surely be familiar with the wealth of mods available for the game. Each and every one of these have been created by a member of the Minecraft community by simply accessing the code that is responsible for EVERYTHING you see and interact with in Minecraft and making their own, inspired adjustments. This code is fairly simple to access and the mods are very simple to compile, it’s the stuff in between, namely the programming itself, that will take the most patience and careful consideration. I am by no means an expert in programming in Minecraft, and far from it in general. Nevertheless, even the simple ability to spot certain patterns will get you well on your way to creating your first mod and this will give you a real example of many programming ideas in practice. Of course there is the issue of accessing the code itself. Unfortunately the code isn’t quite in the correct format, unless you know some machine coding, so before you start anything else you are going to need to find away to convert all of the Minecraft code so that it is readable, this is called a higher programming language. Luckily there is handy little tool that will do all the conversion to and from this higher programming language for you! It is called the Minecraft Coder Pack (Download Latest Release Here) and is available for free. This file comes with its own compilers/decompilers which are responsible for the conversion, though for it to work, you’ll first need to go through a few steps to set it up!

(This is for Windows OS)

Before you start, make sure you are confident with making some adjustments to your computers settings. What I will describe below shouldn’t cause any problems, but be aware, sometimes complications just simply happen, so don’t go running hacking and slashing through your system, this goes for anytime you start playing with your computer’s settings. And note the steps you take. If an issue arises, just work backwards and reverse the changes you’ve made. I’ve worked through the steps myself while writing and it all went fine, but of course this may vary from computer to computer. Anyway, disclaimer out the way, down to business….

Getting MCP working!

    1. Download the latest Java Development Kit http://www.oracle.com/technetwork/java/javase/downloads/index.html
      You’ll want to select the JDK download, the latest edition is “SE 7u1″ but you’ll want the latest version at the time of reading. This is required because Minecraft is written in the Java programming language.
    2. Create Path.
      To do this you need to get into your advanced system settings:
      Control Panel -> System -> Advanced/Advanced System Settings -> Environment Variables…    and you should get something like the window below:

      Now, if you scroll down in the System Variables box, you’ll find a variable called “Path”. Click this and then click “Edit…”, this will open a new window,  set this thing aside for now. You must now find the location of the JDK file you’ve just installed. To do this, go into My Computer -> Your hard-disk -> Program Files -> Java -> jdk1.7.0_01  (or jdk…something, the something depending on the version) -> bin. Right-click any of the files you see and look at its properties. It will give you a “Location” which, in my case, is “C:\Program Files\Java\jdk1.7.0_01\bin”, yours should look similar, copy this. Then go back into the “Path” window you opened at the top of this paragraph and paste it at the end of the “Variable value” like so:

      NB: Make sure you remember the semi-colon (;) at the start so it can distinguish from this location and the last.
      Then just click “OK”!
    3. Now we need to sort out the MCP file. To begin with I’d recommend placing this somewhere and extracting it to a normal folder. When you open it up you should see a few folders and a few other things. What you now need to do is copy your Minecraft’s “bin” and “resources” folder into the folder labelled “jars”. Make sure you are taking the bin and resources from a fresh Minecraft, i.e. before you do this, run a “Force Update” on Minecraft.
      Here are two fairly simple ways to find your computer’s Minecraft folder:
      - Run Minecraft, click on Texture packs and then open texture pack folder. This will take you to a folder called texturepacks, the folder this is in is called “.minecraft”, this is where you’ll find “bin” and “resources”. Just copy these two folders into the “jars” folder in the MCP file.
      -Alternatively, open up the “Run” application in windows and type in %appdata% which should show you your .minecraft folder. Then copy and paste the files as mentioned above.

      If you’re interested in creating mods for a Server. Go to the Minecraft site and download minecraft_server.jar http://www.minecraft.net/download then paste this into the “jar” folder.
    4. Next, go into the MCP folder, and there will be a program called “updatemcp” which is a Batch file. Quickly run this to make sure everything is up to date (as the name suggests). Now you need to run “decompile”, this will take everything you have put into the jars and create the higher programming language which you are able to work with. This will take several moments so be patient. You’ll notice that a few new folders have appeared (if all has gone to plan), you are interested in “src”, open this up, open up the succeeding folders and when you get to “client” and “src”, choose “src”.

Before you, there is a total of 928 text files. Each of them has been meticulously written by Notch and his team (but mostly Notch) and include thousands upon thousand of lines of code. You are now staring into the heart of the beast. This is all the instructions, all the mechanics that make Minecraft work. This is where everything from the lowly creeper’s attributes to simply looking up is defined. Believe it or not, Notch has done a very good job at laying out his work and you are in fact looking at a very tidy bit of coding.

__________________________________________________________________________________

I think I’ll end this post here for now. If you want to get your hands dirty then try editing a few of the text files, try experimenting. If you want to test your coding out, run the “recompile” program and run “startclient”, which will start up a special Minecraft client with your mods installed.

If you mess with the code quite a bit and screw it up beyond all hope, simply run the “cleanup” file and then decompile again. You aren’t changing the code in your normal copy of Minecraft , by the way, this is entirely isolated.

In my next “Modifying Minecraft” post, I’ll give you a few pointers in the coding and I’ll show you how to actually finalize your mod to put into your main copy of Minecraft, or even for distribution. If you’re interested in this, keep an eye on the blog!

I hope this has been helpful, please leave feedback if you’re a little unsure with what I’ve discussed and whether I need to clarify any point, it would be very much appreciated. :D

Until next time,

Thanks for reading :)

DM

About these ads

Single Post Navigation

4 thoughts on “Modifying Minecraft: The Source Code

  1. Jonathan on said:

    VERY helpful. I am very confused when it comes to modding Minecraft. I couldn’t even get the Coder Pack to work…until now.

    Thanks :D

    • I’m glad to hear. I found it far from intuitive when I first looked into it. Most guides online would tell you a few things, while omitting a detailed description of how to complete certain steps. Since I managed to get it working myself, I thought it would be helpful to let others , such as yourself, know how to do it. I think that, with modding being such an integral part of Minecraft, Mojang should really think about adding an integrated modding environment. Even if it is simply to bypass the fiddly setting up of the coder pack, that would be enough! Thanks for your feedback :)

  2. WHERE”S THE MCP FILE?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 39 other followers

%d bloggers like this: