Add lore to result in shapeless recipe

Discussion in 'Plugin Development' started by CraterHater, Jul 18, 2016.

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

    CraterHater

    Hey, I am making a plugin which should add "Enchanting" to the game, I have a series of books which I want to be able to combine in a workbench. I want this to be a shapeless recipe of a sword and a book and I want the result to be the same sword with the lore of the book. How do I do this?

    Thanks.
     
  2. Offline

    thapengwin

    Just get the crafted item and edit it's metadata
     
  3. Offline

    CraterHater

    @thapengwin I mean like;

    1. I put in WOOD_SWORD, and BOOK
    2. I get WOOD_SWORD with lore of BOOK
     
  4. Offline

    thapengwin

    Pretty much the same thing, all you need to do is loop through the items that are being crafted, find the book, save it's lore, then get the crafted item, get its ItemMeta, set the lore, save ItemMeta and place the crafted item in the crafting slot.
     
  5. Offline

    CraterHater

    @thapengwin I now got this, but it doesn't work:

    Code:
    public void onCraftPrepare(PrepareItemCraftEvent event){
               for(ItemStack ingredients : event.getInventory().getContents()){
                   if(ingredients != null){
                       if(ingredients.getType() == Material.ENCHANTED_BOOK){
                           if(ingredients.hasItemMeta()){
                               if(ingredients.getItemMeta().hasLore()){
                                   for(ItemStack ingredients1 : event.getInventory().getContents()){
                                       if(ingredients1 != null){
                                           if(ingredients1.getType() == Material.WOOD_SWORD){
                                               if(!ingredients.hasItemMeta()){
                                                   ItemStack result = new ItemStack(ingredients1.getType(),1);
                                                       ItemMeta im = result.getItemMeta();
                                                       ArrayList<String> lore = new ArrayList<String>();
                                                       lore.add(ingredients.getItemMeta().getLore().get(1));
                                                       im.setLore(lore);
                                                       result.setItemMeta(im);
                                                      
                                                    event.getInventory().setResult(result);
                                               }else{
                                                       if(!ingredients.getItemMeta().hasLore()){
                                                          
                                                           ItemStack result = new ItemStack(ingredients1.getType(),1);
                                                           ItemMeta im = result.getItemMeta();
                                                           ArrayList<String> lore = new ArrayList<String>();
                                                           lore.add(ingredients.getItemMeta().getLore().get(1));
                                                           im.setLore(lore);
                                                           result.setItemMeta(im);
                                                          
                                                        event.getInventory().setResult(result);
                                                   }
                                               }
                                           }
                                       }
                                   }
                               }
                           }
                       }
                   }
               }
            }
     
Thread Status:
Not open for further replies.

Share This Page