Advertisement
TechMage66

RecipesCauldron

Jul 28th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. package com.techmage.magetech.crafting;
  2.  
  3. import net.minecraft.item.Item;
  4. import net.minecraft.item.ItemStack;
  5. import java.util.*;
  6.  
  7. public class RecipesCauldron
  8. {
  9.  
  10.     private static final RecipesCauldron cauldronBase = new RecipesCauldron();
  11.     public static RecipesCauldron crafting() { return cauldronBase; }
  12.     private RecipesCauldron() { }
  13.  
  14.     private Map recipes = new HashMap<ItemStack, ArrayList<Item>>();
  15.  
  16.     public void addRecipe(ItemStack output, Item ... inputs)
  17.     {
  18.         ArrayList<Item> inputList = new ArrayList<Item>();
  19.  
  20.         for (Item input : inputs)
  21.             inputList.add(input);
  22.  
  23.         recipes.put(output, inputList);
  24.     }
  25.  
  26.     public boolean hasCraftingResult(Item ... inputs)
  27.     {
  28.         ArrayList<Item> inputList = new ArrayList<Item>();
  29.         Iterator<Map.Entry<ItemStack, ArrayList<Item>>> iterator = recipes.entrySet().iterator();
  30.  
  31.         for (Item input : inputs)
  32.             inputList.add(input);
  33.  
  34.         while (iterator.hasNext())
  35.         {
  36.             Map.Entry<ItemStack, ArrayList<Item>> entry = iterator.next();
  37.  
  38.             if (entry.getValue().containsAll(inputList) && entry.getValue().size() == inputList.size())
  39.                 return true;
  40.         }
  41.  
  42.         return false;
  43.     }
  44.  
  45.     public ItemStack getCraftingResult(Item ... inputs)
  46.     {
  47.         ArrayList<Item> inputList = new ArrayList<Item>();
  48.         Iterator<Map.Entry<ItemStack, ArrayList<Item>>> iterator = recipes.entrySet().iterator();
  49.  
  50.         for (Item input : inputs)
  51.             inputList.add(input);
  52.  
  53.         while (iterator.hasNext())
  54.         {
  55.             Map.Entry<ItemStack, ArrayList<Item>> entry = iterator.next();
  56.  
  57.             if (entry.getValue().containsAll(inputList) && entry.getValue().size() == inputList.size())
  58.                 return entry.getKey();
  59.         }
  60.  
  61.         return null;
  62.     }
  63.  
  64.     public ArrayList<Item> getCraftingIngredients(ItemStack output)
  65.     {
  66.         Iterator<Map.Entry<ItemStack, ArrayList<Item>>> iterator = recipes.entrySet().iterator();
  67.  
  68.         while (iterator.hasNext())
  69.         {
  70.             Map.Entry<ItemStack, ArrayList<Item>> entry = iterator.next();
  71.  
  72.             if (entry.getKey().getItem() == output.getItem() && entry.getKey().stackSize == output.stackSize && entry.getKey().getItemDamage() == output.getItemDamage())
  73.                 return entry.getValue();
  74.         }
  75.  
  76.         return null;
  77.     }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement