Forge ModLoader Setup - TriValleyCoderDojo/Minecraft-Jar-Hacks GitHub Wiki
Getting Your Environment Setup
Before you can start creating your Minecraft mod, you will need to set up a development environment, which will be made up of five different things:
- Java Development Kit (not the JRE, you will need the compiler)
- Eclipse – an Integrated Development Environment (IDE)
- Minecraft Coder Pack (MCP) – a toolkit to compile, decompile, obfuscate, deobfuscate and debug the Minecraft files
- Minecraft Forge (Forge) – a set of open source APIs that allows for the mods to work in Minecraft
- Forge Mod Loader (FML) – allows for mods to be loaded into Minecraft from the filesystem as a packaged archive
There is often some confusion about MCP, Forge and FML. They are often grouped into a single thing, but in truth they are really three separate and distinct components. But the confusion is understandable, since they are distributed together, work very closely together, and really have no purpose as a separate component. The collection of these three components will be called just Forge for the rest of this page.
Since the majority of the aspiring young Minecraft hackers use a Windows computer that operating system will be described in detail here.
If you are using a Mac, follow the instructions here: [Forge ModLoader Setup (Mac OS X)](https://github.com/TriValleyCoderDojo/Minecraft-Jar-Hacks/wiki/Forge-ModLoader-Setup-(Mac OS X))
If you are using a Linux box, then you are probably pretty savvy and will be able to make the translation, or can use Google to look up how to do what needs to be done.
Shutdown Running Java Applications
Before proceeding you will need to make sure that all running Java applications have been shutdown. A good example is a running instance of Minecraft. You will need to shutdown anything that is running with Java. If you are unsure, then it would be a good idea to reboot.
Installing the JDK
The first thing that needs to be done is to install the Java Development Kit (JDK). You need to have the JDK to be able to compile Java class files into byte code. Most of the time, you will not have the JDK. Usually, the Java Runtime Environment (JRE) is installed. However, the JRE only lets you run byte code that has already been compiled, and does not let you compile. You will need to compile Java source code into byte code.
If you are not sure whether you have the JDK installed, you can follow the steps in this PDF document to check: JDK?
However, before you can install the JDK, you need to know if your computer uses 32 or 64 bits. If you do not know, you can follow the steps in this PDF document: How Many Bits?
Once you know the number of bits your computer using, then you can download the JDK from the Oracle download URL: Oracle Downloads
- Open the URL
- Scroll down and find the JDK section
- Click on the DOWNLOAD button in the JDK section
- A new window will appear and you need to make some selections
- Click on the Accept License Agreement radio button
- Click on the version that matches your operating system and number of bits
Note: You do not need to worry about the "Demos and Samples" or JavaFX Demos and Samples" downloads at this time. You will not need them for the Forge.
Once the download completes, all you need to do is click on it to run it, and accept the defaults. Once it has completed, you will have the JDK installed.
Installing Eclipse
Eclipse is a very popular Integrated Development Environment (IDE). It is free and there are many tutorials available, such as Lars Vogel's Eclipse Tutorial. There are other IDEs available (NetBeans, IntelliJ, etc…), but Forge was built around Eclipse. It will be just easier to use Eclipse, and it will be assumed that Eclipse is being used. Eclipse can be downloaded from http://www.eclipse.org/downloads/. You can download either the Java EE or Java package, although I would recommend the Java EE package, because it will allow for web application development later, and as the serious hacker that you are, you will want that. To install Eclipse, follow the tutorial referred to above.
Note: Not all the Eclipse mirror sites are created equally. Sometimes you may start a download with one mirror that is moving very slowly, for instance over 1 hour to finish. In these cases, the best thing to do is to cancel that download and try a different mirror site, which can be found by scrolling down the page.
Installing Forge
The first step for installing Forge will be to create a directory (or file folder) to put it. To make things easier for the mentors and yourself, let's use a standard location for the installation. That way if there are questions or problems, then the mentors will know where to look for things. In addition, later instructions will assume the use of the standard directory. Create the directory
mkdir C:\minecraft\mods
You can do this with the file browser or the command line, either will work.
Next, you will need to download the Forge Suite into this directory from http://files.minecraftforge.net/. When you first land on the page, you will want to find the latest version of FML 1.6.4, which would have -Latest or -Recommended in the name in the Promotion section at the top of the page, or scroll down to the 1.6.4 Downloads section. The latest release was 9.11.1.965 at the time this was written. There will be a number of hyperlinks to choose from for each version. You will want to click on the Src link to start the download.
Once Forge has finished downloading, you want to move the downloaded file (e.g.: forge-1.6.4-9.11.1.965-src.zip) into the C:\minecraft\mods directory, if it was not downloaded directly there. It will be a Zip file, something like forge-1.6.4-9.11.1.965-src.zip. You will need to extract it in the C:\minecraft\mods directory.
For the extracting, you will want to use either 7zip or WinRAR (if you have paid for it), but you do NOT want to use the default Windows extractor, because it will cause problems. 7zip is free and can be downloaded from 7zip Downloads. With 7zip you can right mouse click on the zip file and a fly-out menu will appear, select "7-Zip-> Extract Here". After the extraction is complete, it will be extracted as the forge directory.
Next, you will need to complete the installation of your Forge development environment. Forge comes with a bunch of automated scripts that will do a lot of configuring, downloading, decompiling and so forth. It really does a lot, and fortunately for us, we really don't need to understand any of it. We just need to let the Forge install do what it does. There is a command that you will need to run, install.cmd, and the best way to run it is from a new Command window. That way you will be able to keep the text in the window and be able to review it. If you just clicked on it from the file browser, the window will disappear.
- Open a new Command window by clicking on Start and then enter cmd.exe in the Search box
- In the Command window change to the Forge directory under the standard directory and execute the command
cd C:\minecraft\mods\forge
install.cmd
This command will do a whole lot of stuff and take a really long time, something like 10 minutes. Also, it may generate some errors when compiling some of the Minecraft files, but most likely that will be okay. Generally, you can ignore them and continue on. However, sometimes there are valid problems, such as FATAL_ERROR. The best thing to do is give it a try and see what happens, unless you get a FATAL_ERROR.
Linux special consideration: The Forge install.sh would be used on Linux systems. However, when you first extract it, the permissions will not be set correctly. You will need to manually set them to allow for execution with the chmod command. Also, you will need to install the Windows Emulator Wine before you can run the install.sh. If you do not, the install will fail, and it will show you an error message telling you to install Wine.
Make a Backup
Once the install command has completed, the first thing you should do is to make a backup copy of the entire forge directory. The reason is that this will give you a clean copy of a fully configured instance of Forge. If for some reason something goes wrong and something gets corrupted, gee that would never happen right! You would always be able to go back to your backup copy and start over. Otherwise, you would need to re-run the install and have to wait all over again. In addition, you would need to make different copies of Forge if you decide to go to the next level and start creating your own custom mods that you can distribute. You can make a backup by simply copying the entire directory, or you can use an archive tool like 7zip or WinRAR.
Configure the JDK in Eclipse
When Eclipse gets configured it does not always know about the installed JDK, and instead it may find the JRE by default. You will want it to use the JDK and sometimes, you will need go into the Eclipse configuration and set it.
To check if Eclipse is using the JDK or JRE, go into the preference:
- Go to the Menu Bar and select Window -> Preferences
- Navigate to Java -> Installed JREs
You will want to have the JDK in the list and it to be checked to make it the active JRE. In the image above, the JDK is available, but it is not checked, and it would need to be checked.
If you do not even have a JDK, but installed the JDK, then you will need to add the JDK to Eclipse and make it the currently active one by checking it. To do this:
- Click on the Add button
- In the popup window select Standard VM and click the Next button
- In the next window click on the Directory button and navigate to the home directory of your JDK, usually C:\Program Files\Java\jdk1.7.0 (or whatever version you have installed)
Starting Eclipse
AT this point, you will be ready to launch your MCP instance. You will need to launch Eclipse and then point the workspace to the one created for you when Forge was installed. Since we used a standard directory, we know exactly where that will be:
C:\minecraft\mods\forge\mcp\eclipse
This is one of the things that the installer did for you, it created this directory and an Eclipse workspace. What you need to do is use this directory in the Eclipse launch window. Launch Eclipse and select (or type) this directory, as shown below:
Eclipse will come up and it may take a little while for the project to synchronize and finish building. After Eclipse has settled down, you should see a single project in the workspace, named Minecraft. From here you will be able launch Minecraft from inside of Eclipse. It is a good idea to make sure this basic step will work, before doing any hacking. To this just click on the Run button in the menu bar, as shown below:
If you do not see the Run button, its okay. All it means is that for some reason Eclipse did not come up with the Java perspective, and you will need to reset it manually by doing:
- Go to the Menu Bar and select Window -> Open Perspective ->
- Scroll down and select Java
Congratulations!
Okay, so at this point, you will get an instance of Minecraft that is running inside of Eclipse. You should be able to go in and create a new world and navigate around in the world, while doing everything you would normally do in a MC world.
However, these are not exactly a normal worlds. Everything you do here will be in Eclipse. These worlds should only be used to test the changes you make. These are separate from the worlds you create with the normal client, so you don't need to worry about making any changes to them. Another thing to be aware of is that you will be logged in as random user every time you enter one of your testing worlds.
Congratulations! You have setup your Forge development environment!
Good Luck & Happy Hacking!