Jump to content

(Solved / Headdesk) 1.12.2] Can't remove recipes added via addShapeless


EM3R50N

Recommended Posts

I know custom recipes went to JSON format quite a while ago but when I tried to start moving to that today I found out my recipes seem stuck in the mod/game and I can't clear them?  All of them were added w/one of the addShapeless() methods from the CraftingHelper class below. I've tried cleaning my project, moving to updated version of forge and few other things but even though my addShapeless() recipes are commented out they're still in the game when I debug. Anyone know how to remove these recipes? It is driving me INSANE...

 

Example of one my recipes

CraftingHelper.addShapeless(event, new ItemStack(Items.APPLE,0),new Object[]{Items.COAL});

 

CraftingHelper class  w/the addShapeless method(s):

package com.me.mymod.util;

import java.util.List;
import com.me.mymod.Reference;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.stats.RecipeBook;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.OreIngredient;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import net.minecraftforge.registries.IForgeRegistry;

public class CraftingHelper {

	private static int j = 0;
	private static final String MODID = Reference.MOD_ID;// Mod.MODID;
	private static final String MODNAME = Reference.MOD_NAME; // Mod.MODNAME;

	public static void addRecipe(RegistryEvent.Register<IRecipe> event, int j, IRecipe rec) {
		final IForgeRegistry<IRecipe> registry = event.getRegistry();
		
	    if(rec.getRegistryName() == null)
	    	registry.register(rec.setRegistryName(new ResourceLocation(MODID, "recipes" + j)));
	    else registry.register(rec);
	}

	/*
	 * This adds the recipe to the list of crafting recipes.  Cares about names.
	 */
	public static void addRecipe(RegistryEvent.Register<IRecipe> event, String name, IRecipe rec) {
		
		final IForgeRegistry<IRecipe> registry = event.getRegistry();
        	
	    if(rec.getRegistryName() == null)
	    	registry.register(rec.setRegistryName(new ResourceLocation(MODID, name)));
	    else registry.register(rec);
	}

	/*
	 * This adds a shaped recipe to the list of crafting recipes, using the forge format.
	 */
	public static void addOldShaped(RegistryEvent.Register<IRecipe> event, ItemStack output, Object... input) {
		addRecipe(event, j++, new ShapedOreRecipe(new ResourceLocation(MODID, "recipes" + j), output, input));
	}

	/*
	 * This adds a shaped recipe to the list of crafting recipes, using the forge format, with a custom group.
	 */
	public static void addOldShaped(RegistryEvent.Register<IRecipe> event, String group, ItemStack output, Object... input) {
		addRecipe(event, j++, new ShapedOreRecipe(new ResourceLocation(MODID, group), output, input));
	}
	
	   /*
     * This adds a shaped recipe to the list of crafting recipes, using the forge format, with a custom group.
     */
    public static void addOldShaped(RegistryEvent.Register<IRecipe> event, String name, String group, ItemStack output, Object... input) {
        addRecipe(event, j++, new ShapedOreRecipe(new ResourceLocation(MODID, group), output, input).setRegistryName(MODID, name));
    }

	/*
	 * This adds a shapeless recipe to the list of crafting recipes, using the forge format.
	 */
	public static void addOldShapeless(RegistryEvent.Register<IRecipe> event, ItemStack output, Object... input) {
		addRecipe(event, j++, new ShapelessOreRecipe(new ResourceLocation(MODID, "recipes" + j), output, input));
	}

	/*
	 * This adds a shapeless recipe to the list of crafting recipes, using the forge format, with a custom group.
	 */
	public static void addOldShapeless(RegistryEvent.Register<IRecipe> event, String group, ItemStack output, Object... input) {
		addRecipe(event, j++, new ShapelessOreRecipe(new ResourceLocation(MODID, group), output, input));
	}

	/*
	 * Adds a shapeless recipe with X output using an array of inputs. Use Strings for OreDictionary support. This array is not ordered.
	 */
	public static void addShapeless(RegistryEvent.Register<IRecipe> event, ItemStack output, Object... inputs) {
		addRecipe(event, j++, new ShapelessRecipes(MODID + ":" + j, output, createInput(inputs)));
	}
	
	public static void addShapeless(int outputStackCount, RegistryEvent.Register<IRecipe> event, ItemStack output, Object... inputs) {
		output.setCount(outputStackCount);
		addRecipe(event, j++, new ShapelessRecipes(MODID + ":" + j, output, createInput(inputs)));
	}	

	public static void addShapeless(RegistryEvent.Register<IRecipe> event, Item output, Object... inputs) {
		addShapeless(event, new ItemStack(output), inputs);
	}

	public static void addShapeless(RegistryEvent.Register<IRecipe> event, Block output, Object... inputs) {
		addShapeless(event, new ItemStack(output), inputs);
	}

	/*
	 * Adds a shapeless recipe with X output using an array of inputs. Use Strings for OreDictionary support. This array is not ordered.  This has a custom group.
	 */
	public static void addShapeless(RegistryEvent.Register<IRecipe> event, String group, ItemStack output, Object... inputs) {
		addRecipe(event, j++, new ShapelessRecipes(MODID + ":" + group, output, createInput(inputs)));
	}

	public static void addShapeless(RegistryEvent.Register<IRecipe> event, String group, Item output, Object... inputs) {
		addShapeless(event, group, new ItemStack(output), inputs);
	}

	public static void addShapeless(RegistryEvent.Register<IRecipe> event, String group, Block output, Object... inputs) {
		addShapeless(event, group, new ItemStack(output), inputs);
	}

	/*
	 * Adds a shapeless recipe with X output on a crafting grid that is W x H, using an array of inputs.  Use null for nothing, use Strings for OreDictionary support, this array must have a length of width * height.
	 * This array is ordered, and items must follow from left to right, top to bottom of the crafting grid.
	 */
	public static void addShaped(RegistryEvent.Register<IRecipe> event, ItemStack output, int width, int height, Object... input) {
		addRecipe(event, j++, genShaped(output, width, height, input));
	}

	public static void addShaped(RegistryEvent.Register<IRecipe> event, Item output, int width, int height, Object... input) {
		addShaped(event, new ItemStack(output), width, height, input);
	}

	public static void addShaped(RegistryEvent.Register<IRecipe> event, Block output, int width, int height, Object... input) {
		addShaped(event, new ItemStack(output), width, height, input);
	}

	/*
	 * Adds a shapeless recipe with X output on a crafting grid that is W x H, using an array of inputs.  Use null for nothing, use Strings for OreDictionary support, this array must have a length of width * height.
	 * This array is ordered, and items must follow from left to right, top to bottom of the crafting grid. This has a custom group.
	 */
	public static void addShaped(RegistryEvent.Register<IRecipe> event, String group, ItemStack output, int width, int height, Object... input) {
		addRecipe(event, j++, genShaped(MODID + ":" + group, output, width, height, input));
	}

	public static void addShaped(RegistryEvent.Register<IRecipe> event, String group, Item output, int width, int height, Object... input) {
		addShaped(event, group, new ItemStack(output), width, height, input);
	}

	public static void addShaped(RegistryEvent.Register<IRecipe> event, String group, Block output, int width, int height, Object... input) {
		addShaped(event, group, new ItemStack(output), width, height, input);
	}

	public static ShapedRecipes genShaped(ItemStack output, int l, int w, Object[] input) {
		if (input[0] instanceof Object[])
			input = (Object[]) input[0];
		if (l * w != input.length)
			throw new UnsupportedOperationException(
					"Attempted to add invalid shaped recipe.  Complain to the author of  " + MODNAME);
		NonNullList<Ingredient> inputL = NonNullList.create();
		for (int i = 0; i < input.length; i++) {
			Object k = input[i];
			if (k instanceof String) {
				inputL.add(i, new OreIngredient((String) k));
			} else if (k instanceof ItemStack && !((ItemStack) k).isEmpty()) {
				inputL.add(i, Ingredient.fromStacks((ItemStack) k));
			} else if (k instanceof Item) {
				inputL.add(i, Ingredient.fromStacks(new ItemStack((Item) k)));
			} else if (k instanceof Block) {
				inputL.add(i, Ingredient.fromStacks(new ItemStack((Block) k)));
			} else {
				inputL.add(i, Ingredient.EMPTY);
			}
		}

		return new ShapedRecipes(MODID + ":" + j, l, w, inputL, output);
	}

	public static ShapedRecipes genShaped(String group, ItemStack output, int l, int w, Object[] input) {
		if(input[0] instanceof List)
			input = ((List<?>) input[0]).toArray();
		else if (input[0] instanceof Object[])
			input = (Object[]) input[0];
		if (l * w != input.length)
			throw new UnsupportedOperationException(
					"Attempted to add invalid shaped recipe.  Complain to the author of  " + MODNAME);
		NonNullList<Ingredient> inputL = NonNullList.create();
		for (int i = 0; i < input.length; i++) {
			Object k = input[i];
			if (k instanceof String) {
				inputL.add(i, new OreIngredient((String) k));
			} else if (k instanceof ItemStack && !((ItemStack) k).isEmpty()) {
				inputL.add(i, Ingredient.fromStacks((ItemStack) k));
			} else if (k instanceof Item) {
				inputL.add(i, Ingredient.fromStacks(new ItemStack((Item) k)));
			} else if (k instanceof Block) {
				inputL.add(i, Ingredient.fromStacks(new ItemStack((Block) k)));
			} else {
				inputL.add(i, Ingredient.EMPTY);
			}
		}

		return new ShapedRecipes(group, l, w, inputL, output);
	}

	public static NonNullList<Ingredient> createInput(Object[] input) {
		if(input[0] instanceof List)
			input = ((List<?>) input[0]).toArray();
		else if (input[0] instanceof Object[])
			input = (Object[]) input[0];
		NonNullList<Ingredient> inputL = NonNullList.create();
		for (int i = 0; i < input.length; i++) {
			Object k = input[i];
			if (k instanceof String) {
				inputL.add(i, new OreIngredient((String) k));
			} else if (k instanceof ItemStack) {
				inputL.add(i, Ingredient.fromStacks((ItemStack) k));
			} else if (k instanceof Item) {
				inputL.add(i, Ingredient.fromStacks(new ItemStack((Item) k)));
			} else if (k instanceof Block) {
				inputL.add(i, Ingredient.fromStacks(new ItemStack((Block) k)));
			} else {
				throw new UnsupportedOperationException(
						"Attempted to add invalid shapeless recipe.  Complain to the author of " + MODNAME);
			}
		}
		return inputL;
	}
}

 

Edited by EM3R50N
Link to comment
Share on other sites

11 minutes ago, EM3R50N said:

my recipes seem stuck in the mod/game and I can't clear them?

Huh? What?

11 minutes ago, EM3R50N said:

Anyone know how to remove these recipes?

Have you tried....deleting the code?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I've had them all commented out the whole time I've been trying to get them out of my mod. All of them look like this right now

// CraftingHelper.addShapeless(event, new ItemStack(Items.APPLE,0),new Object[]{Items.COAL});
// CraftingHelper.addShapeless(event, new ItemStack(Items.IRON_INGOT,0),new Object[]{Items.COAL});
// CraftingHelper.addShapeless(event, new ItemStack(Items.BONE_MEAL,0),new Object[]{Items.COAL});

 

Not sure if you're joking but I'm so desperate I'll try delete the commented out lines too!... but assuming that won't change anything.

Link to comment
Share on other sites

Yeah deleting the commented out lines didn't change anything (again I'm desperate - realize that's crazy person logic). 

I guess I'm paying for my sins of not moving to JSON recipe format back when it first came out. 

 

If anyone know more about the  IForgeRegistry and how that is handled and/or if it can be cleaned out/reset somehow please chime in? I obviously know very little about it right now but am assuming that's where my recipes are stuck because all my addShapeless() calls have been going through this

	public static void addRecipe(RegistryEvent.Register<IRecipe> event, String name, IRecipe rec) {
		
		final IForgeRegistry<IRecipe> registry = event.getRegistry();
        	
	    if(rec.getRegistryName() == null)
	    	registry.register(rec.setRegistryName(new ResourceLocation(MODID, name)));
	    else registry.register(rec);
	}

 

Link to comment
Share on other sites

If your code doesn’t exist but it’s still getting run... make sure your IDE is correctly launching your project and that your edits are getting saved. 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Just realized a version of the recipe I was trying to remove was ALREADY IN VANILLA MINECRAFT... and that was what I was interpreting as a sign my recipes weren't removed yet.

/headdesk x 100

 

God help me.

 

@Draco18s @Cadiboo Thanks for trying to help/replying guys. Sorry for distraction


 

 

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.