Project icon

Custom crafting tutorial

Minecraft Version(s)
1.13-1.14.2
Prerequisites:
  • basic knowledge of how data packs work
This tutorial will be split into 3 parts:
  1. custom crafting recipes
  2. custom crafting benches
  3. floor crafting
Custom crafting recipes
custom crafting recipes are basically .json files which you place inside your data pack to add new recipes to the game. You can either write the code manually or use an online recipe generator (like this one https://crafting.thedestruc7i0n.ca).

once you obtain a recipe .json file, you need to place it in: your_datapack > data > namespace > recipes

the code below is a .json file generated with the online recipe generator which contains information about our custom crafting recipe. I will try my best to explain what every line does.
JSON:
{
    "type": "minecraft:crafting_shaped",
    "pattern": [
        "###",
        "#G#",
        "###"
    ],
    "key": {
        "#": {
            "item": "minecraft:diamond"
        },
        "G": {
            "item": "minecraft:golden_apple"
        }
    },
    "result": {
        "item": "minecraft:enchanted_golden_apple",
        "count": 1
    },
    "group": "newRecipes"
}
let's start with the first line. the "type" tag specifies what type of recipe this is. The 2 types are:
  • craftine_shaped - the items must match the given pattern
  • crafting_shapeless - the items can be placed in any order
the next tag is "pattern" which is used to specify what pattern the items need to be in for the recipe to work. Every symbol represents a different item type. You can replace the "#" and "G" with your own symbols and assign an item type to them in the next step.

the next tag is "key", this section is used to tell the game what item type every symbol represents. In this example, the "#" represents a diamond and the "G" represents a golden apple.

the "result" tag is used to specify the output item of the recipe

the "group" tag is used to sort all your recipes, this can be any name. All recipes that have the same group name will be displayed together in the recipe book (screenshot included)

188


so every recipe with the group name "newRecipes" will be displayed in a group window in the recipe book like shown in the screenshot.

the other type of crafting is "shapeless" crafting which looks like this:
JSON:
{
    "type": "minecraft:crafting_shapeless",
    "ingredients": [
        {
            "item": "minecraft:diamond"
        },
        {
            "item": "minecraft:diamond"
        },
        {
            "item": "minecraft:diamond"
        },
        {
            "item": "minecraft:diamond"
        },
        {
            "item": "minecraft:golden_apple"
        },
        {
            "item": "minecraft:diamond"
        },
        {
            "item": "minecraft:diamond"
        },
        {
            "item": "minecraft:diamond"
        },
        {
            "item": "minecraft:diamond"
        }
    ],
    "result": {
        "item": "minecraft:enchanted_golden_apple",
        "count": 1
    },
    "group": "newRecipes"
}
the only difference is that this recipe uses "ingredients" instead of "pattern". It works the same way as shaped crafting but the items can be placed on the grid in any order.

However, this method comes with a big limitation which is no NBT support. This means you can only craft regular items with no additional data.

Custom crafting benches
Unlike custom crafting recipes, this method allows you to include NBT in your recipes but isn't as nice as the custom crafting recipe method.

For this method, you only need 1 line of code so you can paste it in a command block or in your function file if you're using a data pack.

Also, I'm using an armor stand with a tag "crafter" as a reference point for the crafting bench but you can use coordinates if you want.

here is the code:
Code:
execute as @e[tag=craft] at @s if block ~ ~ ~ minecraft:dropper{Items:[{Slot:4b,id:"minecraft:diamond",Count:1b},{Slot:7b,id:"minecraft:diamond",Count:1b}]} run data merge block ~ ~ ~ {Items:[{Slot:4b,id:"minecraft:stick",Count:1,tag:{display:{Name:"\"name_here\""}}}]}
this command is testing if the block at the armor stands position is a dropper with a specific formation of items and if so, it overwrites the droppers inventory, clearing out all the items all and places an output item in the droppers inventory. In this case, I'm crafting a stick with a custom name if there are 2 diamonds in a stick shape (4b and 7b).

Here's the layout of the slots. for example "Slot:4b" would be the middle square
dropper inventory layout.png

There's just one more thing to do and that is to implement a crafting limitation.
what I mean by that is add some code so you can't craft another stick if a stick from the previous crafting is already inside the dropper.

the piece of code you need to add is: unless block ~ ~ ~ dropper{Items:[{Slot:4b,id:"minecraft:stick",Count:1}]}
this prevents the user from crafting another item if there's already an item inside the crafting grid. In this example, my crafting recipe will output a stick in slot 4b so that's why I'm testing if there is no stick in slot 4b.

so the code with the limitation implemented will look like this:
Code:
execute as @e[tag=craft] at @s if block ~ ~ ~ minecraft:dropper{Items:[{Slot:4b,id:"minecraft:diamond",Count:1b},{Slot:7b,id:"minecraft:diamond",Count:1b}]} unless block ~ ~ ~ dropper{Items:[{Slot:4b,id:"minecraft:stick",Count:1}]} run data merge block ~ ~ ~ {Items:[{Slot:4b,id:"minecraft:stick",Count:1,tag:{display:{Name:"\"name_here\""}}}]}
Floor crafting
floor crafting is pretty common for command block creations and even data packs. Its basically throwing 2 or more items on the ground and combining them into a new item.

the basic syntax is as follows:
execute from item #1 > execute to item #2 > summon output item > remove item #1 and #2

so the commands would look like this:
Code:
execute as @e[type=minecraft:item,nbt={Item:{id:"minecraft:white_wool",Count:1b},OnGround:1b}] at @s run execute as @e[type=item,nbt={Item:{id:"minecraft:lapis_lazuli",Count:1b},OnGround:1b},distance=..1] at @s run summon minecraft:item ~ ~ ~ {Item:{id:"minecraft:blue_wool",Count:1},Tags:["output"]}
Code:
execute as @e[tag=output] at @s run kill @e[type=minecraft:item,nbt={Item:{id:"minecraft:white_wool"}},distance=..1]
Code:
execute as @e[tag=output] at @s run kill @e[type=minecraft:item,nbt={Item:{id:"minecraft:lapis_lazuli"}},distance=..1]
and that is it, the system is done. Now obviously, there are a lot of bugs with this system for example if you throw 2 wool and 1 lapis, you will get 2 blue wool which is not logical but that's a bit more complicated so I won't go over that in this tutorial.
Author
MegaCrafter10
Views
163
First release
Last update
Rating
4.00 star(s) 1 ratings

More projects from MegaCrafter10

Latest reviews

It's a good tutorial, but would be better if you also explained the vanilla system of custom recipes' JSON structure.
MegaCrafter10
MegaCrafter10
Thanks for the feedback, I added your suggestion
Top