Jump to content

[1.7.2] Cannot Remove Furnace Recipes


nokel81

Recommended Posts

FurnaceRecipes.smelting().getSmeltingList().remove(Blocks.iron_ore);

 

This is how it was in 1.6.4 but then you had to put ".blockID" after iron_ore but now that IDs are not used in code this does not work anymore, if this not how you remove recipes anymore?

Link to comment
Share on other sites

[Okay, while I was typing this, deiseiben07 posted.]

 

FurnaceRecipes.smelting().getSmeltingList().remove(new ItemStack(Blocks.iron_ore)) will not work.

 

The reason is simple if you understand hashmaps. The key is looked up in an array of hash buckets indexed by the hashCode() return value. Then, if the key is not equals(Object o) to the one to remove/add/get the object looks down to list or hash bucket and checks equals() again (some do a rehash, but not this implementation).

 

Now to the actual reason it fails. No two new ItemStacks will generate the same hash (under normal circumstances.) So, every ItemStack will not match an existing key, and since ItemStack does not implement either hashCode() or equals(o), the Object (superclass) methods are used (they amount to the address of the instance as hashCode). If you put an ItemStack in the map, it stays but will never match anything but that exact reference, ever.

 

You therefore must iterate through the recipes, check with ItemStack.areItemStacksEqual(s1, s2) -- yes, really slow... but the only way right now.

 

Link to comment
Share on other sites

This is what I did for removing crafting recipes

static void removeRecipesWithResult(ItemStack resultItem) {
	ArrayList recipes = (ArrayList) CraftingManager.getInstance().getRecipeList();

	for (int scan = 0; scan < recipes.size(); scan++) {
		IRecipe tmpRecipe = (IRecipe) recipes.get(scan);
		if (ItemStack.areItemStacksEqual(resultItem, tmpRecipe.getRecipeOutput())) {
			recipes.remove(scan);
		}//if
	}//for
}//removeRecipesWithResult

 

This is what I am trying to do for removing furnace recipes, is there a furnace equivalent to IRecipe?

 

static void removeFurnaceRecipeWithResult(ItemStack resultItem) {
	java.util.Map recipes = FurnaceRecipes.smelting().getSmeltingList();

	for (int scan = 0; scan < recipes.size(); scan++) {
		if (ItemStack.areItemStacksEqual(resultItem, [b][/b]) {
			recipes.remove(scan);
		}
	}
}//removeFurnaceRecipeWithResult

Link to comment
Share on other sites

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.