Advertisement
Guest User

Getting the recipes

a guest
May 30th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.67 KB | None | 0 0
  1.     public static final void removeAllRecipes()
  2.     {
  3.         List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
  4.        
  5.        
  6.         Iterator<IRecipe> Leash = recipes.iterator();
  7.         {
  8.             while (Leash.hasNext())
  9.             {
  10.                 //Get Recipe
  11.                 IRecipe recipe = Leash.next();
  12.                 //Remove Recipe
  13.                 Leash.remove();
  14.                 //Add the Recipe back
  15.                 addVanillaRecipes(recipe);
  16.             }
  17.            
  18.         }
  19.     }
  20.  
  21.     /**
  22.      * Adds the recipe back to minecraft with my custom requirements.
  23.      */
  24.     private static final void addVanillaRecipes(IRecipe recipe)
  25.     {
  26.        
  27.         char letters[] = {'a','b','c','d','e','f','g','h','i'};
  28.        
  29.        
  30.         if(recipe instanceof ShapedOreRecipe)
  31.         {
  32.            
  33.             ItemStack result = recipe.getRecipeOutput();
  34.             if(result != null && result.getUnlocalizedName().equals(Items.wooden_axe.getUnlocalizedName()))
  35.             {
  36.                 int hi = 0;
  37.             }
  38.            
  39.             //Gets list of Items within
  40.             Object[] locationNumbers = ((ShapedOreRecipe)recipe).getInput();
  41.            
  42.             String[] recipeData = {"","",""};
  43.             ItemStack[] stacks = new ItemStack[9];
  44.             for(int i = 0; i < locationNumbers.length; i++)
  45.             {
  46.                 int index = i/3;
  47.                
  48.                 if ( locationNumbers[i] != null)
  49.                 {
  50.                     if(locationNumbers[i] instanceof List)
  51.                     {
  52.                         stacks[i] = (ItemStack)((List)locationNumbers[i]).get(0);
  53.                         recipeData[index] += letters[i];
  54.                     }
  55.                     else if(locationNumbers[i] instanceof ItemStack)
  56.                     {
  57.                         stacks[i] = (ItemStack) locationNumbers[i];
  58.                         recipeData[index] += letters[i];
  59.                     }
  60.                 }
  61.                 else
  62.                 {
  63.                     recipeData[index] += ' ';
  64.                 }
  65.             }
  66.            
  67.             System.out.println("The next thing makes : " + result.getUnlocalizedName());
  68.            
  69.             new CustomShapedOreRecipe( new CraftingRequirement(new byte[]{},
  70.                                         new byte[]{},
  71.                                         new short[]{, },
  72.                                         new byte[]{}),
  73.                                        
  74.                                         result, getObjectRecipe(recipeData, stacks));
  75.         }
  76.         else if(recipe instanceof ShapelessOreRecipe)
  77.         {
  78.             ArrayList<Object> stacks = ((ShapelessOreRecipe)recipe).getInput();
  79.             ItemStack result = recipe.getRecipeOutput();
  80.            
  81.             int temp = 0;
  82.         }
  83.        
  84.         else if(recipe instanceof ShapedRecipes)
  85.         {
  86.             ItemStack[] stacks = (ItemStack[])((ShapedRecipes)recipe).recipeItems;
  87.             ItemStack result = recipe.getRecipeOutput();
  88.            
  89.            
  90.             int temp = 0;
  91.         }
  92.     }
  93.  
  94.     private static final Object[] getObjectRecipe(String[] recipeData, ItemStack[] stacks)
  95.     {
  96.         //What will be returned
  97.         Object[] RETURN;
  98.        
  99.         //Holds each letter in the string without spaces
  100.         String charMap = "";
  101.        
  102.         //Holds each ItemStack next to eachother
  103.         ItemStack[] stacksMap;
  104.         //Obtains the size of the array without spaces
  105.         int trueStacksSize = 0;
  106.        
  107.         for(int i = 0; i < 3; i++)
  108.         {
  109.             String recipe = recipeData[i];
  110.            
  111.             for(int k = 0; k < recipe.length(); k++)
  112.             {
  113.                 if(recipe.charAt(k) != ' ')
  114.                 {
  115.                     charMap += recipe.charAt(k);
  116.                     trueStacksSize++;
  117.                 }
  118.             }
  119.         }
  120.        
  121.         //Defines stacksMap Array with no spaces
  122.         int index = 0;
  123.         stacksMap = new ItemStack[trueStacksSize];
  124.         for(int i = 0; i < 9; i++)
  125.         {
  126.             if(stacks[i] != null)
  127.             {
  128.                 stacksMap[index] = stacks[i];
  129.                 index++;
  130.             }
  131.         }
  132.        
  133.         String replaceMap = "";
  134.        
  135.         ItemStack currentStack, previousStack;
  136.         int charsRemoved= 0;
  137.         for(int i = 1; i < stacksMap.length; i++)
  138.         {
  139.             previousStack = stacksMap[i - 1];
  140.            
  141.             int numberOfStacksRemoved = 0;
  142.             for(int recipeIndex = i; recipeIndex < stacksMap.length; recipeIndex++)
  143.             {
  144.                 currentStack = stacksMap[recipeIndex];
  145.                
  146.                 if(currentStack.getUnlocalizedName().equals(previousStack.getUnlocalizedName()))
  147.                 {
  148.                     int charIndex = recipeIndex - charsRemoved;
  149.                    
  150.                     //Add the letter that needs replacing for later use
  151.                     replaceMap += charMap.charAt(charIndex);
  152.                    
  153.                     //Add the letter that will replace above letter for later use
  154.                     replaceMap += charMap.charAt(i - 1);
  155.                    
  156.                     //Shorten charMap to only unique characters
  157.                     charMap = charMap.replace("" + charMap.charAt(charIndex), "");
  158.                     charsRemoved +=1 ;
  159.                    
  160.                     stacksMap[recipeIndex] = null;
  161.                     numberOfStacksRemoved++;
  162.                 }
  163.             }
  164.            
  165.             //Shorten StacksMap to only unique occurences
  166.             ItemStack[] clone = new ItemStack[stacksMap.length - numberOfStacksRemoved];
  167.             for(int k = 0, cloneIndex = 0; k < stacksMap.length; k++)
  168.             {
  169.                 if(stacksMap[k] != null)
  170.                 {
  171.                     clone[cloneIndex] = stacksMap[k];
  172.                     cloneIndex++;
  173.                 }
  174.             }
  175.             stacksMap = clone;
  176.             charsRemoved = 0;
  177.            
  178.         }
  179.        
  180.         //Update old recipe (Make it use as few letters as needed)
  181.         for(int i = 0; i < 3; i++)
  182.         {
  183.             for(int l = 0; l < replaceMap.length(); l += 2)
  184.             {
  185.                 recipeData[i] = recipeData[i].replace(replaceMap.charAt(l), replaceMap.charAt(l+1));
  186.             }
  187.         }
  188.     //MORE BELOW, BUT UNIMPORTANT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement