User Tools

Site Tools


tutorial:mappings

This is an old revision of the document!


Mappings

Introduction

Mappings define the names of classes, fields and methods. In an ordinary loom environment, Yarn mappings are used, which provide meaningful names for the Minecraft codebase as decided by the community. Intermediary is also an essential type of mapping used by Fabric. The need for mappings comes from the obfuscation of Minecraft releases, which presents multiple challenges. Remapping is the process of applying mappings to compiled classes or source files.

Using mappings

In Loom, the mappings define the names for Minecraft classes, fields and methods used in your development environment. These names may vary from one development environment to another depending on the installed mappings.

Yarn is the default mapping used by Loom. Yarn gradually improves and receives new releases as contributions are accepted. Mappings in Loom are specified using the mappings dependency configuration in the buildscript and can be updated by updating the dependency. Minecraft as well as dependencies included with the modCompile dependency configuration are remapped with the mapping. Classes, fields and methods that are not mapped in Yarn are given Intermediary names like class_1234, method_1234 and field_1234.

dependencies {
    [...]
    mappings "net.fabricmc:yarn:${project.yarn_mappings}"
}

By changing the mappings in your development environment, you can expect that names of classes, methods and fields in Minecraft and any included mods have changed, and that your code might have to be updated to reference the changed names. This process can be partially automated. You will also have to run genSources to access Minecraft sources with the updated mappings.

Loom's remapJar task will produce the primary mod artifact, which is a built jar using intermediary names. Additionally, if a sourcesJar task is present, remapSourcesJar will produce a sources jar using intermediary names. These jars can be installed as mods or included in a development environment with the modCompile dependency configuration.

  • The output of jar, the '-dev' jar, does not use intermediary names, and is therefore not useful. It cannot be installed as a mod outside a development environment and will only work in a development environment with matching mappings. The remapJar task output should be used instead and installed in development environments using the modCompile dependency configuration.
  • Yarn names are only applied in a development environment. Outside a development environment, only intermediary names exist, meaning the code will not match exactly what you see and wrote. Loom silently handles this transition for you, but be cautious when using reflection.

Obfuscation and deobfuscation

Releases of Minecraft Java Edition are obfuscated jar files, which means they are compiled binaries stripped of any meaningful naming information, leaving only the bare logic behind. The motivation behind obfuscation is to prevent reverse engineering and to reduce file sizes. Java programs like Minecraft are rather simple to decompile, but the obfuscation is stripping away a lot of information that would be useful for modding purposes. One might wonder how it is possible to develop for Minecraft in the first place.

Mappings like Yarn provide meaningful names for development. Using mappings it is possible to make sense of the Minecraft code and create mods for it. Mapping can provide names for classes, fields, methods, parameters, and local variables. It should be obvious these mappings are not perfect. Mapping the entirety of Minecraft involves a lot guesswork from multiple contributors. Mappings may be incomplete and sometimes change as more accurate names are found.

Intermediary

A property of Minecraft's obfuscation is that it is not always consistent between Minecraft versions. A class may be called abc in one version of Minecraft, and abd in another. The same inconsistency applies to fields and methods. This creates binary incompatibility between Minecraft versions.

Intermediary provides stable names for Minecraft's internals across Minecraft versions. The purpose of an Intermediary name is that it will always refer to the same class, field or method. Unlike Yarn names, Intermediary names are not meaningful and instead follow a numeric pattern like class_1234, method_1234 and field_1234.

Being a stable mapping, Intermediary can make Minecraft's API allow binary compatibility across multiple versions of Minecraft (such as snapshot versions)! While compatibility is not guaranteed, it can work in many cases depending on the changeset. When installed outside a development environment, Fabric Loader provides an environment with intermediary names by remapping Minecraft (and Minecraft Realms) before the game is started. This can be observed by looking at a crash report from a production environment with Fabric Loader installed, which will contain intermediary names. Mods, using intermediary names as applied by Loom, are naturally compatible with this environment.

tutorial/mappings.1559078455.txt.gz · Last modified: 2019/05/28 21:20 by jamieswhiteshirt