Custom Item in Recipie

Discussion in 'Spigot Plugin Development' started by ersterstreber, May 3, 2015.

  1. Hey,
    I have a ShapedRecipe where I want to use an item with a custom lore as an ingredient. How could I do that? The setIngredient-method only takes a material, not a whole ItemStack.

    *Of course it it Recipe and not Recipie ;)
     
    #1 ersterstreber, May 3, 2015
    Last edited: May 4, 2015
  2. You could use reflection but I'm not sure if it will work :

    Code (Text):
    ItemStack output= new ItemStack(Material.EXP_BOTTLE, 1);

    ShapedRecipe sr= new ShapedRecipe(output);

    sr.shape(YOURSHAPE);

    ItemStack customIs = new ItemStack(Material.FEATHER);
            ArrayList<String> lore = new ArrayList<String>();
            lore.add("My lore");
            ItemMeta meta = customIs.getItemMeta();
            meta.setLore(lore);
            customIs.setItemMeta(meta);
         
            try{
                Field f = ShapedRecipe.class.getDeclaredField("ingredients");
                Map<Character, ItemStack> ingredientmap = (Map<Character, ItemStack>)f.get(sr);
                ingredientmap.put('*', customIs);
             
            }catch(Exception e){}
     
    Not tested typed from my phone..
     
  3. that should work so you should be good

     
  4. Tried it:
    My block is a renamed stone, it works with the custom block but also with a stone...

    //Just blocked it in the CraftItemEvent.
     
    #4 ersterstreber, May 4, 2015
    Last edited: May 4, 2015