tutorial:reading_mc_code
This is an old revision of the document!
Table of Contents
Reading the Minecraft source
Reading the Minecraft source is an important skill in modding. This is mainly because
- Most of the Minecraft things are not documented
- Documentations/tutorials get outdated fairly quickly
To read the Minecraft source, you need to generate sources first. See the “Generating Minecraft Sources” section in Setting up a mod development environment.
Searching for a Minecraft class
To search a Minecraft class, follow these steps.
Intellij IDEA
- Open the search pane with
Ctrl + N
- Set the search scope to
Project and Libraries
or wider - Type the class name in the search box
Visual Studio Code
- Open the search pane with
Ctrl + P
- Type the class name with prefix
#
In Visual Studio Code, you can also use Ctrl + T
to open the class search directly.
Tips
- If you don't know what class to read, take a look at open source mods which are similar to what you want to make.
- When you find a method or class but don't understand what they are doing, check the usages or subclasses of them. You might need to check the usages of the usages and such.
- Generated sources is located at the user gradle cache (i.e.
~/.gradle/caches/fabric-loom
). If you want to use external tools to mess around with Minecraft source, you can use the sources jar.
Reading the bytecode
Reading the bytecode is occasionally required because
- Mixin operates on bytecode, not the source code. Understanding the bytecode is essential when you write a complex mixin.
- Decompiler (FernFlower) is not perfect. It sometimes produce an invalid java code such as
int i = true;
.
To open the bytecode, follow these steps.
Intellij IDEA
- Open the class of which you want to see the bytecode
- Select
View
from the main menu - Select
Show Bytecode
External Tools
If your IDE or editor doesn't support bytecode viewing, you can still use external bytecode viewers such as https://github.com/Konloch/bytecode-viewer.
tutorial/reading_mc_code.1633101581.txt.gz · Last modified: 2021/10/01 15:19 by siglong