javaminecraftminecraft-fabric

Custom Recipe Parsing Error when developing mod with fabric in Minecraft 1.21.4


I was following this tutorial and I was trying to create a custom recipe.

However it seems that recipe jsons cannot be parsed and read properly.

[23:41:37] [Render thread/INFO] (Minecraft) Created: 1024x512x0 minecraft:textures/atlas/gui.png-atlas
[23:41:44] [Worker-Main-6/ERROR] (Minecraft) Couldn't parse data file 'tutorial-mod:pink_garnet' from 'tutorial-mod:recipe/pink_garnet.json': DataResult.Error['List is too short: 0, expected range [1-9]']
[23:41:44] [Worker-Main-6/ERROR] (Minecraft) Couldn't parse data file 'tutorial-mod:pink_garnet_block' from 'tutorial-mod:recipe/pink_garnet_block.json': DataResult.Error['Map entry '#' : Failed to parse either. First: Input does not contain a key [fabric:type]: MapLike[{"item":"tutorial-mod:pink_garnet"}]; Second: Failed to parse either. First: Not a string: {"item":"tutorial-mod:pink_garnet"}; Second: Failed to parse either. First: Not a json array: {"item":"tutorial-mod:pink_garnet"}; Second: Not a string: {"item":"tutorial-mod:pink_garnet"}']
[23:41:44] [Render thread/INFO] (Minecraft) Loaded 1370 recipes
[23:41:44] [Render thread/INFO] (Minecraft) Loaded 1481 advancements

Here is the resource/data/tutorial-mod/recipe/pink_garnet_block.json:

{
  "type": "minecraft:crafting_shaped",
  "category": "misc",
  "key": {
    "#": {
      "item": "tutorial-mod:pink_garnet"
    }
  },
  "pattern": [
    "###",
    "###",
    "###"
  ],
  "result": {
    "count": 1,
    "id": "tutorial-mod:pink_garnet_block"
  }
}

Here is the resource/data/tutorial-mod/recipe/pink_garnet.json:

{
  "type": "minecraft:crafting_shapeless",
  "category": "building",
  "ingredients": [
    {
      "item": "tutorial-mod:pink_garnet_block"
    }
  ],
  "result": {
    "count": 9,
    "id": "minecraft:diamond"
  }
}

Here is the src/main/java/me/saudoge/TutorialMod.java:

package me.saudoge;

import me.saudoge.block.ModBlocks;
import me.saudoge.item.ModItemGroups;
import me.saudoge.item.ModItems;
import net.fabricmc.api.ModInitializer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TutorialMod implements ModInitializer {
    public static final String MOD_ID = "tutorial-mod";

    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

    @Override
    public void onInitialize() {

       LOGGER.info("Hello Fabric world!");
       ModItems.registerModItems();
       ModBlocks.registerModBlocks();
       ModItemGroups.registerItemGroups();
    }
}

Here is the folder structure:

folder structure image

Here is the github repo link if anyone wants to replicate the error:

https://github.com/SauDoge/tutorial-mod-template-1.21.4

I don't know what went wrong but I suspect that the folder structure is somehow wrong.

I saw a few questions asking about solving the problem by using "id" instead of "item", but I am already using "id".


Solution

  • To answer your question, the reason it is unable to parse the JSON file is because your syntax related to the ingredients has changed in 1.21.4. For your example the new syntax should look like this.

    For the Pink Garnet Block:

    {
      "type": "minecraft:crafting_shaped",
      "category": "misc",
      "key": {
        "#": "tutorial-mod:pink_garnet"
      },
      "pattern": [
        "###",
        "###",
        "###"
      ],
      "result": {
        "count": 1,
        "id": "tutorial-mod:pink_garnet_block"
      }
    }
    

    For the Pink Garnet Block to Diamond

    {
      "type": "minecraft:crafting_shapeless",
      "category": "building",
      "ingredients": [
        {
          "tutorial-mod:pink_garnet_block"
        }
      ],
      "result": {
        "count": 9,
        "id": "minecraft:diamond"
      }
    }
    

    The ingredients no longer use the "'item':" tag for some reason.

    Just as an added tidbit, you can check how all vanilla recipes are formatted in the "net.minecraft:minecraft-merged-abba00472f:1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.8-v2" external library! Hope this helped :D