Tutorial: See Minecraft's code
Since snapshot 19w36a, Mojang releases obfuscation maps for every version of Minecraft 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.
After 26.1 Snapshot 1, the game will be deobfuscated, but still needs to be decompiled in order to see the readable source code.[1]
Legal disclaimer
[edit | edit source]According to its license, decompiling Minecraft is allowed, but it is recommended that one does not release decompiled code. Furthermore, a tweet from Dinnerbone suggests usage of the mappings inside of projects by the community, such as modding (using them to decompile Minecraft for usage with Forge, NeoForge, Fabric, Quilt and other modloaders) or for usage in server software with plugins (such as Spigot, Bukkit, Paper, and others) is okay, and an intended use. It should be noted however that this tweet is not legally withstanding, so while it is probably fine to use these mappings for such purposes, you do so at your own risk. This can be extended to decompiling and accessing Minecraft's code as a whole; the only things you should not do under any circumstances are releasing the code or releasing something that contains an exact copy of the code.
Decompiling JAR
[edit | edit source]There are numerous ways of decompiling the Minecraft game source, see below.
Using third-party software
[edit | edit source]There is no official way of decompiling Minecraft's source code. You'd have to use a third-party software designed to process the obfuscation map provided by Mojang and decompile the game into a directory consisting of multiple human readable Java files. One of the third-party software you can use is MaxPixelStudios' MinecraftDecompiler.
The MinecraftDecompiler software is distributed in a JAR file, so you'd need Java to run it (see Tutorial:Update Java § How to download). You can receive the latest JAR file from their GitHub release page.
Upon downloading, you'd need to open a terminal to run the JAR file. On Windows, you can use Command Prompt, and on macOS or Linux, it may be the terminal provided by your system. Make sure to open it in the same directory as the JAR file.
On the command line, the JAR file can be run using Java by typing the following command:
java -jar MinecraftDecompiler.jar --version 1.21.11 --side SERVER --decompile --output 1.21.11-remapped.jar --decompiled-output 1.21.11-decompiled
This will write a mapped version of the server.jar to 1.21.11-remapped.jar, as well as decompiling the game and writing the generated source files to 1.21.11-decompiled. The following arguments for the MinecraftDecompiler software are used:
--version <version>- This specifies which version of the game you want to decompile. MinecraftDecompiler will automatically fetch the game's executable files from the specified version.
--side <environment>- This specifies which environment you want to decompile. There are two environment you can specify:
CLIENTandSERVER. The client environment contains the entire game you're playing, while the server only contains the resources necessary to host a multiplayer game. The client includes the entire server code, plus client specific, like rendering, user interface, etc.
--decompile [<decompiler>]- This specifies that you want to decompile the game, usually after deobfuscating the JAR file. Optionally, you can also specify which decompiler you want to use. By default, it uses
vineflower, but you can use other decompilers:fernflower,forgeflower,cfr, oruser-defined.
--output <mapped-jar-output>- This specifies the output file for the deobfuscated JAR file (or mapped JAR file) from the obfuscation map.
--decompiled-output <decompilation-directory>- This specifies the output directory for the decompilation files.
Additionally, you can run java -jar MinecraftDecompiler.jar --help to see all available options.
Using built-in IDE functions
[edit | edit source]If you prefer to download as little additional software as possible, you can also view Minecraft's source using built-in IDE functions from IntelliJ IDEA, Eclipse, or Visual Studio Code.
Since you are not using additional software, you will have to generate the source yourself. Start by downloading the Fabric example mod from GitHub, and opening it in your IDE of choice.
Next, you will have to ensure that the version you want to find the source for is selected. If you want to use the latest stable version, i.e. 1.21.11, you may skip this step, as the example mod will almost always be up-to-date. Otherwise, navigate here, select your chosen version in the first dropdown menu, and update your gradle.properties file accordingly.
Once you have completed this step, open a command line window. If this window is in the IDE, run gradlew gensources, or ./gradlew gensources if you are on Linux or Mac. However, if this window is separate from your IDE, remember to run cd path/to/mod_folder/ first.
Now, return to your IDE window and follow the steps below, depending on the IDE you use:
- Visual Studio Code: Ctrl/⌘ Command + P, and begin typing possible class names with the
#prefix - IntelliJ IDEA: Ctrl + N or ⌘ Command + O, and begin typing possible class names
- Eclipse: Ctrl/⌘ Command + ⇧ Shift + T, and begin typing possible class names