Custom Ingredients in Custom Recipes

Discussion in 'Bukkit Help' started by SyntaxError89, Nov 15, 2020.

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

    SyntaxError89

    Hello, I would just like to ask how to add custom ingredients as setIngredients in the ShapedRecipe. Here are my codes (Line 45 and 46 is where the custom ingredients need to be added):
    Code:
    import java.util.ArrayList;
    import java.util.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.NamespacedKey;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.inventory.ItemFlag;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class ItemManager {
       
        public static ItemStack GrapplingHook;
        public static ItemStack MathsPoint;
        public static ItemStack Grapple;
        public static ItemStack EnchantedString;
       
        public static void init() {
            createGrapplingHook();
            createMathsPoint();
            createGrapple();
            createEnchantedString();
        }
       
        private static void createGrapplingHook() {
            ItemStack item = new ItemStack(Material.FISHING_ROD, 1);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName("§9Grappling Hook");
            List<String> lore = new ArrayList<>();
            lore.add("§9RARE");
            lore.add("§7Travel in style with this useful tool");
            lore.add("But, beware of fall damage...");
            meta.setLore(lore);
            item.setItemMeta(meta);
            GrapplingHook = item;
           
            ShapedRecipe sr = new ShapedRecipe(NamespacedKey.minecraft("grappling_hook"), item);
            sr.shape("EGE",
                    "EIE",
                    " S ");
            sr.setIngredient('S', Material.STICK);
            sr.setIngredient('I', Material.IRON_INGOT);
            sr.setIngredient('E', EnchantedString.getData());
            sr.setIngredient('G', Grapple.getData());
            Bukkit.getServer().addRecipe(sr);
        }
        private static void createMathsPoint() {
            ItemStack item = new ItemStack(Material.NAME_TAG, 1);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName("§cMaths Point");
            List<String> lore = new ArrayList<>();
            lore.add("§cSPECIAL");
            lore.add("§cForged from the blood of Mathematics");
            meta.setLore(lore);
            item.setItemMeta(meta);
            MathsPoint = item;
        }
        private static void createGrapple() {
            ItemStack item = new ItemStack(Material.IRON_PICKAXE, 1);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName("§aGrapple");
            List<String> lore = new ArrayList<>();
            lore.add("§aUNCOMMON");
            lore.add("§7A secret core to an ancient tool.");
            meta.setLore(lore);
            item.setItemMeta(meta);
            Grapple = item;
        }   
        private static void createEnchantedString() {
            ItemStack item = new ItemStack(Material.STRING, 1);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName("§aEnchanted String");
            List<String> lore = new ArrayList<>();
            lore.add("§aUNCOMMON");
            lore.add("§7A compacted form of string.");
            lore.add("§7Making it tougher than normal string.");
            meta.setLore(lore);
            meta.addEnchant(Enchantment.DURABILITY, 3, false);
            meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
            item.setItemMeta(meta);
            EnchantedString = item;
           
            ShapedRecipe sr = new ShapedRecipe(NamespacedKey.minecraft("enchanted_string"), item);
            sr.shape("SDS",
                    "SDS",
                    "SDS");
            sr.setIngredient('S', Material.STRING);
            sr.setIngredient('D', Material.DIAMOND);
            Bukkit.getServer().addRecipe(sr);
        }   
    }
    Thank you!
     
Thread Status:
Not open for further replies.

Share This Page