How to check for lore in recipes? help!

Discussion in 'Plugin Development' started by octoshrimpy, Sep 8, 2014.

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

    octoshrimpy

    How would I check for items with lore in custom recipes? say I have two recipes that create custom items with displayName and lore, and a third recipe that uses the items from the first two recipes. How would I go about checking for the lore in specific items for the specific recipes? is there a better way than checking each item in each recipe onPrepareItemCraftEvent? if so, how?
    Here's what I have so far:
    Code:java
    1. List<String> fancyRecipes = Arrays.asList("Material.COMPASS");
    2. @EventHandler
    3. public boolean checkCraft(PrepareItemCraftEvent e){
    4.  
    5. if(!fancyRecipes.contains(e.getRecipe().getResult())){
    6. return false;
    7. }
    8. for(int a = 1 ; a < 9 ; a ++){
    9. if(e.getInventory().getItem(a)!=null && e.getInventory().getItem(a).getItemMeta().getLore().contains(ChatColor.DARK_GRAY+"Octo's Items")){
    10. //craft all the stuffs; return true..?
    11. }else{
    12. return false;
    13. }
    14. }
    15. return true;
    16. }
     
  2. Offline

    Totom3

  3. Offline

    octoshrimpy

    Totom3 did you even scroll through that thread? >_> I replied to it, and the info I got still made no sense. I don't want to be spoonfed, but an explanation on how it works would be much appreciated.
     
  4. Offline

    octoshrimpy

    AdamQpzm Let's say I have a recipe that contains both custom items, and vanilla items. That check will make it stop working properly. And I guess my question also includes stopping the crafting event, since there's no e.setCancelled(true); I got this so that only named items with lore can be used:
    Code:java
    1.  
    2. List<String> fancyRecipes = Arrays.asList("Material.COMPASS");
    3. List<String> itemNames = Arrays.asList("Magnetic North", "Magnetic South", "Radiant Core", "Item Magnet", "Advanced Magnet");
    4. @EventHandler
    5. public void checkLore(PrepareItemCraftEvent e){
    6. if(!(fancyRecipes.contains(e.getRecipe().getResult()))){
    7. return;
    8. }
    9. for(int a=1; a<9; a++){
    10. ItemStack item = e.getInventory().getItem(a);
    11. if(item != null){
    12. if(itemNames.contains(item.getItemMeta().getDisplayName())){
    13. if(item.getItemMeta().getLore().contains("Octo's Items")){
    14. //craft stuff
    15. }else{
    16. e.getInventory().setItem(0, new ItemStack(Material.AIR));
    17. Player p = (Player) e.getView().getPlayer(); p.closeInventory(); p.sendMessage("You cannot cheat items in!");
    18. }
    19. }
    20. }
    21. }
    22.  
    23. }

    I have it close the inventory, but that feels messy to me. :/ public void vs public boolean? which is best? Will I have to check each recipe individually? Should I make a recipe checker class with all the recipes?
     
  5. octoshrimpy I'm not sure what you mean by it will mess up if you combine vanilla and non-vanilla. And you can't cancel the event, but you can set the result in the craft slot to air :)
     
  6. Offline

    octoshrimpy

    AdamQpzm What I mean is (how do I words) if I have a recipe that requires both vanilla items and custom items, will I need to check for the custom items in each possible recipe?
     
  7. octoshrimpy Still don't really understand, sorry, anyway you could give an example?
     
  8. Offline

    octoshrimpy

    AdamQpzm I don't understand it much myself xD Here is what my brain is thinking:

    there are a few kinds of recipes:
    1. vanilla item -> vanilla result
    2. vanilla item -> custom result
    3. custom item -> custom result
    4.custom item -> vanilla result
    5. vanilla + custom item -> custom result

    any recipe that takes custom items (3,4,5) need to have a check that the custom items have the name and the lore. No problem, just iterate through each item in the crafting grid and check that they have the name & lore.
    Now, imagine I have a recipe that required an ender pearl, 3 iron ingots, and a custom item that is a named and lore'd iron ingot. my fear ( and problem) is checking for ONLY the custom item. Maybe i'm just overcomplicating it, but will I have to check each custom recipe for the specific items, or is there an easy way to do something like:
    Code:java
    1. if(e.getRecipe() instanceof ShapedRecipe){
    2. Map<Character, ItemStack> ingredients = ((ShapedRecipe) e.getRecipe()).getIngredientMap();
    3. checkRecipe(e.getRecipe().getResult() ingredients);
    4. }
     
Thread Status:
Not open for further replies.

Share This Page