ShapedRecipe

Discussion in 'Plugin Development' started by koniad776, Dec 21, 2019.

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

    koniad776

    I have a problem. I have created two items. And I want to make the second item make crafted using the first item, but I have to use MATERIAL. Is there any way to make crafting without using MATERIAL? Or using ItemStack?

    Here's my code:
    Code:
    package me.mycarttv.piwo.crafting;
    
    import java.util.ArrayList;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemFlag;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.Plugin;
    
    import me.mycarttv.piwo.main;
    
    public class piwo implements Listener{
        private Plugin plugin = main.getPlugin(main.class);
       
        @SuppressWarnings("deprecation")
        public void crafting() {
            /* Create required item to make another one */
            ItemStack baza = new ItemStack(Material.POTION);
            ItemMeta bazaMeta = baza.getItemMeta();
           
            bazaMeta.setDisplayName("Baza");
            ArrayList<String> bazaLore = new ArrayList<String>();
            bazaLore.add(ChatColor.GREEN + "Baza wymagana do utworzenia piwa");
            bazaMeta.setLore(bazaLore);
            bazaMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
            baza.setItemMeta(bazaMeta);
            ShapedRecipe rBaza = new ShapedRecipe(baza);
           
            rBaza.shape("@@@", "@#@", "@[email protected]");
            rBaza.setIngredient('@', Material.SUGAR);
            rBaza.setIngredient('#', Material.GLASS_BOTTLE);
            rBaza.setIngredient('$', Material.WATER_BUCKET);
           
           
            /* Create this item using default items and using create one above */
            ItemStack piwo = new ItemStack(Material.POTION);
            ItemMeta piwoMeta = piwo.getItemMeta();
           
            piwoMeta.setDisplayName(ChatColor.GOLD + "Piwo");
            ArrayList<String> piwoLore = new ArrayList<String>();
            piwoLore.add(ChatColor.GREEN + "Aaaa dobra perełka");
            piwoMeta.setLore(piwoLore);
            piwoMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
            piwo.setItemMeta(piwoMeta);
            ShapedRecipe rPiwo = new ShapedRecipe(piwo);
           
            rPiwo.shape("@@@", "@[email protected]", "@#@");
            rPiwo.setIngredient('@', Material.SUGAR);
            rPiwo.setIngredient('#', Material.POTION); //How can I use there "baza" item?
            rPiwo.setIngredient('$', Material.GLASS_BOTTLE);
            plugin.getServer().addRecipe(rPiwo);
        }
    }
     
    Last edited by a moderator: Dec 22, 2019
  2. Offline

    thechrisanator

    You have to used ShapedRecipe with Materials.
    You'll want to create a custom recipe API or something if you want to make custom recipes with itemstacks.
     
  3. Offline

    koniad776

    So I can't make custom recipe using material with Lore or meta?
     
  4. Offline

    knokko

    To do this, you can add a simple shaped recipe for your custom items (with only using the Material of the ingredient). Then, you need to listen for PrepareItemCraftEvent and prevent the crafting of your second custom item if the ingredient is not equal to your first custom item. (I believe it's setResult(null) or setCancelled(true), but I don't remember exactly)
     
Thread Status:
Not open for further replies.

Share This Page