How to Upgrade a Forge Mod

Minecraft version 1.20.1 has been out for a while now, and a stable version of Forge has been released for it. So it’s time to update our mod to run in the latest version of Minecraft. That way we’ll be able to use the Butterflies mod with the fancy new features of Minecraft.

Getting the Right Version

We want to be able to run alongside optifine so we should use the version of Forge that it has been built with – 47.0.35. At the time of writing, the latest version of Forge is 47.1.42, but if we look under “Show all versions” we can find the specific version we need. Now we just download both the MDK and the installer.

Getting the right version

With this, we can run the installer to upgrade the version of Forge in the Minecraft Launcher. That sorts out the game side of things, but we also need to update the mod itself.

Updating the Mod

To do this, we start by extracting the .zip file into the root folder of the Butterflies project. A bunch of new files are added that we don’t need, so we can use git to revert those changes right away. Then we ned go through the changes and make sure any mod-specific changes are back to the way they were.

One thing to notice about this update is that they have moved most of the properties into Gradle’s properties file. This is a really nice change, as going forward there is only one place we need to edit when we upgrade Forge.

We update this file with our mod description, version number, mod ID and so on. Now we are ready to build and run the mod to make sure everything works. Before we do anything, however, we need to reload the Gradle project. In IntelliJ we can do this by opening the gradle tab and clicking the “Reload All Gradle Projects” icon.

Reloading all Gradle projects

This can take a while, so it’s a good opportunity to make a brew.

Once this is done, we are ready to build and run the mod. Of course, a new version of Forge often means changes in the libraries. Our project now has build errors we need to fix. There is a Mod Migration Primer that can help us make the changes we need. Thankfully, our mod is still small, so there aren’t many changes we need to make.

First, there is a new BuildCreativeModeTabContentsEvent that is used to add items to the creative mode inventory (instead of using CreativeModeTabEvent.BuildContents).

    public static void registerCreativeTabContents(BuildCreativeModeTabContentsEvent event) {
        if (event.getTabKey() == CreativeModeTabs.TOOLS_AND_UTILITIES) {
            event.accept(BUTTERFLY_NET);
        }

        if (event.getTabKey() == CreativeModeTabs.SPAWN_EGGS) {
            event.accept(BUTTERFLY_MORPHO_EGG);
            event.accept(BUTTERFLY_FORESTER_EGG);
            event.accept(BUTTERFLY_COMMON_EGG);

Second, an entity’s level attribute is now private, but we have an accessor we can us instead Entity#level().

        Level level = player.level();

These are both nice changes. An actual event for the creative mode inventory and it’s always better to use accessors for properties. Although, I still wish we could define what creative tab an item appears in using a JSON file or something similar.

Now we are ready to build and run the mod as before! We run it through IntelliJ to make sure it still works, then build a release and upgrade our actual survival world to the new version (making sure to backup the world in case anything goes wrong).

Updating the Updated Mod

It turns out that despite using the matching version, Optifine still doesn’t work with our installation. So we may as well update to the latest stable release. It turns out that the gradle.properties file is the best change ever made. To upgrade Forge all we need to do now is modify a single line:

forge_version=47.1.42

That’s it! The mod is upgraded! We still need to reload the Gradle project and make any changes to our source code, but the next time we want to upgrade we don’t even need to download a new version of the MDK!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.