How do I get the durability of a item in a custom recipe?

Discussion in 'Plugin Development' started by CaLxCyMru, Jun 24, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    CaLxCyMru

    Hello there, I want to make it so that when a person crafts a Custom Recipe - A wood sword, They get it back with the added dura of the 2 items used to craft it, I have the base for the plugin, But I cant figure out how to get the dura in the ingredient, Then add them.

    Thanks in advance
    -CaL

    Here is the code

    Code:java
    1. ShapelessRecipe re = new ShapelessRecipe(new ItemStack(Material.WOOD_SWORD)).addIngredient(Material.WOOD_SWORD).addIngredient(Material.WOOD_SWORD);
    2. @EventHandler(priority = EventPriority.MONITOR)
    3. public void onCraft(PrepareItemCraftEvent event){
    4. Recipe r = event.getRecipe();
    5. if(r instanceof ShapelessRecipe){
    6. ShapelessRecipe sr = (ShapelessRecipe) r;
    7. if(sr.getIngredientList().equals(re.getIngredientList())){
    8. ItemStack sword = sr.getResult();
    9. ItemMeta sm = sword.getItemMeta();
    10. sm.setDisplayName(ChatColor.RED + "" + ChatColor.BOLD + "Repaired Wooden Sword");
    11. List<String> lore1 = new ArrayList<String>();
    12. lore1.add(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "" + ChatColor.ITALIC + "TYPE: " + ChatColor.RESET + "" + ChatColor.RED + "" + ChatColor.BOLD + "" + ChatColor.UNDERLINE + "Weapon");
    13. sm.setLore(lore1);
    14. sword.setItemMeta(sm);
    15. event.getInventory().setResult(sword);
    16. Bukkit.getServer().addRecipe(re);
    17. }
    18. }
    19. }
     
  2. Offline

    caseif

    That's not possible just using recipes; you'd need to check the durability by getting the ItemStack from the crafting matrix in the PrepareItemCraftEvent.
     
  3. Offline

    CaLxCyMru

    Can you please show how?
     
Thread Status:
Not open for further replies.

Share This Page