Shaped Recipes are recipes where the order of the ingredients matter, they need to be in a specific shape for the reciep to craft.
An example of a shaped recipe is the Bucket recipe, where the Iron Ingots need to be placed in the correct order for it to Craft.

While Shaped recipe need to follow the specific pattern, they do not always need to be placed in the exact slot.
Using the Bucket example, both of the recipes below are valid recipes for the Iron Bucket, even though the items are placed in different slots on the grid.

Bucket With Ingots in the top two rows

Bucket with Ingots in the bottom two rows

This effect is achieved by not filling out the full 3x3 grid, an example of how to add a recipe like this is below.

Adding Shaped Recipes

Link to adding-shaped-recipes

This method is used to add a Shaped Crafting recipe to the game.

The basic syntax for a shaped recipe is:

ZenScript
Copy
// craftingTable.addShaped(recipeName as string, 
//      output as IItemStack,
//      ingredients as IIngredient[][], 
//      recipeFunction as @optional RecipeFunctionMatrix);

The optional RecipeFunctionMatrix at the end of the method is only needed for advanced recipe where the output changes depending on the input, an example being transfering NBT data from one of the input ingredients to the output item.

In general, most of your recipes are not going to be using the function, but it is there if you need it.

The recipeName has some restrictions that should be kept in mind:

  1. The name you provide is the "path" value of the name of the recipe, all recipes added through CraftTweaker will have the crafttweaker modid as part of the name.
    For example, if you provide "boat" as the name, the full recipe name will be crafttweaker:boat.
  2. It needs to be unique, using a non-unique recipe name will cause your recipe to replace the previous recipe.
  3. It cannot contain spaces or colons (:).
  4. It must be all lowercased.
  5. It cannot start with "autogenerated/" as it is a reserved CraftTweaker folder.

For the output, something to note is that it has to be an IItemStack, passing in an IIngredient will not work, so using <tag:items:minecraft:wool> or <item:minecraft:diamond> | <item:minecraft:dirt> will not work as they are both IIngredients, but using <item:minecraft:diamond> is valid and will work.

Here is an example of how to add a Shaped recipe that will accept three pieces of Dirt, one in the top left slot, one in the center middle slot and one in the top right slot and output a Diamond.

For a recipe like this, you don't need the recipe function, so it is simply left out.

Something to note with this recipe, because we are only using 2 rows, the recipe can be exactly like the Bucket recipe is made in the examples above.

ZenScript
Copy
craftingTable.addShaped("dirt_bucket_to_diamond", <item:minecraft:diamond>, [
    [<item:minecraft:dirt>, <item:minecraft:air>, <item:minecraft:dirt>], 
    [<item:minecraft:air>, <item:minecraft:dirt>, <item:minecraft:air>]]);

The next Shaped recipe is an example of how you can force the recipe to require items in specific slots, even if the recipe only uses 2 rows of items like the Bucket recipe above.

The recipe will accept a single Apple only in the bottom left slot, and will output an Arrow.

The reason that this will only accept the apple in the bottom left slot is because we put <item:minecraft:air> in the other slots.

ZenScript
Copy
craftingTable.addShaped("apple_to_arrow", <item:minecraft:arrow>, [
    [<item:minecraft:air>, <item:minecraft:air>, <item:minecraft:air>], 
    [<item:minecraft:air>, <item:minecraft:air>, <item:minecraft:air>], 
    [<item:minecraft:apple>, <item:minecraft:air>, <item:minecraft:air>]]);

This next Shaped recipe is an example of how to use the RecipeFunction to change the output based on the input items.

The Shaped recipe will give a piece of Dirt when a Diamond is put into the left slot and an Apple is put into the center middle in the Crafting Grid, however, if the input Apple has the name "Super Apple", it will produce 8 Dirt.

The way that you reference items from the inputs is using the index of where they are in the input array, so because apple is at row 1 column 1, we use [1][1] to reference it, even though the recipe is 2x2 and the apple may not be in the center middle slot of the Crafting Grid.

ZenScript
Copy
craftingTable.addShaped("diamond_and_apples_to_dirt", <item:minecraft:dirt>, [
    [<item:minecraft:diamond>, <item:minecraft:air>], 
    [<item:minecraft:air>, <item:minecraft:apple>]],
(usualOut as IItemStack, inputs as IItemStack[][]) => {

    if <item:minecraft:apple>.withTag({display: {Name: "{\"text\":\"Super Apple\"}"}}).matches(inputs[1][1]) {
        return usualOut * 8;
    }

    return usualOut;

});