User Tools

Site Tools


tutorial:reading_mc_code

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:reading_mc_code [2021/09/18 16:46] – Don't put Ctrl+T in the numbered list jummittutorial:reading_mc_code [2023/11/17 19:14] (current) – [Eclipse] cph101
Line 6: Line 6:
 To read the Minecraft source, you need to generate sources first. See the "Generating Minecraft Sources" section in [[tutorial:setup|Setting up a mod development environment]]. To read the Minecraft source, you need to generate sources first. See the "Generating Minecraft Sources" section in [[tutorial:setup|Setting up a mod development environment]].
  
-===== Searching for a Minecraft class ====+===== Searching for a Minecraft class =====
 To search a Minecraft class, follow these steps. To search a Minecraft class, follow these steps.
  
-==== Intellij IDEA ==== +===== Intellij IDEA ===== 
-    - Open the search pane with ''Ctrl + N''+    - Open the search pane with {{https://i.ibb.co/rmztpCy/IMG-0712.png?height=64}} or {{https://i.ibb.co/2SDypGK/kbs-meta-o.png?height=80}} on mac
     - Set the search scope to ''Project and Libraries'' or wider     - Set the search scope to ''Project and Libraries'' or wider
     - Type the class name in the search box     - Type the class name in the search box
  
-==== Visual Studio Code ====+===== Visual Studio Code =====
     - Open the search pane with ''Ctrl + P''     - Open the search pane with ''Ctrl + P''
     - Type the class name with prefix ''#''     - Type the class name with prefix ''#''
-**Or:** 
-    - You can also use ''Ctrl + T'' to open the class search directly. 
  
-===== Tips ====== +===== Eclipse ===== 
-    * When you find a method or class but don't understand what they are doingcheck the usages or subclasses of them. You might need to check the usages of the usages and such+    - Open the search pane with ''Ctrl + Shift + T'' 
-    * You may find an invalid java code such as ''int i = true;''This is because the decompiler we use is not perfectCheck the corresponding part of bytecodes if needed+ 
-    * 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.+In Visual Studio Code, you can also use ''Ctrl + T'' to open the class search directly. 
 + 
 +===== Finding the class you want to see ==== 
 +Locating the part of code you want to see is a challenging task. Here are some tips. 
 + 
 +    * Take full advantage of IDE's ability to find the relevant code such as ''Call hierarchy'', ''Method hierarchy'' or ''Type hierarchy''
 +    * Take a look at open source mods which are similar to what you want to make. 
 +    * If you are adding a new contentthere is a good chance you need to access registries defined in ''net.minecraft.util.registry.Registries''
 +    * Keep in mind that everything starts from one main class (''net.minecraft.client.main.Main'' for client, ''net.minecraft.server.Main'' for dedicated server). 
 +    * Search Minecraft code for translation keys. ''assets/assets/minecraft/lang/en_us.json'' contains all keys used in vanilla. 
 + 
 +===== 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 produces an invalid java code such as ''int i = true;''. 
 + 
 +If you are not familiar with the java bytecode, reference [[https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-6.html|the JVM specification]]. 
 + 
 +To see 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 doesn't support bytecode viewing, use external bytecode viewers such as https://github.com/Konloch/bytecode-viewer. 
 + 
 +===== FAQ ===== 
 +**Where is the generated sources?** 
 + 
 +It's either in the user gradle cache (''~/.gradle/caches/fabric-loom''or in the project gradle cache (''./.gradle/loom-cache''). 
 +You can use the sources jar outside of your IDE. 
tutorial/reading_mc_code.1631983616.txt.gz · Last modified: 2021/09/18 16:46 by jummit