Since snapshot 19w36a, Mojang releases obfuscation maps for every version available in the launcher. Those maps can be used to deobfuscate a version's JAR file, that is to say, replace obfuscated class names and class member names with their original (deobfuscated) names. Using a decompiler, it is possible to reconstruct human-readable Java code.
Disclaimer[]
Instructions: Add more information about what is allowed and what is not.
According to the license, decompiling Minecraft is allowed, but it is recommended not to release decompiled code.
Downloading obfuscation map[]
Every version's JSON file contains a link to the obfuscation maps for that version since 19w36a. The JSON file for a version can be found in the version_manifest.json.
Once you have found the JSON file corresponding to the version you want to decompile, find the client_mappings or server_mappings field (depending on which side you want to decompile) under the downloads field and download the file from the URL inside the url field.
Deobfuscating JAR[]
To deobfuscate a JAR file, you need a program that takes the JAR file and its corresponding obfuscation map as inputs, and returns a deobfuscated JAR file. A free and open source program you can use is SpecialSource. You can download the latest version on Maven. You don't actually need to download every dependency to get SpecialSource to run. Here is the list of the dependencies required for version 1.10.0 to work:
- SpecialSource 1.10.0 (.jar) available under BSD 3-Clause License
- Guava 20.0 (.jar), available under Apache License, Version 2.0
- JOpt Simple 4.9 (.jar), available under MIT License
- ASM Commons 9.1 (.jar), available under BSD 3-Clause License
- ASM 9.1 (.jar), available under BSD 3-Clause License
- ASM Tree 9.1 (.jar), available under BSD 3-Clause License
- ASM Analysis 9.1 (.jar), available under BSD 3-Clause License
To use SpecialSource to decompile a JAR file, download all the dependencies above in the same directory and run the following command inside this directory:
java -cp SpecialSource-1.10.0.jar;*;. net.md_5.specialsource.SpecialSource --in-jar <path to JAR file> --out-jar <path to deobfuscated JAR file> --srg-in <path to mappings> --kill-lvt
Where:
<path to JAR file>
is replaced by the path to a version's obfuscated JAR file<path to deobfuscated JAR file>
is replaced by the path of the JAR file to output<path to mappings>
is replaced by the path to the version's obfuscation map
If running under Linux or macOS, replace the semicolons with colons before running it. If running in PowerShell, place SpecialSource-1.10.0.jar;*;.
inside double quotes.
Note[]
Obfuscation maps provided by Mojang do not include local variable names. The --kill-lvt
("kill local variable table") option tells SpecialSource not to try to remap local variable names.
Decompiling JAR[]
Now that you have a deobfuscated JAR file, you can use a decompiler to reconstruct source code from this file. The produced source code should be valid Java code, but is not the original code of the game. A decompiler is unable to reconstruct the original code, it can only try to produce valid code that matches what the compiled file does.
There are many Java decompilers available. CFR is a free and open source option available under the MIT License. You can download CFR 0.148 on Maven (.jar). 0.148 is the version that seems to give the best results when decompiling recent versions of Minecraft. To run CFR on a JAR file, use the following command:
java -jar cfr-0.148.jar <path to JAR file> --outputdir <path to directory>
Where:
<path to JAR file>
is replaced by the path to a version's deobfuscated JAR file<path to directory>
is replaced by the path to the directory you want the source code to be in
Useful tools[]
The community has made some tools to simplify the process of deobfuscating and decompiling Minecraft. For example, you can use DecompilerMC to decompile any version automatically.