Advertisement
Guest User

Untitled

a guest
Jan 12th, 2012
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.39 KB | None | 0 0
  1. package net.minecraft.src.ic2.api;
  2.  
  3. /**
  4.  * @file
  5.  * @author Player
  6.  * @version 1.0
  7.  *
  8.  * @section DESCRIPTION
  9.  *
  10.  * The Ic2Recipes api class provides access to the Compressor, Extractor and Macerator recipes.
  11.  *
  12.  * The recipes are only valid after IC2 has been loaded.
  13.  * The recipes are both meta and value sensitive, you can specify n:m processes, e.g. compress 3
  14.  * wooden planks into 2 sticks.
  15.  */
  16.  
  17. import java.util.AbstractMap;
  18. import java.util.List;
  19. import java.util.Map;
  20.  
  21. import net.minecraft.src.Block;
  22. import net.minecraft.src.Item;
  23. import net.minecraft.src.ItemStack;
  24.  
  25. public final class Ic2Recipes {
  26.     /**
  27.      * Retrieve the registered Compressor recipes, key = input, value = output
  28.      */
  29.     public static List<Map.Entry<ItemStack, ItemStack> > getCompressorRecipes() {
  30.         try {
  31.             return (List<Map.Entry<ItemStack, ItemStack> >) Class.forName("net.minecraft.src.ic2.common.TileEntityCompressor").getField("recipes").get(null);
  32.         } catch (Exception e) {
  33.             throw new RuntimeException(e);
  34.         }
  35.     }
  36.    
  37.     /**
  38.      * Add a Compressor recipe
  39.      */
  40.     public static void addCompressorRecipe(ItemStack input, ItemStack output) {
  41.         getCompressorRecipes().add(new AbstractMap.SimpleEntry<ItemStack, ItemStack>(input, output));
  42.     }
  43.    
  44.    
  45.     /**
  46.      * Get the Compressor output for a specific ItemStack
  47.      *
  48.      * @param input Input ItemStack
  49.      * @param adjustInput remove the process requirements from input
  50.      * @return resulting output ItemStack for the specified input ItemStack, independent ItemStack instance
  51.      */
  52.     public static ItemStack getCompressorOutputFor(ItemStack input, boolean adjustInput) {
  53.         return getOutputFor(input, adjustInput, getCompressorRecipes());
  54.     }
  55.    
  56.     /**
  57.      * Retrieve the registered Extractor recipes, key = input, value = output
  58.      */
  59.     public static List<Map.Entry<ItemStack, ItemStack> > getExtractorRecipes() {
  60.         try {
  61.             return (List<Map.Entry<ItemStack, ItemStack> >) Class.forName("net.minecraft.src.ic2.common.TileEntityExtractor").getField("recipes").get(null);
  62.         } catch (Exception e) {
  63.             throw new RuntimeException(e);
  64.         }
  65.     }
  66.    
  67.     /**
  68.      * Add a Extractor recipe
  69.      */
  70.     public static void addExtractorRecipe(ItemStack input, ItemStack output) {
  71.         getExtractorRecipes().add(new AbstractMap.SimpleEntry<ItemStack, ItemStack>(input, output));
  72.     }
  73.    
  74.    
  75.     /**
  76.      * Get the Extractor output for a specific ItemStack
  77.      *
  78.      * @param input Input ItemStack
  79.      * @param adjustInput remove the process requirements from input
  80.      * @return resulting output ItemStack for the specified input ItemStack, independent ItemStack instance
  81.      */
  82.     public static ItemStack getExtractorOutputFor(ItemStack input, boolean adjustInput) {
  83.         return getOutputFor(input, adjustInput, getExtractorRecipes());
  84.     }
  85.    
  86.     /**
  87.      * Retrieve the registered Macerator recipes, key = input, value = output
  88.      */
  89.     public static List<Map.Entry<ItemStack, ItemStack> > getMaceratorRecipes() {
  90.         try {
  91.             return (List<Map.Entry<ItemStack, ItemStack> >) Class.forName("net.minecraft.src.ic2.common.TileEntityMacerator").getField("recipes").get(null);
  92.         } catch (Exception e) {
  93.             throw new RuntimeException(e);
  94.         }
  95.     }
  96.    
  97.     /**
  98.      * Add a Macerator recipe
  99.      */
  100.     public static void addMaceratorRecipe(ItemStack input, ItemStack output) {
  101.         getMaceratorRecipes().add(new AbstractMap.SimpleEntry<ItemStack, ItemStack>(input, output));
  102.     }
  103.    
  104.    
  105.     /**
  106.      * Get the Macerator output for a specific ItemStack
  107.      *
  108.      * @param input Input ItemStack
  109.      * @param adjustInput remove the process requirements from input
  110.      * @return resulting output ItemStack for the specified input ItemStack, independent ItemStack instance
  111.      */
  112.     public static ItemStack getMaceratorOutputFor(ItemStack input, boolean adjustInput) {
  113.         return getOutputFor(input, adjustInput, getMaceratorRecipes());
  114.     }
  115.    
  116.    
  117.     private static ItemStack getOutputFor(ItemStack input, boolean adjustInput, List<Map.Entry<ItemStack, ItemStack> > recipeList) {
  118.         for (Map.Entry<ItemStack, ItemStack> entry: recipeList) {
  119.             if (entry.getKey().isItemEqual(input) && input.stackSize >= entry.getKey().stackSize) {
  120.                 if (adjustInput) input.stackSize -= entry.getKey().stackSize;
  121.                
  122.                 return entry.getValue().copy();
  123.             }
  124.         }
  125.        
  126.         return null;
  127.     }
  128.    
  129.    
  130.     /**
  131.      * Retrieve the registered Recycler blacklist, key = blacklisted item
  132.      */
  133.     public static List<ItemStack> getRecyclerBlacklist() {
  134.         try {
  135.             return (List<ItemStack>) Class.forName("net.minecraft.src.ic2.common.TileEntityRecycler").getField("blacklist").get(null);
  136.         } catch (Exception e) {
  137.             throw new RuntimeException(e);
  138.         }
  139.     }
  140.    
  141.     /**
  142.      * Add a blacklisted item to recycler
  143.      */
  144.     public static void addRecyclerBlacklistItem(ItemStack newBlacklistedItem) {
  145.         getRecyclerBlacklist().add(newBlacklistedItem);
  146.     }
  147.    
  148.     public static void addRecyclerBlacklistItem(Item newBlacklistedItem) {
  149.         addRecyclerBlacklistItem(new ItemStack(newBlacklistedItem));
  150.     }
  151.    
  152.     public static void addRecyclerBlacklistItem(Block newBlacklistedBlock) {
  153.         addRecyclerBlacklistItem(new ItemStack(newBlacklistedBlock));
  154.     }
  155.    
  156.    
  157.     /**
  158.      * Test to see if item is blacklisted in the recycler
  159.      * Quantity does not matter in isItemEqual()
  160.      *
  161.      * @param input testItem ItemStack
  162.      * @return true if item is blacklisted
  163.      */
  164.    
  165.     public static boolean isRecyclerInputBlacklisted(ItemStack itemStack) {
  166.         for (ItemStack blackItem: getRecyclerBlacklist()) {
  167.             if (itemStack.isItemEqual(blackItem)) return true;
  168.         }
  169.        
  170.         return false;
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement