Skip to content
rutgerkok edited this page Jan 4, 2013 · 24 revisions

This page is made for plugin developers. It explains how to compile Terrain Control.

##The Terrain Control interface ###Biome lookups If you use Bukkit's biome lookup API it won't recognize the custom biomes. If you want to support Terrain Control, add it to your build path (just like you did with Bukkit) and use TerrainControl.getBiomeName().

Obviously, this won't work if Terrain Control isn't installed. So to support servers without Terrain Control, we need to make our own method:

public String getBiomeName(Location location)
{
    if(Bukkit.getServer().getPluginManager().getPlugin("TerrainControl") != null)
    {
        return TerrainControl.getBiomeName(location.getWorld().getName(), location.getBlockX(), location.getBlockZ());
    } else
    {
        return location.getWorld().getBiome(location.getBlockX(), location.getBlockZ()).toString());
    }
}

#Compiling Terrain Control

Code structure

Terrain Control has been divided in three parts: Forge, Common and Bukkit. Common contains almost all generation code. It hasn't any dependencies, besides the standard class libary of Java 6. The Bukkit part uses the code from the Common part to generate a world. The Forge part does the same, but for Forge. This setup prevents having a lot of duplicated code.

Setting up your workspace

To compile Terrain Control, I (rutgerkok) am using a setup with two Eclipse workspaces. For the first workspace, you can easily use another IDE if you want. It's not a very nice setup, so if anyone else has a suggestion, I'd be happy to hear it.

First of all, make sure that Eclipse is downloaded and installed. Create a new workspace or use an existing one, if you already have one. Download the Terrain Control source from here (if you know how to use Git, you can also use that). Extract it and create a new project in Eclipse, with the location pointing to the Terrain Control source:

Set the location of the project to TerrainControl

Adding Craftbukkit

After you have created the project, a lot of errors will show up. You need to add CraftBukkit and Forge to the project. You can download the latest development of CraftBukkit here. Right-click the project, select Build Path and click Configure Build Path. Click Add External JARs... and select the file you just downloaded.

Build path

Adding Forge

There are still errors in the Forge version. As you might know, the Minecraft source is obfuscated: every class, field and method has been renamed to a meaningless term, like a or nb. The MCP team has given many of those a meaningful name, to help modders. Using MCP you can get a nice, deobfuscated source code. MCP has also made a script to convert the deobfuscated names back to the original, so that it works with Minecraft again.

The Bukkit team is directly distributing an already deobfucated JAR file, made with their own tools. They don't reobfuscate it, so that plugins working with Bukkit also don't need to. For Forge, will we have to create a JAR file similar to the Craftbukkit one by ourselves, and we will also have to reobfuscate our mod.

Make sure that the JDK is installed and that you can use Java from the command line (tutorial). Download the latest Forge build (use the source) and extract everything into a new folder, the Forge folder. Run install.cmd (Windows) or install.sh (Mac and Linux). This can take a while. You'll need an internet connection for this, as it will automatically setup MCP for you. After everything is installed, open Eclipse and set the workspace to the Forge/mcp/eclispe folder.

You now have two different workspaces. The first one contains Terrain Control, the second one Forge. In the second workspace you should now see one project: Minecraft (with a lot of files inside it). Choose File, Export, JAR file and export everything. This is the jar file we need to add to the Terrain Control project in the first workspace. It contains the deobfuscated Minecraft source along with the Forge files.

Compiling

For Craftbukkit it's easy: just (in the first workspace) select Export, Java, JAR file and include the bukkit and common files.

For Forge it's more complicated. We need to get the compiled classes reobfuscated, so that it works with the original Minecraft classes. Copy the forge and common classes (the com folders) to the Forge/mcp/src/minecraft folder. You can now run (in this order) Forge/mcp/recompile.bat and Forge/mcp/reobfuscate.bat (Windows) or Forge/mcp/recompile.sh and Forge/mcp/reobfuscate.sh (Mac or Linux). It will output all Terrain Control files to Forge/mcp/reofb/minecraft. You can add them to the JAR file of the Craftbukkit version to create a universal build, or you can put them in a ZIP file.

Here's a small Windows .bat file to automate the copying and recompiling process. Place it in the Forge folder. You'll need to adjust the paths on line 4 and 5 a little bit for your computer, of course.

@echo off
cd mcp
rmdir "src\minecraft\com" /S /Q
xcopy "C:\Users\Rutger\Documents\GitHub\TerrainControl\common\src" "src\minecraft" /E /I /Q
xcopy "C:\Users\Rutger\Documents\GitHub\TerrainControl\forge\src" "src\minecraft" /E /I /Q
runtime\bin\python\python_mcp runtime\recompile.py %*
runtime\bin\python\python_mcp runtime\reobfuscate.py %*

Code formatting

For Eclipse, you can download the settings here: the formatting settings and the settings for the imports.

Clone this wiki locally