ProRecipes - RecipeAPI

Mar 16, 2016
ProRecipes - RecipeAPI
  • RecipesAPI

    I've created an API for ProRecipes that allows you to interact and create/remove recipes. You don't even need to buy the plugin to use the api! Here's how to get started.

    Getting started

    If you haven't bought ProRecipes you'll need to compile against RecipeAPI. If you have, compile against ProRecipes. Your plugin/addon will only work with ProRecipes on the server, but I've created a separate API to not limit those who have not bought it from developing with it.

    After you have either ProRecipes or RecipeAPI as a resource you use them the same way.

    First access the API object like this.
    Code (Text):
    RecipeAPI api = ProRecipes.getAPI();
    You can then create, delete, and gain info about recipes using all the methods contained in the API class. The javadocs can be very useful if you have any questions or you can message me.

    Here's an example of creating a shaped recipe then retrieving info about it then deleting it only using methods within the API class.

    First I want to create an array of all the ingredients I want of length 9 max. This will be squished into three rows of three so I'll keep that in mind when creating the recipe.This will also be converted later on into a smaller structure to allow for mobility within a crafting table.

    Code (Text):
    ItemStack apple = new ItemStack(Material.APPLE);

    ItemMeta appleMeta = apple.getItemMeta();
    appleMeta.setDisplayName(ChatColor.GREEN + "I am an apple");
    apple.setItemMeta(appleMeta);

    ItemStack arrow = new ItemStack(Material.ARROW);

    ItemMeta arrowMeta = arrow.getItemMeta();
    arrowMeta.setDisplayName(ChatColor.RED + "Sharp pointy stick");
    arrow.setItemMeta(arrowMeta);

    ItemStack[] arr = api.toArray(apple, arrow, apple,
                                  arrow, apple, arrow);
    Note: I've formatted the code structure of the toArray function to mimic the structure in the crafting table

    Next, we want to create a result.

    Code (Text):
    ItemStack result = new ItemStack(Material.GOLD_BLOCK);
    Lastly, we create the recipe. All the methods that create recipes return an integer. This integer is the recipe ID . If the method returns less than 0, the recipe was not able to be created. Documentation on what each value less than 0 mean can be seen in the javadocs.

    Code (Text):
    int recipeId = api.createShapedRecipe(arr, result);
    Now that we have a recipe ID lets retrieve the recipe.

    Code (Text):
    RecipeContainer container = api.getRecipe(RecipeType.SHAPED, recipeId);
    This Container object can give you the following info.

    Code (Text):
    container.getIngredients();
             container.getResult();
             container.getType();
    Lastly, we want to delete the recipe.

    Code (Text):
    api.removeRecipe(RecipeType.SHAPED, recipeId);
    It's as simple as that! Now each recipe type has slightly different arguments, but they're fully explained the in javadocs.

    Here is the whole example
    Code (Text):

             /*
              * Accessing API
              */

             RecipeAPI api = ProRecipes.getAPI();

             /*
              * Creating Recipe
              */

             ItemStack result = new ItemStack(Material.GOLD_BLOCK);

             ItemStack apple = new ItemStack(Material.APPLE);

             ItemMeta appleMeta = apple.getItemMeta();
             appleMeta.setDisplayName(ChatColor.GREEN + "I am an apple");
             apple.setItemMeta(appleMeta);

             ItemStack arrow = new ItemStack(Material.ARROW);

             ItemMeta arrowMeta = arrow.getItemMeta();
             arrowMeta.setDisplayName(ChatColor.RED + "Sharp pointy stick");
             arrow.setItemMeta(arrowMeta);

             ItemStack[] arr = api.toArray(apple, arrow, apple,
                                           arrow, apple, arrow);



             int recipeId = api.createShapedRecipe(arr, result);


             /*
              *
              * Getting recipe info
              *
              */

             RecipeContainer container = api.getRecipe(RecipeType.SHAPED, recipeId);

             container.getIngredients();
             container.getResult();
             container.getType();

             /*
              *
              * Deleting recipe
              *
              */

             api.removeRecipe(RecipeType.SHAPED, recipeId);

    Update 1 (03/16/16)

    The following events have been added: WorkbenchCraftEvent, FurnaceCraftEvent, MulticraftEvent.

    WorkbenchCraftEvent: Called when a shapeless recipe or shaped recipe is crafted
    FurnaceCraftEvent: Called when something is smelted in the furnace in a furnace recipe
    MulticraftEvent: Called when something is crafted in the multicraft table

    View the Javadocs for more info.​
  • Loading...
  • Loading...