⚒️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)

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

public Crafting setShape(String... shape)

Sets the shape of the crafting recipe.

Parameters

  • shape: An array of strings representing the crafting grid.

setIngredient

public 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

public ShapedRecipe build()

Builds and returns the ShapedRecipe instance representing the crafting recipe.

Usage

  1. Create a new instance of the Crafting class with the desired result item and recipe key.

  2. Set the shape of the crafting recipe using the setShape method.

  3. Add ingredients to the recipe using the setIngredient method.

  4. Build the recipe using the build method.

  5. 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