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 Website -ย Cadiboo.github.io

My Mods -ย Cadiboo.github.io/projects

My Tutorials -ย Cadiboo.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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This has been released asย 49.0.49.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. ๐Ÿ“ˆ Skills: RPG-style skill system that enhances your gaming experience! ๐ŸŽฎ Leaderboards: Compete and shine! Top players are rewarded weekly! ๐Ÿ† Random Teleporter: Travel instantly across different worlds with a click! ๐ŸŒ Custom World Generation: Beautifully generated world. ๐ŸŒ Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. ๐Ÿฐ Kits: Unlock ranks and gain access to various kits. ๐Ÿ› ๏ธ Fishing Tournament: Compete in a friendly fishing tournament! ๐ŸŽฃ Chat Games: Enjoy games right within the chat! ๐ŸŽฒ Minions: Get some help from your loyal minions. ๐Ÿ‘ฅ Piรฑata Party: Enjoy a festive party with Piรฑatas! ๐ŸŽ‰ Quests: Over 1000 quests that you can complete! ๐Ÿ“œ Bounty Hunter: Set a bounty on a player's head. ๐Ÿ’ฐ Tags: Displayed on nametags, in the tab list, and in chat. ๐Ÿท๏ธ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! ๐ŸŸข Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. ๐Ÿ”ฒโœจ[ Player Warp: Set your own warp points for other players to teleport to. ๐ŸŒŸ Display Shop: Create your own shop and sell to other players! ๐Ÿ›’ Item Skins: Customize your items with unique skins. ๐ŸŽจ Pets: Your cute loyal companion to follow you wherever you go! ๐Ÿพ Cosmetics: Enhance the look of your character with beautiful cosmetics! ๐Ÿ’„ XP-Bottle: Store your exp safely in a bottle for later use! ๐Ÿถ Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! ๐Ÿ“ฆ Glowing: Stand out from other players with a colorful glow! โœจ Player Particles: Over 100 unique particle effects to show off. ๐ŸŽ‡ Portable Inventories: Over virtual inventories with ease. ๐Ÿงณ And a lot more! Become part of our growing community today! Discord:ย https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working ย  I am not familiar with Linux - check for similar/related issues ย 
    • Create a new instance and start with Embeddium/Oculus and Valkyrien Skies Try different builds of Embeddium/Valkyrien Skies until you find a working combination - then add the rest of your mods one by one or in groups
  • Topics

×
×
  • Create New...

Important Information

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