User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

These pages will help you setup a productive development environment and semi-automated releases.

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

tutorial:reading_mc_code

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

  1. Open the search pane with Ctrl + N
  2. Set the search scope to Project and Libraries or wider
  3. Type the class name in the search box

Visual Studio Code

  1. Open the search pane with Ctrl + P
  2. Type the class name with prefix #

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 content, there is a good chance you need to access registries defined in net.minecraft.util.registry.Registry.
  • 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 the JVM specification.

To see the bytecode, follow these steps.

Intellij IDEA

  1. Open the class of which you want to see the bytecode
  2. Select View from the main menu
  3. 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.txt · Last modified: 2022/09/29 05:22 by solidblock