Solved Using items with lore in custom recipe?

Discussion in 'Plugin Development' started by winglessraven, Aug 31, 2014.

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

    winglessraven

    Anyone know if you can use items with custom lore in a custom crafting recipe?

    e.g. I have some 'special' diamonds, only obtainable through dungeon runs that I want to use in a custom recipe to make some 'custom' armour.

    'special' diamonds have lore and I need to check for that in the crafting recipe, I can find how to create a custom recipe by Material so at the moment any diamond will do, but I'd like to be able to check for the lore.

    Anyone had experience with this, or know if it's possible?

    Cheers,
    Wingy.
     
  2. Offline

    nzkiwi.5000

    winglessraven likes this.
  3. Offline

    winglessraven

    Ahh good shout :) Works a treat!
     
  4. Offline

    octoshrimpy

    nzkiwi.5000 Mind showing that iteration? I've tried everything I can think of, and haven't managed to get it to work. Asking me to post code of what didn't work is going to be a waste of time, as I was at this for 4 hours, and the post would be too long to even bother reading. I am trying to create a shaped recipe that requires 3 custom items (named and with lore), and feel as if I have been smacking my head against a wall this whole time. (I may as well have, it would have done me just as good). no forums I've read managed to explain it, and I am at a loss here.
     
  5. Offline

    winglessraven

    Hi octoshrimpy,

    I'm at work at the moment so can't put any code snippets up yet, but basically what I did was create the custom recipes with the basic material settings, then use the PerpareItemCraftEvent to verify the items on the table had the lore required at the point of crafting. If they were just the material without the lore then I clear the output of the crafting table so nothing can be crafted.

    I'll post some code when I get home later.
     
  6. Offline

    octoshrimpy

    winglessraven What I got going is a custom recipe with regular items creating a lored item, and then another recipe with more regular items, that will be checked on PrepareItemCraftEvent, using the previous custom items. The making of the recipes itself isn't any trouble, it's checking through the items in the crafting grid (a FOR loop?) that has me stumped. :/

    Code:java
    1.  
    2.  
    3. public void loadRecipes(){
    4.  
    5. //set name & lore for Item Magnet
    6. ItemStack itemMagnet = new ItemStack(Material.COMPASS);
    7. ItemMeta iMagnetMeta = itemMagnet.getItemMeta();
    8. iMagnetMeta.setDisplayName(ChatColor.LIGHT_PURPLE+"Item Magnet");
    9. List<String> iMagnetLore = Arrays.asList(ChatColor.YELLOW+"Suck all the things!", "" , ChatColor.DARK_GRAY+"Octo's Items");
    10. iMagnetMeta.setLore(iMagnetLore);
    11. itemMagnet.setItemMeta(iMagnetMeta);
    12.  
    13. //Create recipe for Item Magnet
    14. ShapedRecipe iMagnetRecipe = new ShapedRecipe(itemMagnet);
    15. iMagnetRecipe.shape("ANA", "ACA", "ASA");
    16. iMagnetRecipe.setIngredient('A', Material.AIR);
    17. iMagnetRecipe.setIngredient('N', Material.NETHER_BRICK_ITEM);
    18. iMagnetRecipe.setIngredient('S', Material.IRON_INGOT);
    19.  
    20. Bukkit.addRecipe(iMagnetRecipe);
    21. }
    22. @EventHandler
    23. public void onCraft(PrepareItemCraftEvent e){
    24. if(e.getRecipe().getResult().equals(Material.COMPASS) && e.getInventory().contains(Material.NETHER_BRICK_ITEM)){
    25.  
    26. //check if items have lore
    27.  
    28. }
    29.  
    30. }
    31.  


    What I have so far.
    --EDIT-- renamed sections of code for continuity

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  7. Offline

    winglessraven

    octoshrimpy

    The way I've done it is to check the itemstack in the slots during the event and then pass the event if the criteria is met.

    Slot rangeDescription
    0 crafting output
    1-9 (3x3) crafting input (1 + x + 3 * y)
    10-36 main inventory
    37-45 held items

    Crafting table slots layout:

    1-2-3
    4-5-6
    7-8-9

    There is probably a more efficient way to do it, but I'm a Sunday coder ;)

    @octoshripmy

    Also, I don't think you need to use air in the recipe, just leave a space...

    Code:java
    1. //Create recipe for Item Magnet
    2. ShapedRecipe iMagnetRecipe = new ShapedRecipe(itemMagnet);
    3. iMagnetRecipe.shape(" N ", " C ", " S ");
    4. iMagnetRecipe.setIngredient('N', Material.NETHER_BRICK_ITEM);
    5. iMagnetRecipe.setIngredient('S', Material.IRON_INGOT);
    6. iMagnetRecipe.setIngredient('C', Material.COAL_BLOCK);


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  8. Offline

    octoshrimpy

    winglessraven
    Code:java
    1. @EventHandler
    2. public void onCraft(PrepareItemCraftEvent e){
    3. if(e.getRecipe().getResult().equals(Material.COMPASS) && e.getInventory().contains(Material.NETHER_BRICK_ITEM)){
    4.  
    5. for(int a = 1; a < 9; a ++){
    6. if(e.getInventory().getItem(a) != null){
    7. if(e.getInventory().getItem(a).getItemMeta().getLore().contains(ChatColor.DARK_GRAY+"Octo's Items")){
    8. //do something, craft item
    9. }
    10. }
    11. }
    12. }
    13.  
    14. }
    I dislike nested if's and may find a way around it, but this looks like it might work..
     
Thread Status:
Not open for further replies.

Share This Page