Recipe help

Discussion in 'Spigot Plugin Development' started by MadMaxCookie, May 29, 2016.

  1. Hello so I'm adding a shaped recipe by doing this one

    Code (Java):
    ShapedRecipe recipe = new ShapedRecipe(ca.getConfig().getItemStack(cs + ".Product"));
                       
                        // the recipes shape
                        recipe.shape("123", "456", "789");
                       
                        for(Integer i = 1; i <= 9; i++) {
                            try {
                                recipe.setIngredient(i.toString().toCharArray()[0], ca.getConfig().getItemStack(cs + ".Slot" + i).getData());
                            }catch(NullPointerException e) {}
                        }
                        Bukkit.getServer().addRecipe(recipe);
    I want to save the ingredient with their displayname how do I do that ?
     
  2. Do you mean that you only want people to be able to craft the recipe if they have ItemStacks with certain names?
     
  3. yes and this is my method is it possible , if so how ?
     
  4. Use PrepareItemCraftEvent, if it's your recipe, check the names of the ItemStacks and if they don't match cancel the event
     
  5. ok I'll try but since there is no e.setCancelled should I set the result to Material.AIR ?
     
  6. Yes, that's what i meant, haven't done work with that event in awhile, sry :p
     
  7. not a problem but how do I check the ingredient what code should I use ?
     
  8. @Redrield in PrepareItemCraftEvent

    I did

    Code (Java):
    if(e.getInventory().getRecipe() // how to check a recipe please give an example);
     
  9. I believe you would use CraftingInventory#getMatrix() (PrepareItemCraftEvent#getInventory()
     
  10. show me atleast one example could you please ?
     
  11. event.getInventory().getMatrix();?
     
  12. how do I convert this recipes of product (Slot 1 to 9)itemstacks to array ?

    I have this kind of config

    Code (Java):
    recipeName:

        Slot 1:
            ItemStack
        Slot 2:
            ItemStack
        Slot ...9;
            ItemStack
         Product:
            ItemStack
         Type:
            Shaped , Shapeless, Furnace
    thanks
     
  13. Well just compare them with a foreach loop, the 0th index would be the first slot, 1st index second, etc. (I think)
     
  14. Code (Java):
    ConfigAccessor ca = ConfigAccessor.getInstance();
            Set<String> cs = ca.getConfig().getKeys(false);
            for(Integer i = 1; i <= 9; i++) {
                ItemStack[] slots = {ca.getConfig().getItemStack(cs + ".Slot" + i)};
            }
    what about this ?
     
  15. if there's more method please suggest guys.