Advertisement
Guest User

grmph

a guest
Dec 30th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.96 KB | None | 0 0
  1. //RECIPE CLASS
  2.  
  3. package lyesoussaiden.satanicofferings.init.classes.recipes;
  4.  
  5. import java.util.HashMap;
  6. import java.util.Hashtable;
  7. import java.util.Map;
  8.  
  9. import net.minecraft.item.Item;
  10. import net.minecraft.item.ItemStack;
  11.  
  12. public class SatanicOfferingsRecipes {
  13.     public static class SatanicAltar
  14.     {  
  15.         private static int InputSlotCount = 4;
  16.        
  17.         /* 0 = Blood Énergy Cost
  18.          * 1 = Duration of Revision
  19.          * 2 = Output Item (AKA The Result) Stack-Size
  20.          */
  21.         private static Map<Item[], int[]> intVals = new HashMap<Item[], int[]>();
  22.         private static Map<Item[], int[]> recipeSizes = new HashMap<Item[], int[]>();
  23.         private static Map<Item[], Item> recipes = new HashMap<Item[], Item>();
  24.         public static void addRecipe(ItemStack output, ItemStack[] recipe, int bÉCost, int duration)
  25.         {
  26.             //Null Checks
  27.             if(output == null || recipe == null || bÉCost <= 0 || duration <= 0)
  28.             {
  29.                 System.out.println("NOTE! NULL PARAMETER DETECTED AND RECIPE NOT ADDED!");
  30.                 return;
  31.             }
  32.            
  33.             //Get a recipe and set a temporary variable to the recipe + recipe attributes
  34.             Item outputItem = output.getItem();
  35.             int outputItemSize = output.stackSize;
  36.             Item[] outputRecipe = new Item[InputSlotCount];
  37.             int[] outputSize = new int[InputSlotCount];
  38.             for(int i = 0; i < InputSlotCount; i++)
  39.             {
  40.                 if(recipe[i] != null)
  41.                 {
  42.                     outputRecipe[i] = recipe[i].getItem();
  43.                     outputSize[i] = recipe[i].stackSize;
  44.                 }
  45.                 else
  46.                 {
  47.                     outputRecipe[i] = null;
  48.                     outputSize[i] = 0;
  49.                 }
  50.             }
  51.            
  52.             //Put recipes and other variables within the Hashtables above.
  53.             recipes.put(outputRecipe, outputItem);
  54.             recipeSizes.put(outputRecipe, outputSize);
  55.             intVals.put(outputRecipe, new int[] {bÉCost, duration, outputItemSize});
  56.         }
  57.        
  58.         public static ItemStack getOutputFromRecipe(ItemStack[] recipe)
  59.         {
  60.             if(recipe != null)
  61.             {
  62.                 //Get a recipe and set a temporary variable to the recipe + recipe attributes
  63.  
  64.                 Item[] inputRecipe = new Item[InputSlotCount];
  65.                 int[] inputSize = new int[InputSlotCount];
  66.                 for(int i = 0; i < InputSlotCount; i++)
  67.                 {
  68.                     if(recipe[i] != null)
  69.                     {
  70.                         inputRecipe[i] = recipe[i].getItem();
  71.                         inputSize[i] = recipe[i].stackSize;
  72.                     }
  73.                     else
  74.                     {
  75.                         inputRecipe[i] = null;
  76.                         inputSize[i] = 0;
  77.                     }
  78.                 }
  79.                 Item outputItem = recipes.get(inputRecipe);
  80.  
  81.                 int outputItemSize = intVals.get(inputRecipe)[2];
  82.                
  83.                 if(outputItem != null && outputItemSize > 0)
  84.                 return new ItemStack(outputItem, outputItemSize);
  85.                
  86.             }
  87.            
  88.             return null;
  89.         }
  90.     }
  91. }
  92.  
  93. //METHODS CALLING IT
  94.  
  95.         /*SATANIC ALTAR RECIPES*/
  96.         //Obsidian Fragment
  97.         SatanicOfferingsRecipes.SatanicAltar.addRecipe(new ItemStack(ModItems.obsidianFragment, 4), new ItemStack[] {null, new ItemStack(Blocks.obsidian, 1), new ItemStack(Items.flint, 1), null}, 600, 10);
  98.         ItemStack debugOutput = SatanicOfferingsRecipes.SatanicAltar.getOutputFromRecipe(new ItemStack[] {null, new ItemStack(Blocks.obsidian, 1), new ItemStack(Items.flint, 1), null});
  99.         System.out.println(debugOutput.getDisplayName());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement