Skip to content

Recipes

Recipes are a way to define a way to craft a particular item. They are defined by a plugin or datapack, however we are only going to cover the plugin side of things here.

ShapedRecipe

A shaped recipe is a recipe that requires a specific pattern of items in the crafting grid to craft an item. These are created using a pattern string and a map of characters to items. The pattern strings are 3, 3-character strings that represent the rows of the crafting grid. They can be created as follows:

TestPlugin.java
public class TestPlugin extends JavaPlugin {
@Override
public void onEnable() {
NamespacedKey key = new NamespacedKey(this, "WarriorSword");
ItemStack item = ItemStack.of(Material.DIAMOND_SWORD);
ShapedRecipe recipe = new ShapedRecipe(key, item);
recipe.shape(" A ", "AAA", " B ");
recipe.setIngredient('A', Material.DIAMOND);
recipe.setIngredient('B', Material.STICK);
getServer().addRecipe(recipe);
}
}

This recipe would require a diamond sword to be crafted with a diamond in the top row, a stick in the middle row, and a diamond in the bottom row. The diamond sword would be in the middle column of the bottom row. The result would look like this in the crafting grid:

A
AAA
B

ShapelessRecipe

A shapeless recipe is a recipe that requires a specific number of items in the crafting grid to craft an item. These are created using a list of items. They can be created as follows:

TestPlugin.java
public class TestPlugin extends JavaPlugin {
@Override
public void onEnable() {
NamespacedKey key = new NamespacedKey(this, "WarriorSword");
ItemStack item = ItemStack.of(Material.DIAMOND_SWORD);
ShapelessRecipe recipe = new ShapelessRecipe(key, item);
recipe.addIngredient(3, Material.DIAMOND);
recipe.addIngredient(2, Material.STICK);
getServer().addRecipe(recipe);
}
}

This recipe declares that you simply need 3 diamonds and 2 sticks to craft the item, without any specific orientation of the cross pattern in the crafting grid. This could be crafted in any of the following ways:

DSS | SDS | S D
D | D | D
D | D | D S

And, any other composition of the 5 items.