How To Give A Crafted Item An NBT Tag

Started by chezr on

Topic category: User side tutorials

Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How To Give A Crafted Item An NBT Tag
Mon, 08/05/2024 - 04:55 (edited)

Hello!

Today I will be showing you how to make a recipe give the crafted item (the result) a Custom Tag!
This is very helpful for if you are trying to make a recipe similar to Suspicious Stew, where depending on the type of flower, it gives a different NBT Tag.



To begin, make a Recipe. In that recipe, add your items and in the result, add the item that you want to give the tag to. For this example, I will be using a shapeless crafting recipe that requires a Steak and Glowstone to make a Steak that gives the Regeneration effect. (The crafted item is a Steak because it will have an NBT tag)

Once you have your recipe all figured out, you can now lock the code of the recipe.

Enter the code editor of the recipe, and scroll down until you see:

"result": {
    "item": "minecraft:cooked_beef",
    "count": 1,
   }
}

Make a new line under count, and write: "nbt":

It should now look something like:

"result": {
    "item": "minecraft:cooked_beef",
    "count": 1,
    "nbt":
   }
}

After "nbt", type the following: "{\"CustomTag\":\"regen\"}" (I am using CustomTag and regen as my tag names, it doesn't matter what the names are.)

After that, the code should look like:

"result": {
    "item": "minecraft:cooked_beef",
    "count": 1,
    "nbt": "{\"CustomTag\":\"regen\"}"
   }
}

(The backslashes \ are used because they cancel out the quotation marks. Without them, it breaks the code.)

And that's it! The "result" now gets a custom tag upon being crafted.

The finished code should look like this:
 

{
  "type": "minecraft:crafting_shapeless",
  "category": "misc",
  "ingredients": [
    {
      "item": "minecraft:cooked_beef"
    },
    {
      "item": "minecraft:glowstone_dust"
    }
  ],
  "result": {
    "item": "minecraft:cooked_beef",
    "count": 1,
    "nbt": "{\"CustomTag\":\"regen\"}"
  }
}



Congratulations! Now whenever you put Steak and Glowstone in a crafting table, you get a Steak with a custom NBT tag!

If you want to make the steak give you Regeneration whenever you eat it, you have to make a global procedure for when the "Player finishes using item".
Then check the Itemstack for that custom tag, and if it has it, apply the Regeneration effect to the player.

Edited by chezr on Mon, 08/05/2024 - 04:55
Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can't seem to get this to…
Sun, 11/10/2024 - 18:20

Can't seem to get this to work. I am however trying to detect an NBT tag of the input item rather than the output