Making custom recipe with custom item meta ingredients !

Discussion in 'Spigot Plugin Development' started by Arest, Jun 7, 2015.

  1. Hey i am trying to make my own custom recipe with my own ingredients
    My ingredients have enchantment and name ( colored ) but when i add this ingredient it does not allowed me to do it . So i need some help
    public class recipe extends JavaPlugin{
    public void onEnable() {
    trecipe();
    Bukkit.getServer().getLogger().info("Tools Recipes Enabled !");
    }
    private void trecipe() {
    ItemStack p = new ItemStack(Material.DIAMOND_PICKAXE);
    ItemStack s = new ItemStack(Material.SNOW_BALL);
    ItemMeta sm = s.getItemMeta();
    sm.setDisplayName(ChatColor.RED + "" + ChatColor.BOLD + "Legend balls");
    sm.setLore(Arrays.asList(ChatColor.LIGHT_PURPLE + "Crafting tools"));
    sm.addEnchant(Enchantment.DURABILITY, 2, true);
    s.setItemMeta(sm);

    ShapedRecipe trecipe = new ShapedRecipe(p);
    trecipe.shape( "@@@",
    "1s1"
    ,"1s1"
    );
    trecipe.setIngredient('@', Material.SNOW_BALL);
    }

    }
     
  2. I've never worked with recipes before. But you didn't define S & 1.
    Soo.. Do,
    Code (Text):
    trecipe.setIngredient('1', s);
    trcipe.setIngredient('s', p);
    Maybe?
     
  3. Already tried and it seem does not work :/
     
  4. Hmm. Do you know that this is possible? Like have you seen servers do this before? Instead of s, use sm.
    Code (Text):
    trecipe.setIngredient('1', sm);

    I don't know if this is the problem but you haven't created an ItemMeta for the Diamond Pickaxe. I think maybe it should be
    Code (Text):
    trecipe.setIngredient('the item meta', p);
    Edit: I had no idea..
     
  5. @Arest ItemMeta will not be checked in recipes, so you will have to handle that yourself on PrepareItemCraftEvent/CraftItemEvent. You can only use Material & datavalue in Bukkit recipes.

    As for your original recipe, you still have to set S and i to a valid Material, Material & datavalue or MaterialData before you can even craft it. If you want air (empty slot) in your crafting recipe, use whitespace (' ') in your recipe.
     
  6. Can you show me some of the example using Material and MaterialData ?
     
  7. For Material, you already had one in your code
    Code (Java):
    trecipe.setIngredient('@', Material.SNOW_BALL);
    MaterialData is quite the same, just replace the Material with a MaterialData instance:
    Code (Java):
    trecipe.setIngredient('@', new MaterialData(Material.SNOWBALL));
    Optionally, pass a datavalue as second parameter in the MaterialData constructor to give it datavalue - or use the third setIngredient method:
    Code (Java):
    trecipe.setIngredient('@', Material.SNOW_BALL, datavalue here);
     
  8. So if i use the third one then does it get the ItemMeta i have already create ? "Legend Ball"
    Edit : I dont really know how to use this :/
     
  9. @EventHandler
    public void restrictCrafting(PrepareItemCraftEvent event) {


    ItemStack p = new ItemStack(Material.DIAMOND_PICKAXE);
    ItemStack s = new ItemStack(Material.SNOW_BALL);
    ItemMeta sm = s.getItemMeta();
    sm.setDisplayName(ChatColor.RED + "" + ChatColor.BOLD + "Legend Balls");
    sm.setLore(Arrays.asList(ChatColor.LIGHT_PURPLE + "Crafting"));
    sm.addEnchant(Enchantment.DURABILITY, 2, true);
    s.setItemMeta(sm);
    boolean found1 = false;
    if (event.getRecipe().getResult().hasItemMeta() && s.equals(event.getRecipe().getResult().getItemMeta().getDisplayName())) {
    // this is our custom item - make sure all three ingredients are found
    for (ItemStack item: event.getInventory().getMatrix()) {
    if (item != null && item.hasItemMeta()) {
    if (s.equals(item.getItemMeta().getDisplayName())) {
    found1 = true;
    }
    }
    }
    }
    if (!found1) {
    event.getInventory().setResult(null);
    }
    }
    }


    I have this but i dont know what to do next
     
  10. Please put that in a
    Code (Text):
    Text Box.
    And your brackets are odd.
    Edit: LOL, Wrong thread. But still ^.