Jump to content

Recommended Posts

Posted

I tried to remove a vanilla recipe by deleting it from the list. It is the recipe for making pumpkin seeds.

    	ShapedRecipes noRecipe1 = this.getShapedRecipesFromRecipe(new ItemStack(Item.pumpkinSeeds, 4), new Object[] {"M", 'M', Block.pumpkin});
    	CraftingManager.getInstance().getRecipeList().remove(noRecipe1);

FYI: getShapedRecipesFromRecipe is a method I made that mimics the CraftingManager.addRecipe except it doesn't add the recipe to the list.

Please tell me what I am doing wrong.

Posted

It's not really CPU heavy, it only gets called once when the mod's loaded.

 

 

A few helpful lines:


    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();

This gets the recipe list.

 

            if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {
                recipes.remove(i--);
                    }

This, in conjunction with a few other things allows you to compare an itemstack passed in (resultItem) and the result of the recipe, which you can get with:

 

ItemStack recipeResult = recipe.getRecipeOutput();

 

Don't want to spoil too much ;)

Posted

private static void removeRecipe(ItemStack resultItem) {

List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();

for (int i = 0; i < recipes.size(); i++)

{

IRecipe tmpRecipe = recipes.get(i);

if (tmpRecipe instanceof ShapedRecipes) {

ShapedRecipes recipe = (ShapedRecipes)tmpRecipe;

ItemStack recipeResult = recipe.getRecipeOutput();

 

if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {

recipes.remove(i--);

}

}

}

}

 

i copied the it from TFC

 

the code have to be inside your commonproxy and it have to look like this if you want to remove a recipe

 

removeRecipe(new ItemStack(Block.blockGold, 1));

 

you have to make the output too! removeRecipe(new ItemStack(block, size, meta));

if the output is not the same as the in the recipe the function will not work!

Posted

*sigh*

 

Oh well, it doesn't have to be in your common proxy, you can just stick it in a separate class and call it from your postinit/init. (recommend postinit)

  • 4 months later...
Posted

A few helpful lines:


    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();

This gets the recipe list.

 

Strange enough, but that doesn't seem to contain all of the recipes. Tools besides shears, weapons, and several varieties of rails are missing (as well as a bunch more, I'm sure. Those are just the ones I noticed when trying to work this out.) I realized this when I was playing around with trying to override the recipe for an iron pickaxe and the code (a variation on Moritz's theme) never triggered.  So I decided to check just what the list contained:

 

 

                    System.out.println("DEBUG: Starting Recipe Scan");
            ItemStack recipeResult = null;
            List recipes = List CraftingManager.getInstance().getRecipeList();
            	            
            for (int scan = 0; scan < recipes.size(); scan++)
            {
                IRecipe tmpRecipe = (IRecipe) recipes.get(scan);
                if (tmpRecipe instanceof ShapedRecipes)
                {
                    ShapedRecipes recipe = (ShapedRecipes)tmpRecipe;
                    recipeResult = recipe.getRecipeOutput();	                    
                }

                if (tmpRecipe instanceof ShapelessRecipes)
                {
                    ShapelessRecipes recipe = (ShapelessRecipes)tmpRecipe;
                    recipeResult = recipe.getRecipeOutput();	                    
                }
                
                System.out.println("[DEBUG] Result: " + recipeResult);

               

 

 

I looked at CraftingManager.java and RecipesTools.java, and it looks like the tools should be added to the list as well, but they don't come up. I'm not sure if this is a bug or if I'm doing something wrong with .getRecipeList(). If the latter, though feel free to laugh and point out my foolishness. :)

 

 

(NB: As I'm still new here, I wasn't sure of the etiquette and preference between thread necromancy or duplication. I decided to opt for the one that showed I was, in fact, using the search bar.)

 

Posted

xD^^ ill check it how to solve that.

^^"

 

I don't think your code is to blame, since the logic seems to be sound. If you find anything, though, I'll be grateful to hear about it.

Posted

Hi. Sorry for need so much time for solve the problem.

I had so much trouble and i did not came to code.

 

Now a perfect solved. It removes recipes.

public static void removeRecipe(ItemStack par1)
{
     List<IRecipe> recipeList = CraftingManager.getInstance().getRecipeList();
     for(int i=0;i<recipeList.size();i++)
     {
          IRecipe currentRecipe = recipeList.get(i);
          if(currentRecipe instanceof ShapedRecipes)
          {
               ShapedRecipes shape = (ShapedRecipes)currentRecipe;
               ItemStack output = shape.getRecipeOutput();
               if(ItemStack.areItemStacksEqual(par1, output))
               {
                    recipeList.remove(i);
               }
          }

          if(currentRecipe instanceof ShapelessRecipes)
          {
               ShapelessRecipes shapeless = (ShapelessRecipes)currentRecipe;
               ItemStack output = shapeless.getRecipeOutput();
               if(ItemStack.areItemStacksEqual(par1, output))
               {
                     recipeList.remove(i);
               }
          }
     }
}

 

I am current to busy to make more options.

 

I hope it helps^^"

  • 2 weeks later...
Posted

Finally have the chance to play with the code. Still not having any luck, but I think I've nailed down the problem.

 

Certain recipes, including the tools, weapons, bed, workbench, etc... seem to be instances of neither shaped nor shapeless.

 

I modified the inner check of the code like this:

 

if(currentRecipe instanceof ShapedRecipes)
                  {
                       ShapedRecipes shape = (ShapedRecipes)currentRecipe;
                       ItemStack output = shape.getRecipeOutput();
                       if(ItemStack.areItemStacksEqual(par1, output))
                       {                    	   
                            recipeList.remove(i);
                            System.out.println("Removed recipe successfully");
                       } else {
                    	   /*System.out.print(par1);
                    	   System.out.print(" is not eq to ");
                    	   System.out.println(output);
                    	   */
                       }
                  } else if(currentRecipe instanceof ShapelessRecipes)
                  {
                       ShapelessRecipes shapeless = (ShapelessRecipes)currentRecipe;
                       ItemStack output = shapeless.getRecipeOutput();
                       if(ItemStack.areItemStacksEqual(par1, output))
                       {
                             recipeList.remove(i);
                             System.out.println("Removed recipe successfully");
                       }
                  } else {
                	  ItemStack output = currentRecipe.getRecipeOutput();
                	  System.out.print("DEBUG: ");
                	  System.out.print(output);
                	  System.out.println(" is neither shaped nor shapeless");
                  }

 

And my output confirmed my suspicions:

 

 

...

2013-08-24 12:02:12 [iNFO] [sTDOUT] DEBUG: 1xitem.pickaxeWood@0 is neither shaped nor shapeless

2013-08-24 12:02:12 [iNFO] [sTDOUT] DEBUG: 1xitem.pickaxeStone@0 is neither shaped nor shapeless

2013-08-24 12:02:12 [iNFO] [sTDOUT] DEBUG: 1xitem.pickaxeIron@0 is neither shaped nor shapeless

2013-08-24 12:02:12 [iNFO] [sTDOUT] DEBUG: 1xitem.pickaxeDiamond@0 is neither shaped nor shapeless

2013-08-24 12:02:12 [iNFO] [sTDOUT] DEBUG: 1xitem.pickaxeGold@0 is neither shaped nor shapeless

2013-08-24 12:02:12 [iNFO] [sTDOUT] DEBUG: 1xitem.bow@0 is neither shaped nor shapeless

2013-08-24 12:02:12 [iNFO] [sTDOUT] DEBUG: 1xtile.chest@0 is neither shaped nor shapeless

...

 

 

When I change the "debug" conditional at the end to

 

   } else {
           ItemStack output = currentRecipe.getRecipeOutput();
           if (ItemStack.areItemStacksEqual(output, par1)){
                 recipeList.remove(i);             
           }

 

It works!

 

So I guess the moral of the story is that there are recipes that are neither shaped nor shapeless (in terms of "instanceOf", at least).

Posted

I've taken the liberty of trimming down some code based on Moritz's, just to eliminate some duplicated code and to handle the tools and whatnot. I'll leave it here in case it helps someone else. Thanks to Moritz for doing all the heavy lifting on it!

 

 

 

public static void removeRecipe(ItemStack par1)
        {        	
             List<IRecipe> recipeList = CraftingManager.getInstance().getRecipeList();
             for(int i=0;i<recipeList.size();i++)
             {     
            	  ItemStack output;
                  IRecipe currentRecipe = recipeList.get(i);                  
                  if(currentRecipe instanceof ShapedRecipes)
                  {
                       ShapedRecipes shape = (ShapedRecipes)currentRecipe;
                       output = shape.getRecipeOutput();
                  } else if(currentRecipe instanceof ShapelessRecipes) 
                  {
                	  ShapelessRecipes shapeless = (ShapelessRecipes)currentRecipe;
                  	  output = shapeless.getRecipeOutput();
                  } else 
                  {
                	  output = currentRecipe.getRecipeOutput();
                  }
                  if (ItemStack.areItemStacksEqual(output, par1))
                  {
                	  recipeList.remove(i);
                  }
             }
             
        }

Posted

"Instance of" checks are completely useless for this.

By the way this solution

ItemStack output = currentRecipe.getRecipeOutput();
if (ItemStack.areItemStacksEqual(output, par1)){
      recipeList.remove(i);             
}

was already suggested by zedicus 10 posts ago.

The moral of this story is that it is better to understand code and to listen to people. :P

Posted

Iterator<IRecipe> iterator = CraftingManager.getInstance().getRecipeList().iterator();

while(iterator.hasNext()){

        ItemStack r = iterator.next().getRecipeOutput();

        if(r != null && r.itemID == Item.YourItem.itemID) iterator.remove();

}

Posted

I may be wrong, but I don't think you should remove anything through an iterator. I don't even know why java allows this, just to say "beware, the behaviour of the iterator will be undetermined if you alter the collection in any way". So why allow us alter the collection in the first place...? Why did it have to be java, God...?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.