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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I personally create registries using DataPackRegistryEvent.NewRegistry. It's pretty powerful as long as you know how to make codecs. In some class, make a registry key like so: public static final ResourceKey<Registry<MyDataType>> MY_REGISTRY = ResourceKey.createRegistryKey(new ResourceLocation(MyMod.MOD_ID, "registry_name")); This will make a registry that holds objects of type "MyDataType". JSON files stored in data/<datapack_namespace>/modid/registryname/ will be parsed and put into this registry. Note that the directory structure has a folder named after your mod inside your datapack directory, so the actual path would look like: data/my_mod/my_mod/registry_name (or if another mod uses your registry: data/their_mod/my_mod/registry_name. To register this registry, subscribe to the DataPackRegistryEvent.NewRegistry event on the MOD event bus and call event.dataPackRegistry() for every registry you have. An example of what I'm doing for my mod (this is in the constructor for the main mod file): IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener((DataPackRegistryEvent.NewRegistry event) -> { event.dataPackRegistry(ModRegistries.INSULATOR_DATA, InsulatorData.CODEC); }); CODEC is a public static field inside the class for the custom data type I am registering. It holds a Codec<InsulatorData> that tells Minecraft how to serialize/deserialize the data. Most of my data so far can be represented by records, so I use RecordCodecBuilder.create() to do this: public static final Codec<InsulatorData> CODEC = RecordCodecBuilder.create(instance -> instance.group( // Yadda yadda ).apply(instance, InsulatorData::new)); What exactly to put here depends on what you're trying to do, so that's up to you. But basically you're just defining a list of codecs that correspond to the parameters of the record (data type). Most primitive data types have records in the Codec class (ex. Codec.INT) that you can use, and other classes like ResourceLocation have their own codecs as a static field (ex. ResourceLocation.CODEC). Hopefully this is what you're looking for, and that this helps.
    • Good days  I finnaly manage to fix and get a working gui from BlockItem and from BlockEntity the next issues i have to fix is this the block Entity model for some reason is moved to the south west  this briefcase model must be centered but is moved to a side, i have nothing weird in the code but this is happening // ########## ########## ########## ########## @Override public RenderShape getRenderShape(BlockState blkstate) {     return RenderShape.MODEL; } the block model is out of place However The hitBox of the block is right in place   ########################################################################################################### This next issue  Mi gui also adds the 5 slots from the player equipment the thing is theres no filter to determine whats can be put in an armor slot and what not      i have this method that draws the slots for the armor, the part i dont get i slike wheres the code that responds when you set an item in a item slot to do checks and allow the item to be set or not  //########## ########## ########## //Draw Player Armor private void addPlayerArmorSlots(Inventory playerInventory) { // 36 this.addSlot(new Slot(playerInventory, 39, 8, 8)); this.addSlot(new Slot(playerInventory, 38, 8, 26)); this.addSlot(new Slot(playerInventory, 37, 8, 44)); this.addSlot(new Slot(playerInventory, 36, 8, 62)); this.addSlot(new Slot(playerInventory, 40, 26, 53)); }   theres must be a method that triggers when you set a itemstack inside an slot and allows to do a check if its a valid item for that slot                                             
    • No like how do I use my new PreperableReloadListener, I know how to set it up now and register it, I just need to know how to use it in other classes.
    • Completely out of the blue my forge loader is lagging, although at 120 fps. Like when I turn it lags, or hit mobs it lags, or run sometimes although staying at 120 fps. I found another person having a similar problem:  But there was no solution I dont think. I tried everything from: 1. Updating my computer 2. Updating/reinstalling forge 3. Testing if allocated memory was problem (if it was low or high or mid nothing changed) 4. Adding various performance mods 5. Deleting most of my profiles if storage was a problem.   Really not sure what to do next or if forge is just broken for ever for me now.  
  • Topics

×
×
  • Create New...

Important Information

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