Tutorial: See Minecraft's code
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
According to the license, decompiling Minecraft is allowed, but it is recommended not to 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, 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 cannot do under any circumstances are releasing the code or releasing something that contains an exact copy of the code.
Decompiling JAR
There are numerous ways of decompiling the Minecraft game source, see below.
Using third-party software
The easiest way to view the source is probably by using MinecraftDecompiler by MaxPixelStudios.
Upon downloading, the jar file can be run using Java on a command line window:
java -jar MinecraftDecompiler.jar \
--version 1.21.8 \
--side SERVER \
--decompile \
--output 1.21.8-remapped.jar \
--decompiled-output 1.21.8-decompiled
This will write a remapped version of the server jar file to 1.21.8-remapped.jar,
as well as decompiling the game and writing the generated source files to 1.21.8-decompiled.
-jar MinecraftDecompiler.jar assumes that the jar file exists in the current directory with that name. On most operating systems, it is necessary to enter cd path/to/downloads_folder/ before running the command mentioned above.Additional options:
- You can replace
SERVERwithCLIENT, to decompile the client code instead of the server, although they must be in capitals. - You can also replace
MinecraftDecompiler.jarwith the path to the application if it is in a different directory. - If you're having issues with the default decompiler VineFlower, you can provide a different one to
--decompile [decompiler]. - Run
java -jar MinecraftDecompiler.jar --helpto see all available options.
Using built-in IDE functions
If you prefer to download as little additional software as possible, you can also view the Minecraft source using built in IDE functions in programs such as IntelliJ IDEA, Eclipse, or VS 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.8, 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/⌘ Cmd + P, and begin typing possible class names with the
#prefix - IntelliJ IDEA: Ctrl + N or ⌘ Cmd + O, and begin typing possible class names
- Eclipse: Ctrl/⌘ Cmd + ⇧ Shift + T, and begin typing possible class names