Skip to content

Instantly share code, notes, and snippets.

@PhoenixVX
Last active June 9, 2021 06:04
Show Gist options
  • Save PhoenixVX/e44fd1370e8207b50ed5c127dd6d82fc to your computer and use it in GitHub Desktop.
Save PhoenixVX/e44fd1370e8207b50ed5c127dd6d82fc to your computer and use it in GitHub Desktop.
A simple easy-to-understand guide on how to port Fabric in it's entirety.

Generating Intermediary

This should not be used unless you are making Fabric run on a version which there are no (similar) intermediaries available for.

Generating intermediary requires Stitch (pre-built releases) or available at the source repository Stitch (source) After either building or downloading a pre-built release, one must have a minecraft JAR to use and the Stitch JAR.

  • Open a Command Prompt (Windows) / Terminal (MacOS/Linux variants)
  • Go to the directory which contains both the Minecraft JAR and Stitch using cd
  • Invoke the Java Runtime Environment to run Stitch. Stitch has the available commands:
Available commands:
        asmTrace <class-file>
        generateIntermediary <input-jar> <mapping-name> [-t|--target-namespace <namespace>] [-p|--obfuscation-pattern <regex pattern>]...
        genPrefixedTiny <input JAR> <prefix> <output tinymap> [inname] [outname]
        matcherToTiny <in> <out> <src-name> <dst-name>
        mergeJar <client-jar> <server-jar> <output> [--removeSnowman] [--syntheticparams]
        mergeTiny <input-a> <input-b> <output> [mappingBlankFillOrder...]
        mergeTinyV2 <input-a> <input-b> <output>
        proposeFieldNames <input jar> <input mappings> <output mappings>
        proposeV2FieldNames <input jar> <input mappings> <output mappings> <should replace>
        reorderTiny <old-mapping-file> <new-mapping-file> [name order...]
        reorderTinyV2 <old-mapping-file> <new-mapping-file> [new name order...]
        rewriteIntermediary <jar> <old-mapping-file> <new-mapping-file> [--writeAll]
        updateIntermediary <old-jar> <new-jar> <old-mapping-file> <new-mapping-file> <match-file> [-t|--target-namespace <namespace>] [-p|--obfuscation-pattern <regex pattern>]
  • In this case, we want to use generateIntermediary with our Minecraft JAR as the input-jar and mapping-name as the intermediary mappings name (Good prefix is mcversion-intermediary-v1.tiny).

Example: java -jar stitch.jar generateIntermediary minecraft.jar 1.16.4-intermediary-v1.tiny

Note: Some Minecraft versions may require an optional regex parameter to not generate intermediary for libraries.

  • Finally, your Tiny V1 intermediary is available in the same directory as your Stitch JAR.

Matching intermediary

This is what is usually used for newer versions

Matching intermediaries require a program called Matcher which unfortunately must be built from source as there is no ready-made built binaries.

  • Gather your A and B JARs (Ex: 1.16.4 and 1.16.5)
    Note: These steps will require both Stitch (which can be downloaded above) and Matcher
  • Open the Matcher (JAR) application and hit the File->New Project
    New Project
  • Configure the project to have A and B JARs (Usually A is older than B)
    Project Configuration
  • Matcher has an auto-match functionality available in the Matching tab->Auto match all
    Note: This isn't perfect but the amount of false-positives are in the single digits and the weights can be finetuned for older / newer versions if need be.
  • Click on the View tab->Sort by match status to show yellow (class is matched, but not all members are) and red (no/poor match) at the top of the list.
  • Work your way down the list, matching / marking classes/methods/fields as unmatchable if need be.
  • When you finish, you must export your match to a .match file using the File tab->Save matches
    Saving Matches

Generating intermediaries from a Match file

Stitch now has the necessary inputs to generate Tiny V1 intermediary for this version of Minecraft.
Reviewing Stitch' commands, the updateIntermediary task requires an old jar, a new jar, old intermediary mapping file (must be V1), the intermediary file to output as, and finally the Match file we generated earlier.

  • Execute the Java Runtime Environment on the Stitch JAR with the updateIntermediary filling in the neccesary information.
    (Example: java -jar stitch.jar updateIntermediary 1.16.4.jar 1.16.5.jar 1.16.4-intermediary-v1.tiny 1.16.5-intermediary-v1.tiny 1.16.4-1.16.5.match [optional regex if needed])

Intermediary repository

This stays the same for generating intermediary or for updating intermediary

Most Fabric-based toolchains use two repositories for mappings (intermediaries and yarn). Intermediaries are mappings which stay the same between versions as long as both versions have their respective copies of them. Yarn is the remapping of intermediaries to a name. The whole process is usually Obfuscated->Intermediary->Yarn The original Fabric intermediary repo is available at Intermediary

  • Upload the intermediary Stitch created into the mappings folder and the matches you created with Matcher go into the matches folder.
  • Gradle generates a build task for each version inside the mappings folder. This task allows you to build V1, and V2 intermediaries in a single task. Use gradlew.bat build (Windows) or ./gradlew build (MacOS/Linux) to build for all mappings located inside the mappings folder.
    One can also use the gradlew tasks / ./gradlew tasks to find out the exact name of the task for building a specific mappings.
  • Run the Gradle task to generate intermediaries and then publish them to a Maven (if possible).

Yarn repository

After uploading the intermediaries to the Fabric maven (using a local copy of intermediaries is possible but it requires shredding the build.gradle), one must change the minecraft version that Yarn (Enigma) downloads for mapping. Enigma is a mapping tool also developed by FabricMC to map JARs from intermediary (actually works with obfuscated, but let's not talk about that).

  • Change the Minecraft version so that it may download the specified version Line to change
  • Downloading intermediaries should already be handled properly if you use the FabricMC maven. If not, edit the downloadIntermediary and downloadIntermediaryV2 tasks to be proper to your cases.
  • Run the yarn task using gradlew yarn (Windows) or ./gradlew yarn (MacOS/Linux)
  • Enigma should pop up, displaying classes in a List form. If you click on a class, it will decompile and show the class and all of its methods and fields. For every unmapped name, one should right click->Rename {type} and name it properly. Naming conventions
  • Do not forget to save the mappings. After saving, push your changes to the Yarn repo (on the right branch).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment