Porting to 1.21.4: Stage 3

I’ve been porting Bok’s Banging Butterflies to Minecraft 1.21.4. The code compiled – great! The game loaded to the title screen – even better! But I still wasn’t done. Because now, the real test began: could I create a new Minecraft world?

When you get to this stage of porting a mod, the problem usually isn’t with the code. It is often due to changes in the data. When world creation starts, Minecraft will check that all of the data is valid. If it isn’t, the game exits with an error indicating which data is wrong.

So, of course, since there are some changes to the data format, I encountered some of these errors when trying to create a world.

Client Items


The first error I hit was strange – Minecraft couldn’t find any of my item models. It wasn’t a formatting issue. It wasn’t missing files or using an incorrect folder name. But the game was still complaining that they didn’t exist at all.

The models were definitely there, so I was stumped. Then I stumbled across the NeoForge 1.21.4 Primer, and there it was. Minecraft had introduced Client Items.

Client Items act kind of like block states except they apply to item models rather than block models. These can be used to add properties, colour tints, and other features. They also specify models for each item. And they’re now required.

So I needed to add one of these for all 450+ items in Bok’s Banging Butterflies. Obviously there was no way I was going to do this manually. Thankfully, the JSON I needed to specify a model for each item was simple. As an example, the Bottled Forester Caterpillar looks like this:

{
  "model": {
    "model": "butterflies:item/bottled_caterpillar_forester",
    "type": "minecraft:model"
  }
}

This made it extremely easy to write a quick Python script to generate this data for me. I added another method to my data generation script and within a few seconds of running it I had all the files I needed:

# Use to generate missing client items.
def generate_item_models():

    # Generate a list of all item model files
    files = generate_file_list("resources/assets/butterflies/models/items/")

    # For each item, create a new client item file with the same name and generate the JSON to apply the model.
    for file in files:
        with open("resources/assets/butterflies/items/" + file + ".json", 'w+', encoding="utf8") as output_file:
            output_file.write("""{
  "model": {
    "model": "butterflies:item/""" + file + """",
    "type": "minecraft:model"
  }
}
""")

I thought this script might be useful to others so I shared it in the NeoForge Discord. Someone asked me why I didn’t use the datagen. That’s how I learned that there is already a system for Data Generation in NeoForge. Somehow, despite all the hours I’ve poured into this mod, data generation completely slipped past me. It happens.

I haven’t had chance to look at it properly yet, but it looks like it might be a little involved. I really wanted to finish this port before I did anything else, so I decided to continue using my Python code for now and look at datagen later.

This was the only major change to the data I needed to fix, but there was one minor change I still needed to make.

Oh the Biomes We Won’t Go Anymore


The next problem I had in creating a world was an issue with the biome modifiers. The game was telling me that the #c:is_dense biome filter didn’t exist anymore. This one was actually a little harder to figure out, as there wasn’t any obvious documentation on this change.

No documentation. No changelog. Just one tiny tag standing in the way of world creation. Fortunately, once I tracked it down, it was a simple fix. It had been renamed to #c:is_dense_vegetation. One small change, and suddenly the world loaded:

{
  "biomes": "#c:is_dense_vegetation",
  "spawners": [
    // Cut for brevity
  ],
  "type": "neoforge:add_spawns"
}

So, I was finally done, right?

No


Well, almost. Now I had to go through and test every feature in the mod. Up until this point I had kept a list of features I wanted to focus on based on the major changes in the code and the data. Now it was time to start working through that list.

One last stage to go. After that, Bok’s Banging Butterflies would finally be ready to take flight in 1.21.4!

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.