|
| 1 | +# Customizing the Mappings in Your Development Environment |
| 2 | + |
| 3 | +## What are mappings? |
| 4 | + |
| 5 | +Before a new Minecraft version jar is published to Mojang's servers, it goes through a process called *obfuscation*, |
| 6 | +where the human-readable class, field and method names are simplified to just a few letters, mainly to optimize the file |
| 7 | +size. In addition, obfuscation makes code very difficult to understand, because those simplified names aren't just |
| 8 | +contractions of the real names, they're completely random letters. This is where mappings come into play. |
| 9 | + |
| 10 | +A mapping is just a change from one name to another, in most cases an obfuscated name to a human readable one. Each |
| 11 | +mapping may also have extra metadata, like documentation. A set of mappings is called a "mapping set" or more often |
| 12 | +just "mappings". You can think of a mapping set as a translation dictionary, where each single mapping would be a |
| 13 | +translation of a word to another language. Here, the obfuscated names would be the language the computer uses, and |
| 14 | +the dictionary would help us translate that to plain english. |
| 15 | + |
| 16 | +While a simple obuscated-to-human-readable mapping set would be enough for one minecraft version, the obfuscated names |
| 17 | +aren't constant between different minecraft versions: `DirtBlock` could be obfuscated as `abc` in 1.19 but in 1.20 it |
| 18 | +could be `def`. From this arises the need to keep the obfuscation changes between versions minimal, a problem that can |
| 19 | +be solved with intermediate mappings, that convert those obfuscated names to names that won't change between versions, |
| 20 | +but still aren't readable in english. Quilt uses Hashed Mojmap, in which every class, field, and method is prefixed by |
| 21 | +`C_`, `f_`, and `m_` respectively, followed by an 8-letter hash. |
| 22 | +While developing mods, most of the time you'll see Fabric's intermediary instead, which uses `class_`, `field_`, and |
| 23 | +`method_`, followed by a number. Mojang also publishes official mappings, often called Mojmap (short for |
| 24 | +Moj(ang)-map(pings)), for every version after 1.14. Since they don't have an intermediate mapping set, you have to do |
| 25 | +some extra processing to use them where you'd use other mappings. Luckily, Loom does this process for you, so you don't |
| 26 | +have to worry about that and can easily replace the mappings used in your mod for Mojang's official ones. |
| 27 | + |
| 28 | +There are a few different formats to store mappings, and, as of the time this article was written, we are developing a |
| 29 | +new one with a bunch of improvements. In our ecosystem, the most used format is [Tiny V2], which uses a single `.tiny` |
| 30 | +file to store mappings, and places fields & methods as "children" of their parent class. |
| 31 | +Another format we often use is the Enigma format, which uses a directory tree with a file for each top-level class, and |
| 32 | +organizes the entries in a tree-like structure, placing each field, method, and class as a child of another class or a |
| 33 | +top level one. |
| 34 | + |
| 35 | +## Editing your mappings |
| 36 | + |
| 37 | +Mapping sets don't have to contain a mapping for every class, field or method in a jar to be valid; in fact, most mapping |
| 38 | +sets aren't complete. For instance, Quilt Mappings (QM for short) has reached 99% completion at most. In a development |
| 39 | +environment, unmapped things will use their intermediary name instead of the obfuscated one, so if you have ever browsed |
| 40 | +Minecraft's code with QM or Fabric's Yarn applied, it's very likely you have seen quite a few intermediary names. |
| 41 | +It gets worse when it comes to method parameters: since they are really prone to incompatible changes between versions, |
| 42 | +they (usually) don't have intermediate names, thus the names you see in the code depend on the tooling that you used to |
| 43 | +decompile the game. |
| 44 | + |
| 45 | +If you want to add a name or change a wrong or bad one, or add documentation to the code, you can start by picking which |
| 46 | +mapping set you'll work on top of. In this article, we'll use QM, though the process for Yarn is almost identical. |
| 47 | +If you want to work on top of Mojang's mappings, you'll have to do some extra work which we won't cover here. If you |
| 48 | +are going to work on QM, we highly suggest taking a look at its [contributing documentation][QM CONTRIBUTING.md] and |
| 49 | +contributing your changes to the repository. You'll need some very basic Git knowledge, but it should be fairly easy |
| 50 | +to do if you've ever worked with Git before. |
| 51 | + |
| 52 | +To get started, first get your own copy of [Quilt Mappings]' code by cloning or downloading the repo. If you want to |
| 53 | +contribute your changes at some point, directly downloading the code won't work; you'll have to [fork the repo][fork qm] |
| 54 | +and clone said fork instead. |
| 55 | +Once you have the code, run `./gradlew mappings` in your command prompt or terminal to launch [Enigma], our favorite |
| 56 | +tool to edit and write mappings. Rai wrote a really [great guide on how to edit mappings in Enigma][Enigma guide], |
| 57 | +so you can take a look and start mapping! Once you have finished editing, don't forget to save your changes before |
| 58 | +closing Enigma. |
| 59 | + |
| 60 | +### Contributing the changes back to Quilt |
| 61 | + |
| 62 | +To contribute your changes, you have to add and commit your changes, then push the changes to your fork of QM. This is |
| 63 | +really easy to do with an IDE, as described in [the Setting Up article][setting-up], but if you want you can also do it |
| 64 | +from the command prompt or terminal with these commands. |
| 65 | + |
| 66 | +```bash |
| 67 | +git add . # tell git to track all your changes in the current directory |
| 68 | + |
| 69 | +git commit -m "Blabla" # add those changes into a new commit (replace "blabla" with a short description of your changes) |
| 70 | + |
| 71 | +git push # upload your commits to your fork of QM. You might need to add `origin <minecraft version>` at the end if git complains about a missing upstream branch |
| 72 | +``` |
| 73 | + |
| 74 | +Once you pushed your changes to your fork, go to [QM's Pull Requests tab][QM PRs] and click the "Compare & Pull |
| 75 | +Request" button in the note about your recent changes. Fill in the title and description of your PR, submit it, and wait |
| 76 | +for your changes to be reviewed and accepted. Again, there's a more in-depth explanation of the PR process in |
| 77 | +[the contributing documentation][QM CONTRIBUTING.md]. |
| 78 | + |
| 79 | +### Using the edited mappings |
| 80 | + |
| 81 | +If you don't want to contribute your changes back to Quilt, or want to try them out in a development environment, you |
| 82 | +can run `./gradlew publishToMavenLocal` to make the required files available to other projects in your computer. You can |
| 83 | +now head to the project where you want to apply these mappings, and edit the `build.gradle` file to add `mavenLocal()` |
| 84 | +to the `repositories` block, if it isn't already there. |
| 85 | + |
| 86 | +```gradle |
| 87 | +repositories { |
| 88 | + // ... |
| 89 | + mavenLocal() |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +Once you have `mavenLocal()` in your repositories, you can edit the `libs.versions.toml` file, in the `gradle/` |
| 94 | +directory, to change the version of the mappings you are using to the one you just edited. In the case of QM, you can |
| 95 | +change the `+build.*` suffix to `+local`; other projects may use a different versioning format, so you have to check |
| 96 | +their documentation or code to verify the version you want. |
| 97 | + |
| 98 | +```diff |
| 99 | + minecraft = "1.20.4" |
| 100 | +-quilt_mappings = "1.20.4+build.1" |
| 101 | ++quilt_mappings = "1.20.4+local" |
| 102 | + quilt_loader = "0.23.1" |
| 103 | +``` |
| 104 | + |
| 105 | +That's it! You can now reload gradle through your IDE to apply these changes, and use your new mappings when reading |
| 106 | +Minecraft's code. |
| 107 | + |
| 108 | + |
| 109 | +<!-- Links --> |
| 110 | +[Quilt Mappings]: https://github.com/QuiltMC/quilt-mappings |
| 111 | +[QM CONTRIBUTING.md]: https://github.com/QuiltMC/quilt-mappings/blob/HEAD/CONTRIBUTING.md |
| 112 | +[Fork QM]: https://github.com/QuiltMC/quilt-mappings/fork |
| 113 | +[QM PRs]: https://github.com/QuiltMC/quilt-mappings/pulls |
| 114 | +[Enigma]: https://github.com/QuiltMC/enigma |
| 115 | +[Enigma guide]: https://github.com/QuiltMC/quilt-mappings/blob/HEAD/GUIDE.md |
| 116 | + |
| 117 | +[setting-up]: /en/introduction/setting-up |
| 118 | + |
| 119 | +[Tiny V2]: https://fabricmc.net/wiki/documentation:tiny2 |
0 commit comments