⚒️Crafting Recipes
Create custom crafting recipes with ease
Overview
The Crafting class provides a utility for creating custom crafting recipes in Bukkit.
Constructors
Crafting(JavaPlugin plugin, ItemStack result, String key)
Crafting(JavaPlugin plugin, ItemStack result, String key)public Crafting(JavaPlugin plugin, ItemStack result, String key)Creates a new instance of the Crafting class with the specified result item and recipe key.
Parameters
- plugin: The JavaPlugin instance representing the plugin that owns this recipe.
- result: The ItemStack representing the result of the crafting recipe.
- key: The key used to identify this recipe.
Methods
setShape
setShapepublic Crafting setShape(String... shape)Sets the shape of the crafting recipe.
Parameters
- shape: An array of strings representing the crafting grid.
setIngredient
setIngredientpublic Crafting setIngredient(char key, Material material, int amount)Sets an ingredient for the crafting recipe using a Material.
Parameters
- key: The character representing the ingredient's position in the crafting grid.
- material: The Material of the ingredient.
- amount: The amount of the ingredient required.
public Crafting setIngredient(char key, ItemStack itemStack, int amount)Sets an ingredient for the crafting recipe using an ItemStack.
Parameters
- key: The character representing the ingredient's position in the crafting grid.
- itemStack: The ItemStack representing the ingredient.
- amount: The amount of the ingredient required.
build
buildpublic ShapedRecipe build()Builds and returns the ShapedRecipe instance representing the crafting recipe.
Usage
- Create a new instance of the - Craftingclass with the desired result item and recipe key.
- Set the shape of the crafting recipe using the - setShapemethod.
- Add ingredients to the recipe using the - setIngredientmethod.
- Build the recipe using the - buildmethod.
- Register the recipe with Bukkit using - Bukkit.addRecipe.
Example
JavaPlugin plugin = // your JavaPlugin instance
ItemStack result = new ItemStack(Material.DIAMOND_SWORD);
String key = "custom_recipe";
Crafting crafting = new Crafting(plugin, result, key)
        .setShape("ABA", "CDC", "AEA")
        .setIngredient('A', Material.IRON_INGOT, 1)
        .setIngredient('B', Material.DIAMOND, 1)
        .setIngredient('C', Material.STICK, 1)
        .setIngredient('D', Material.GOLD_INGOT, 1)
        .setIngredient('E', new ItemStack(Material.APPLE), 1);
ShapedRecipe recipe = crafting.build();
Bukkit.addRecipe(recipe);In this example, we create a custom crafting recipe for a diamond sword (result) using various materials and items.
Last updated