Exploring the mod's source code

If you want to understand the inner working of the Mod, make sub mods or derivative versions, you'll need to grab the latest .jar version and decompile it.

## Decompiling the mod

You can do this, for example, with the CFR tool, with which we obtained good results.

Once downloaded, just type the following command line to get quickly started:

```
# java -jar cfr-${VERSION_CFR}.jar LOTRMod\ v${VERSION_LOTR}.jar --outputdir .

```

Please note that this syntax is just intended to have a peak view at the source code. If you need to recompile the mod, you’ll have to provide the libraries used by Minecraft, Forge and the Mod to improve the decompilation. We’ll detail this later.

## Source code tree walkthrough

You'll then find a **lotr** subdir organized like this:

## Better decompilation of the mod

As mentioned earlier, if you need to recompile the mod, you’ll need to provide the libraries used by Minecraft, Forge and the Mod to improve the decompilation.

Assuming that you have setup a working Forge mod development environment, with CFR, you can do that like this:

```
#!/bin/sh

VERSION_CFR=0.146
VERSION_LOTR=35.3

if [ ! -f cfr-${VERSION_CFR}.jar ]
then    fetch https://www.benf.org/other/cfr/cfr-${VERSION\_CFR}.jar
fi

mkdir -p lib
cp ~/.gradle/caches/minecraft/net/minecraftforge/forge/1.7.10-10.13.4.1614-1.7.10/forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.2.4/a60a5e993c98c864010053cb901b7eab25306568/gson-2.2.4.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/18.0/cce0823396aa693798f8882e64213b1772032b09/guava-18.0.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/17.0/9c6ef172e8de35fd8d4d8783e4821e57cdef7445/guava-17.0.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/com.mojang/authlib/1.5.16/ef1582b11fd0943d069cdcb72e99008ac209a283/authlib-1.5.16.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/io.netty/netty-all/4.0.10.Final/9e50bd52ffe257a0e2cd8d971688d6ce7d174325/netty-all-4.0.10.Final.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/net.minecraft/launchwrapper/1.12/111e7bea9c968cdb3d06ef4632bf7ff0824d0f36/launchwrapper-1.12.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.3.2/90a3822c38ec8c996e84c16a3477ef632cbc87a3/commons-lang3-3.3.2.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.0-beta9/1dd66e68cccd907880229f9e2de1314bd13ff785/log4j-api-2.0-beta9.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.0-beta9/678861ba1b2e1fccb594bb0ca03114bb05da9695/log4j-core-2.0-beta9.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.lwjgl.lwjgl/lwjgl/2.9.1/f58c5aabcef0e41718a564be9f8e412fff8db847/lwjgl-2.9.1.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.lwjgl.lwjgl/lwjgl_util/2.9.1/290d7ba8a1bd9566f5ddf16ad06f09af5ec9b20e/lwjgl_util-2.9.1.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-debug-all/5.0.3/f9e364ae2a66ce2a543012a4668856e84e5dab74/asm-debug-all-5.0.3.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/1.4/a8762d07e76cfde2395257a5da47ba7c1dbd3dce/commons-io-1.4.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.4/b1b6ea3b7e4aa4f492509a4952029cd8e48019ad/commons-io-2.4.jar lib

mkdir -p src
rm -rf src/*
java -jar cfr-${VERSION_CFR}.jar LOTRMod\ v${VERSION_LOTR}.jar --extraclasspath lib --outputdir src

```

However, CFR still has one issue with the full decompilation of the mod:

```
Summary for LOTRMod v35.3.jar
Decompiled with CFR 0.146

## lotr.client.render.tileentity.LOTRRenderMug

func_147500_a(net.minecraft.tileentity.TileEntity double double double float )
 Unable to fully structure code

```

So for that purpose, we'll get better results with the FernFlower decompiler, which is notably used in the Mod Coder Pack (MCP):

```
#!/bin/sh

VERSION_LOTR=35.3

mkdir -p lib
cp ~/.gradle/caches/minecraft/net/minecraftforge/forge/1.7.10-10.13.4.1614-1.7.10/forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.2.4/a60a5e993c98c864010053cb901b7eab25306568/gson-2.2.4.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/18.0/cce0823396aa693798f8882e64213b1772032b09/guava-18.0.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/17.0/9c6ef172e8de35fd8d4d8783e4821e57cdef7445/guava-17.0.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/com.mojang/authlib/1.5.16/ef1582b11fd0943d069cdcb72e99008ac209a283/authlib-1.5.16.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/io.netty/netty-all/4.0.10.Final/9e50bd52ffe257a0e2cd8d971688d6ce7d174325/netty-all-4.0.10.Final.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/net.minecraft/launchwrapper/1.12/111e7bea9c968cdb3d06ef4632bf7ff0824d0f36/launchwrapper-1.12.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.3.2/90a3822c38ec8c996e84c16a3477ef632cbc87a3/commons-lang3-3.3.2.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.0-beta9/1dd66e68cccd907880229f9e2de1314bd13ff785/log4j-api-2.0-beta9.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.0-beta9/678861ba1b2e1fccb594bb0ca03114bb05da9695/log4j-core-2.0-beta9.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.lwjgl.lwjgl/lwjgl/2.9.1/f58c5aabcef0e41718a564be9f8e412fff8db847/lwjgl-2.9.1.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.lwjgl.lwjgl/lwjgl_util/2.9.1/290d7ba8a1bd9566f5ddf16ad06f09af5ec9b20e/lwjgl_util-2.9.1.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-debug-all/5.0.3/f9e364ae2a66ce2a543012a4668856e84e5dab74/asm-debug-all-5.0.3.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/1.4/a8762d07e76cfde2395257a5da47ba7c1dbd3dce/commons-io-1.4.jar lib
cp ~/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.4/b1b6ea3b7e4aa4f492509a4952029cd8e48019ad/commons-io-2.4.jar lib

mkdir -p src
rm -rf src/*
java -jar fernflower.jar LOTRMod\ v${VERSION_LOTR}.jar -e=lib/asm-debug-all-5.0.3.jar -e=lib/authlib-1.5.16.jar -e=lib/commons-io-1.4.jar -e=lib/commons-io-2.4.jar -e=lib/commons-lang3-3.3.2.jar -e=lib/forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar -e=lib/gson-2.2.4.jar -e=lib/guava-17.0.jar -e=lib/guava-18.0.jar -e=lib/launchwrapper-1.12.jar -e=lib/log4j-api-2.0-beta9.jar -e=lib/log4j-core-2.0-beta9.jar -e=lib/lwjgl-2.9.1.jar -e=lib/lwjgl_util-2.9.1.jar -e=lib/netty-all-4.0.10.Final.jar src

```

## Deobfuscating the mod

The LOTR mod source code is not obfuscated, but Minecraft source code is!

So, if you want to avoid seeing things like func\_XXXXX() in the code, you'll have to translate them into something meaningful.

As a example, in lotr/common/LOTRLevelData.java you'll see the following call:

```
CompressedStreamTools.func_74799_a((NBTTagCompound)new NBTTagCompound(), (OutputStream)new FileOutputStream(LOTR_dat));

```

that should get translated to:

```
CompressedStreamTools.writeCompressed((NBTTagCompound)new NBTTagCompound(), (OutputStream)new FileOutputStream(LOTR_dat));

```

You can probably use the Mod Coder Pack (MCP), Minecraft Deobfuscator or Bearded-Octo-Nemesis (BON) tools to do that.