Now that we have a working Eclipse and MCP workspace, we could dive straight in and start coding our mods. However there are two topics which are still useful to cover before we do so. If you are reading this tutorial to get started as quickly as possible, you can skip these steps if you wish but I strongly recommend you read at least the first point. The information covered in this step will save you a lot of time and pain later on.
If you installed Java from the Oracle site then chances are you installed the most up-to-date version, which at time of writing is Java 8 (or 1.8.x_xx), for Minecraft development however this is not the best version to use. If you are not sure what versions of Java you have installed, you can find out by doing the following:
The reason that we want Java 6 is that Java 7 is still not fully ubiquitous “in the wild”, there are still a lot of systems running Java 6 and compiling your mod with Java 7 or 8 can lead to it not running for some users who don't yet have Java 7. Whether or not they should get Java 8 is not a debate for this tutorial, suffice to know that if you are developing for Minecraft you should use Java 6.
You can still download the Java Development Kit from Oracle although you will have to register on the Oracle site to do so, this is relatively painless though and you do not need to wait for the verification email before you can continue to the download.
Once you have Java 6 set up, you need to tell Eclipse that this is the Java Runtime Environment (JRE) that you'd like to use.
(Where the “xx” is the revision number of the 1.6 JDK. You may also use a “jre6” installation if you have one.)
Eclipse is now configured to use Java 6, you can optionally skip the next part and move to the next section of the tutorial if you wish.
Eclipse is an incredibly powerful tool, however “out of the box” some of the settings are not ideal and some optional warnings and errors which help immensely are turned off by default. In this section I will cover which settings you should enable to get the most out of Eclipse when writing your mods.
Before we do that however, we need to exclude the decompiled source from our new settings, otherwise all hell will break loose since there are so many violations of these rules in the decompiled MCP source that we'd be swamped in meaningless errors and warnings before we even started. To do this, we will just tell the project to use its own settings, which it will inherit from the current settings we have now.
Now we've frozen the settings for “Client”, we're free to make the global settings more strict.
Of the above, if you choose to make no other modifications, requiring @Override is by far the most critical. The reason for this being that since all methods in Java are virtual methods, without this annotation some potentially catastrophic programming errors can occur which could easily be spotted at compile-time if this annotation is used.
For example, without using @Override, the following situations can occur
Needless to say, it's a bit of a mystery why this option is turned off by default, other than the fact that the Java specification doesn't require it, not even having it set to “Warning” as a default is completely mystifying.
Quite often when making mods for Minecraft, you will want to invoke OpenGL functions in your code. As recommended in the LWJGL documentation, using Java's static import feature makes this much more comfortable and familiar if you have used OpenGL before in other languages such as C++. However, static imports are a nuisance because they aren't auto-completed by Eclipse under normal circumstances, however a simple change will allow auto-completion for these static imports and automatic creation of the static import declaration in classes where you use them.
Note, it's best to ignore the decompiled source's use of LWJGL, which uses qualified calls throughout - this is solely due to the decompile process and you can rest assured that this is not representative of the original code and isn't a practice you should emulate in your own code!
Note that the usage of OpenGL has changed in Minecraft 1.8, see below for setting up static imports for Minecraft 1.8 and later
To turn on the static auto-completion, we need to add candidate classes to the Content Assist Favourites screen:
This ensures that the first static import used will import the entire class, which is neater than ending up with dozens of individual method imports
In 1.8 the procedure is exactly the same as for 1.7, but instead of importing all of the lwjgl namespaces, you need only import a single convenience class provided by LiteLoader:
This new class replaces all of the lwjgl calls with calls to Mojang's new GlStateManager class.