Tuesday, August 26, 2014

Using the Javadoc that comes with the Forge dev kit

Many of you probably don't need this help, but if you are like me you'll want to make sure you have the Javadoc available within Eclipse for all of your development, and since you downloaded the ZIP file (you did, right?) you might need to know how to link it in.

In Eclipse, with your project open, go to the Project menu, then choose Properties.  Select Javadoc location, and browse to the folder where you have unzipped the documentation.  There might be a better way to do it, but that worked for me.

A reading assignment

There are a great many tutorials out there for getting up and running on modding, but there is only one that I've found so far that actually does a good job of explaining the basics of how Minecraft and Forge work, and work together.  You can find that here, and many thanks to greyminecraftcoder for putting it together.  His aim is a bit different than mine, but definitely complimentary.  I'm planning on reading most/all of his work before doing much coding.  Join me over on his blog for a while, and get indoctrinated in the mysteries of Minecraft.

Monday, August 25, 2014

Building and installing your mod

Name and Version

Now that you have your project in Eclipse, you'll need to do a few things.  First of all, make sure you know where Eclipse is looking for the files, particularly if you copied the Forge source directory during the import process.  If you don't know what I'm talking about, read my previous post.

You will notice that you have at the top of your package explorer the source for a very basic mod, ExampleMod.  Within the ExampleMod.java file you will see that there is a place for entering a MODID and a VERSION.  Update those values to something unique to you.  No sense in cluttering up the world with mods named ExampleMod.  You should also rename the Java class to reflect the name you chose, and put it in a package that is unique to you.  

Once you've done that, you are almost ready to test and then build.  You'll also need to change the mcmod.info file in your src/main/resources directory.  Make sure the modid in this file matches the one you put into your Java source.  

Do a test run

Now it should be ready to do a quick test run.  The big thing here is making sure you use the Client run configuration.  It should either be called Client or Run Client, or some other similar name you chose during setup.  To make sure you do it right the first time, go to the Run menu, choose Run Configurations, select the Run Client (or whatever) configuration under Java Application, and press the Run button.  Here's a screenshot if you are a more visual person:


This should wind up starting Minecraft, with Forge, and if you check out the mods that are loaded, yours will be there.

As long as all this works, you are ready to actually build the JAR with your mod.  This isn't tricky either, thanks to the magical tools provided by the Forge team.

Build your mod

Get to a command prompt and change to the root directory of your project.  Type gradlew build and hit Enter.  If all is well, you should see some lines of text popping out, at the end of which will be "BUILD SUCCESSFUL".

Check in the directory build\libs and you will find there your mod, in a file named modid.jar, with the name of course being the value you chose for MODID earlier.

Install and test

Now that you have your JAR file, you can copy it into your Minecraft mods directory, fire up Minecraft, and try playing!  It doesn't actually do anything useful or fun just yet, but you have at this point validated that your tools are up and running, and all you have left to do is the trivial task of coding a useful mod.  Stay tuned as we explore the wild and woolly world of mod coding! 

Setup

Intro

I'm creating this blog as a way of tracking my own progress from Minecraft player (or more importantly, parent of Minecraft players...) to Minecraft modder.  I'm going to do my best to link to the resources I used, and they are myriad.  The idea of this blog, though, is to be sort of a soup to nuts guide.  It won't be the most detailed necessarily, but I plan to provide links to more details.  Please feel free to point out any glaring omissions or errors.  I am, after all, completely new to this, and am putting this together as a way to help others navigate these rather complex waters.

Download stuff

Obviously there are a bunch of things required for development.  Here are a few links:
  1. Minecraft.  This should be obvious.  As of the start of this blog I'm running 1.7.10.  I'll try to update with changes, but unless you see a reference to some other version, this is what I'm using.  You'll want to download the minecraft_server.1.7.10.jar for later also.
  2. Minecraft Forge. If you don't already have it installed, you need it.  I'm using version 10.13.0.  Make sure you also download the Source and the Javadoc packages, in addition to the installer for your platform.
  3. Java SDK.  Since Minecraft is Java-based, this should be evident.  I'm going to be using the most recent version of the Java 7 SDK, due to reports that Java 8 is not supported at the moment.
  4. Eclipse.  This is my preferred Java development environment, which happens to be free.  If you want to use something else, you're on your own, sorry.  I'm using Eclipse Standard 4.4.

Create a workspace

I have created a folder to put everything in one place, including Eclipse.  I have a separate install of Eclipse for doing Android development, so I don't get things too mixed up.  You certainly can just use a single install for everything, but don't blame me if you run into problems.

I put all the installers I'm using in the root of this folder, just in case I need to reinstall or reference a version.  Eclipse can just be unzipped, there is no fancy install process.  You'll also need to unzip the Forge source package, and you'll probably want to rename the directory to something shorter.

If you haven't already done it, you'll need to make sure that the path to your JDK is present in your PATH variable.  The Java developer website has instructions on doing this.  You'll also need to make sure your JAVA_HOME environment variable is set to the SDK install directory (NOT the \bin directory within it!) in order for the Forge tools to work properly.

Once you've done this, you can setup the workspace using the Forge magical tools.  There is a good intro to this process on the Forge website.  Here's a summary:
  1. Open a command prompt in your Forge source directory.  In Windows hold down shift, right click the directory, and choose "Open command window here" from the menu.
  2. Enter gradlew setupDecompWorkspace, hit Enter, and wait for the magic to finish.
  3. Enter gradlew eclipse and once more wait for the magic to finish.
With any luck this succeeded and you can fire up Eclipse.  Choose whatever workspace you want, and then Import the project.  If this doesn't work, you'll perhaps need to take a look at the detailed instructions on this page.  My sound didn't work, it wouldn't recognize the eclipse directory as a project, but after reading that page and playing a bit, I was able to successfully launch Minecraft with the example mod loaded.

Congrats!  You've done the preliminary work!  Next up: building the mod and running it in Minecraft outside of Eclipse...