Custom Recipe using Custom Item?

Discussion in 'Plugin Development' started by mccrafter1212, May 29, 2017.

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

    mccrafter1212

    So, I got my recipe code:

    ItemStack item = new ItemStack(Material.FLINT_AND_STEEL);
    ItemMeta itemMeta = item.getItemMeta();

    itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&l&2Chain"));

    List<String> lore = new ArrayList<String>();
    lore.add(ChatColor.GOLD + "Chains used to craft:");
    lore.add(ChatColor.GOLD + "* Chainmail Helmet");
    lore.add(ChatColor.GOLD + "* Chainmail Chestplate");
    lore.add(ChatColor.GOLD + "* Chainmail Leggings");
    lore.add(ChatColor.GOLD + "* Chainmail Boots");
    lore.add(ChatColor.ITALIC + "" + ChatColor.WHITE + "BetterRecipes");

    itemMeta.setLore(lore);

    item.setItemMeta(itemMeta);

    ShapedRecipe recipe = new ShapedRecipe(item);
    recipe.shape(
    " X ",
    "X X",
    " X "
    );
    recipe.setIngredient('X', Material.IRON_INGOT);
    Bukkit.getServer().addRecipe(recipe);

    This creates an item called "Chain"

    I've got a second recipe:

    ItemStack item = new ItemStack(Material.CHAINMAIL_HELMET);
    ItemMeta itemMeta = item.getItemMeta();

    itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&l&2Chainmail Helmet"));

    List<String> lore = new ArrayList<String>();
    lore.add(ChatColor.GOLD + "Sturdy helmet made from chains. Definitely stronger than an iron helmet.");
    lore.add(ChatColor.GOLD + "It's has so many layers of iron that it protects from fire!");
    lore.add(ChatColor.ITALIC + "" + ChatColor.WHITE + "BetterRecipes");

    itemMeta.setLore(lore);

    itemMeta.addEnchant(Enchantment.PROTECTION_FIRE, 5, true);

    item.setItemMeta(itemMeta);

    ShapedRecipe recipe = new ShapedRecipe(item);
    recipe.shape(
    "OOO",
    "O O",
    " "
    );
    recipe.setIngredient('X', Material.FLINT_AND_STEEL);
    Bukkit.getServer().addRecipe(recipe);

    I want this second recipe to use the item created with the first recipe, not just any flint and steel. How can I do this? Thanks! :D
     
  2. Offline

    Caderape2

    @mccrafter1212 You't cant with recipe add ingredient with itemMeta.
    I guess you have to check it on the event PrepareItemCraftEvent
     
  3. Offline

    mccrafter1212

    How could I go about doing this?
     
  4. Offline

    S1ant

    So people, Including me, Can see his code better:
    Code:java
    1. ItemStack item = new ItemStack(Material.FLINT_AND_STEEL);
    2. ItemMeta itemMeta = item.getItemMeta();
    3.  
    4. itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&l&2Chain"));
    5.  
    6. List<String> lore = new ArrayList<String>();
    7. lore.add(ChatColor.GOLD + "Chains used to craft:");
    8. lore.add(ChatColor.GOLD + "* Chainmail Helmet");
    9. lore.add(ChatColor.GOLD + "* Chainmail Chestplate");
    10. lore.add(ChatColor.GOLD + "* Chainmail Leggings");
    11. lore.add(ChatColor.GOLD + "* Chainmail Boots");
    12. lore.add(ChatColor.ITALIC + "" + ChatColor.WHITE + "BetterRecipes");
    13.  
    14. itemMeta.setLore(lore);
    15.  
    16. item.setItemMeta(itemMeta);
    17.  
    18. ShapedRecipe recipe = new ShapedRecipe(item);
    19. recipe.shape(
    20. " X ",
    21. "X X",
    22. " X "
    23. );
    24. recipe.setIngredient('X', Material.IRON_INGOT);
    25. Bukkit.getServer().addRecipe(recipe);
    26.  
    27. //This creates an item called "Chain"
    28.  
    29. //I've got a second recipe:
    30.  
    31. ItemStack item = new ItemStack(Material.CHAINMAIL_HELMET);
    32. ItemMeta itemMeta = item.getItemMeta();
    33.  
    34. itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&l&2Chainmail Helmet"));
    35.  
    36. List<String> lore = new ArrayList<String>();
    37. lore.add(ChatColor.GOLD + "Sturdy helmet made from chains. Definitely stronger than an iron helmet.");
    38. lore.add(ChatColor.GOLD + "It's has so many layers of iron that it protects from fire!");
    39. lore.add(ChatColor.ITALIC + "" + ChatColor.WHITE + "BetterRecipes");
    40.  
    41. itemMeta.setLore(lore);
    42.  
    43. itemMeta.addEnchant(Enchantment.PROTECTION_FIRE, 5, true);
    44.  
    45. item.setItemMeta(itemMeta);
    46.  
    47. ShapedRecipe recipe = new ShapedRecipe(item);
    48. recipe.shape(
    49. "OOO",
    50. "O O",
    51. " "
    52. );
    53. recipe.setIngredient('X', Material.FLINT_AND_STEEL);
    54. Bukkit.getServer().addRecipe(recipe);
     
    Dnyce72799 likes this.
  5. Offline

    Dnyce72799

    Your second recipe still has setIngredient('X', Material.FLINT_AND_STEEL); but your ingredient is 'O'. And I'm not 100% sure, but I don't think you're allowed to leave the recipe shape empty. You should add a new ingredient and set it to Material.AIR. I don't know for sure though.

    Sent from my LGLS775 using Tapatalk
     
  6. Offline

    S1ant

    @Dnyce72799 That there is false, You are supposed to leave to leave it empty indicating that they put nothing there, so there is no need to set that as air.
     
    Last edited: May 30, 2017
  7. Offline

    timtower Administrator Administrator Moderator

    @S1ant air is seen by Minecraft as nothing in a lot of cases.
    Even if you give yourself air nothing changes.
     
Thread Status:
Not open for further replies.

Share This Page