Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static final void removeAllRecipes()
- {
- List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
- Iterator<IRecipe> Leash = recipes.iterator();
- {
- while (Leash.hasNext())
- {
- //Get Recipe
- IRecipe recipe = Leash.next();
- //Remove Recipe
- Leash.remove();
- //Add the Recipe back
- addVanillaRecipes(recipe);
- }
- }
- }
- /**
- * Adds the recipe back to minecraft with my custom requirements.
- */
- private static final void addVanillaRecipes(IRecipe recipe)
- {
- char letters[] = {'a','b','c','d','e','f','g','h','i'};
- if(recipe instanceof ShapedOreRecipe)
- {
- ItemStack result = recipe.getRecipeOutput();
- if(result != null && result.getUnlocalizedName().equals(Items.wooden_axe.getUnlocalizedName()))
- {
- int hi = 0;
- }
- //Gets list of Items within
- Object[] locationNumbers = ((ShapedOreRecipe)recipe).getInput();
- String[] recipeData = {"","",""};
- ItemStack[] stacks = new ItemStack[9];
- for(int i = 0; i < locationNumbers.length; i++)
- {
- int index = i/3;
- if ( locationNumbers[i] != null)
- {
- if(locationNumbers[i] instanceof List)
- {
- stacks[i] = (ItemStack)((List)locationNumbers[i]).get(0);
- recipeData[index] += letters[i];
- }
- else if(locationNumbers[i] instanceof ItemStack)
- {
- stacks[i] = (ItemStack) locationNumbers[i];
- recipeData[index] += letters[i];
- }
- }
- else
- {
- recipeData[index] += ' ';
- }
- }
- System.out.println("The next thing makes : " + result.getUnlocalizedName());
- new CustomShapedOreRecipe( new CraftingRequirement(new byte[]{},
- new byte[]{},
- new short[]{, },
- new byte[]{}),
- result, getObjectRecipe(recipeData, stacks));
- }
- else if(recipe instanceof ShapelessOreRecipe)
- {
- ArrayList<Object> stacks = ((ShapelessOreRecipe)recipe).getInput();
- ItemStack result = recipe.getRecipeOutput();
- int temp = 0;
- }
- else if(recipe instanceof ShapedRecipes)
- {
- ItemStack[] stacks = (ItemStack[])((ShapedRecipes)recipe).recipeItems;
- ItemStack result = recipe.getRecipeOutput();
- int temp = 0;
- }
- }
- private static final Object[] getObjectRecipe(String[] recipeData, ItemStack[] stacks)
- {
- //What will be returned
- Object[] RETURN;
- //Holds each letter in the string without spaces
- String charMap = "";
- //Holds each ItemStack next to eachother
- ItemStack[] stacksMap;
- //Obtains the size of the array without spaces
- int trueStacksSize = 0;
- for(int i = 0; i < 3; i++)
- {
- String recipe = recipeData[i];
- for(int k = 0; k < recipe.length(); k++)
- {
- if(recipe.charAt(k) != ' ')
- {
- charMap += recipe.charAt(k);
- trueStacksSize++;
- }
- }
- }
- //Defines stacksMap Array with no spaces
- int index = 0;
- stacksMap = new ItemStack[trueStacksSize];
- for(int i = 0; i < 9; i++)
- {
- if(stacks[i] != null)
- {
- stacksMap[index] = stacks[i];
- index++;
- }
- }
- String replaceMap = "";
- ItemStack currentStack, previousStack;
- int charsRemoved= 0;
- for(int i = 1; i < stacksMap.length; i++)
- {
- previousStack = stacksMap[i - 1];
- int numberOfStacksRemoved = 0;
- for(int recipeIndex = i; recipeIndex < stacksMap.length; recipeIndex++)
- {
- currentStack = stacksMap[recipeIndex];
- if(currentStack.getUnlocalizedName().equals(previousStack.getUnlocalizedName()))
- {
- int charIndex = recipeIndex - charsRemoved;
- //Add the letter that needs replacing for later use
- replaceMap += charMap.charAt(charIndex);
- //Add the letter that will replace above letter for later use
- replaceMap += charMap.charAt(i - 1);
- //Shorten charMap to only unique characters
- charMap = charMap.replace("" + charMap.charAt(charIndex), "");
- charsRemoved +=1 ;
- stacksMap[recipeIndex] = null;
- numberOfStacksRemoved++;
- }
- }
- //Shorten StacksMap to only unique occurences
- ItemStack[] clone = new ItemStack[stacksMap.length - numberOfStacksRemoved];
- for(int k = 0, cloneIndex = 0; k < stacksMap.length; k++)
- {
- if(stacksMap[k] != null)
- {
- clone[cloneIndex] = stacksMap[k];
- cloneIndex++;
- }
- }
- stacksMap = clone;
- charsRemoved = 0;
- }
- //Update old recipe (Make it use as few letters as needed)
- for(int i = 0; i < 3; i++)
- {
- for(int l = 0; l < replaceMap.length(); l += 2)
- {
- recipeData[i] = recipeData[i].replace(replaceMap.charAt(l), replaceMap.charAt(l+1));
- }
- }
- //MORE BELOW, BUT UNIMPORTANT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement