Porting to 1.21.4: Stage 4

In my porting adventure, I was almost there. I could load the game and create a new world. That didn’t mean that I was ready to release, however. Next came the laborious task of testing (almost) every feature in the mod to ensure that they still work.

I had a list of features to focus on, but that didn’t mean I didn’t find bugs in other features. As I found features that didn’t work, I went through them and figured out how to fix them.

Advancements


One of the first issues I came across was that there were no more advancements. Checking the error logs, I found that the JSON for them was missing an id attribute. This was because icon doesn’t use an item attribute anymore, it uses id. A simple find and replace fixed this one.

A more complicated problem was with the Fill Book challenges. These relied on the CustomModelData which has been reworked to have several arrays of values, rather than just a single value. This breaks both the code and the way these advancements are detected.

To fix this, I rewrote the code to use the CUSTOM_DATA tag instead, which is a list of key/value pairs.

        if (numButterflies >= ButterflyData.getNumButterflySpecies()) {
            CompoundTag filledButterfly = new CompoundTag();
            filledButterfly.putBoolean("filled_butterfly", true);
            newBook.set(DataComponents.CUSTOM_DATA, CustomData.of(filledButterfly));
        }

        if (numMoths >= ButterflyData.getNumMothSpecies()) {
            CompoundTag filledMoth = new CompoundTag();
            filledMoth.putBoolean("filled_moth", true);
            newBook.set(DataComponents.CUSTOM_DATA, CustomData.of(filledMoth));
        }

Now I can test for these flags by updating the criteria on my advancements:

  "criteria": {
    "filled_book_butterfly": {
      "trigger": "minecraft:inventory_changed",
      "conditions": {
        "items": [
          {
            "items": "butterflies:butterfly_book",
            "components": {
              "minecraft:custom_data": {
                "filled_butterfly": true
              }
            }
          }
        ]
      }
    }
  }

I loaded into the game and filled a book with all butterflies and moths, and it worked perfectly. With that done, all advancements worked in this version.

This isn’t the end of it, however. These changes started being introduced in 1.21.1, so I made a note in my buglist to check that this still works in earlier versions.

Translation Strings


Translation strings for block items now use item.<mod>.<id> instead of block.<mod>.<id>. This meant that all block items were missing the correct translation strings. This was, of course, an easy fix:

  "block.butterflies.butterfly_feeder": "Butterfly Feeder",
  "block.butterflies.butterfly_microscope": "Butterfly Microscope",
  "item.butterflies.butterfly_feeder": "Butterfly Feeder",
  "item.butterflies.butterfly_microscope": "Butterfly Microscope",

Butterfly Scrolls


Butterfly Scolls had been affected by the changes to NBTs, the rendering changes, and the networking changes. Instead, they had what seemed to be a default square bounding box floating oddly in the air, regardless of the scroll’s placement.

After digging into the issue, I found that the direction wasn’t being synchronized properly, and the bounding box wasn’t being calculated at all. By stripping out a lot of custom code, and relying on the base HangingEntity implementation, I was able to get the results I wanted with a lot less code:

Empty Bottles


Bottled Butterflies and Bottled Caterpillars were always empty in this new version. Thankfully this one was easy to fix. InteractionResults work differently since 1.21.2, so all I needed to do was to check for InteractionResult.SUCCESS instead of InteractionResult.CONSUME and everything worked again.

Item Duping


Networking changes introduced a new bug where you could duplicate Butterfly Books with the Butterfly Microscope. This took a while to fix, but it boiled down to removing some synchronisation code, because Minecraft does it all for you now.

Recipe Data Format


Recipes stopped working in this new port. Checking the Data Pack Changes shows us that the format for items in recipes has changed. So instead of a list of objects:

    {
      "item": "butterflies:bottled_butterfly_forester"
    },
    {
      "item": "minecraft:paper"
    },
    {
      "item": "minecraft:iron_nugget"
    }

We can use a much simpler list of IDs:

    "butterflies:bottled_butterfly_forester",
    "minecraft:paper",
    "minecraft:iron_nugget"

Of course, I wrote a Python script to help me convert these, but this is one reason I want to investigate Forge/NeoForge’s Data Generation – this change could have been done for me and I’d have less work to do.

Release


After these fixes, I generated a new release that you can download and play with right now. And, of course, there are still some things I’ve missed. Some I spotted later playing in my forever world, others have been reported by players. So there’s still work to do, as always.

Every update comes with its share of surprises, bugs, and late-night debugging sessions. But that’s the joy of modding. Bok’s Banging Butterflies is now fluttering happily in 1.21.4, and I’ve learned a lot in the process.

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.