Advertisement
TechMage66

RecipesCrystalInfuser

May 14th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.20 KB | None | 0 0
  1. package com.techmage.magetech.item.crafting;
  2.  
  3. import net.minecraft.entity.item.EntityItem;
  4. import net.minecraft.item.Item;
  5. import net.minecraft.item.ItemStack;
  6.  
  7. import java.util.ArrayList;
  8. import java.util.List;
  9.  
  10. public class RecipesCrystalInfuser
  11. {
  12.     private static final RecipesCrystalInfuser infusingBase = new RecipesCrystalInfuser();
  13.  
  14.     public static RecipesCrystalInfuser infusing()
  15.     {
  16.         return infusingBase;
  17.     }
  18.  
  19.     private RecipesCrystalInfuser() { }
  20.  
  21.     private List<Item> outputs = new ArrayList<Item>();
  22.     private List<List<ItemStack>> inputs = new ArrayList<List<ItemStack>>();
  23.  
  24.     public void addRecipe(Item output, List<ItemStack> inputs)
  25.     {
  26.         this.outputs.add(output);
  27.         this.inputs.add(inputs);
  28.     }
  29.  
  30.     /**
  31.      * @param inputs List of ItemEntities to get the craftingResults for
  32.      * @return A List of items with all available recipes for the given items
  33.      */
  34.     public List<Item> getCraftingResults(List inputs)
  35.     {
  36.         List<Item> craftingResults = new ArrayList<Item>();
  37.         List<Item> inputItems = new ArrayList<Item>();
  38.  
  39.         // Convert the input EntityItems to Items ...
  40.         for (EntityItem entityItem : (List<EntityItem>) inputs)
  41.         {
  42.             inputItems.add(entityItem.getEntityItem().getItem());
  43.         }
  44.  
  45.         // Get the crafting result
  46.         for (List<ItemStack> sInputs : this.inputs)
  47.         {
  48.             int equal = 0;
  49.  
  50.             for (ItemStack sInput : sInputs)
  51.             {
  52.                 if (inputItems.contains(sInput.getItem()))
  53.                     equal ++;
  54.             }
  55.  
  56.             if (equal == sInputs.size())
  57.                 craftingResults.add(outputs.get(this.inputs.indexOf(sInputs)));
  58.         }
  59.  
  60.         return craftingResults;
  61.     }
  62.  
  63.     public Item getNextCraftingResult(List<Item> craftingResults, Item currentResult)
  64.     {
  65.         if (craftingResults == null) return null;
  66.  
  67.         if (currentResult == null)
  68.             return craftingResults.get(0);
  69.  
  70.         else
  71.         {
  72.             if (craftingResults.indexOf(currentResult) == craftingResults.size() - 1)
  73.                 return null;
  74.  
  75.             else
  76.                 return craftingResults.get(craftingResults.indexOf(currentResult) + 1);
  77.         }
  78.     }
  79.  
  80.     public List<ItemStack> getNeededInputs(Item output)
  81.     {
  82.         return this.outputs.contains(output) ? this.inputs.get(this.outputs.indexOf(output)) : null;
  83.     }
  84.  
  85.     public boolean hasCraftingResult(List inputs)
  86.     {
  87.         List<Item> inputItems = new ArrayList<Item>();
  88.  
  89.         // Convert the input EntityItems to Items ...
  90.         for (EntityItem entityItem : (List<EntityItem>) inputs)
  91.         {
  92.             inputItems.add(entityItem.getEntityItem().getItem());
  93.         }
  94.  
  95.         // Check if there is a recipe registered for the given items
  96.         for (List<ItemStack> sInputs : this.inputs)
  97.         {
  98.             int equal = 0;
  99.  
  100.             for (ItemStack sInput : sInputs)
  101.             {
  102.                 if (inputItems.contains(sInput.getItem()))
  103.                     equal ++;
  104.             }
  105.  
  106.             if (equal == sInputs.size())
  107.                 return true;
  108.         }
  109.  
  110.         return false;
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement