Jump to content

[1.7.10] Recipe remover mod


Roboguy99

Recommended Posts

I want to make a tiny mod which allows you to put a list of IDs (or probably a new system thanks to 1.7) into a config file and then removes the recipe from the game. I'd also really like this to work with mods. How do I set up a config file and how can I remove both vanilla and mod recipes? Any help is appreciated.

I have no idea what I'm doing.

Link to comment
Share on other sites

package com.draco18s.hardlib;

import java.util.ArrayList;
import java.util.Map;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;

public class RecipesUtil {
public static void RemoveRecipe(Item resultItem, int stacksize, int meta, String modID) {
	ItemStack resultStack = new ItemStack(resultItem, stacksize, meta);
	ItemStack recipeResult = null;
	ArrayList recipes = (ArrayList) 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();
		 }
		 if (ItemStack.areItemStacksEqual(resultStack, recipeResult)) {
			 System.out.println(modID + " Removed Recipe: " + recipes.get(scan) + " -> " + recipeResult);
			 recipes.remove(scan);
		 }
	}
}

public static void RemoveSmelting(Item resultItem, int stacksize, int meta, String modID) {
	ItemStack resultStack = new ItemStack(resultItem, stacksize, meta);
	ItemStack recipeResult = null;
	Map recipes = FurnaceRecipes.smelting().getSmeltingList();
	for (int scan = 0; scan < recipes.size(); scan++) {
		 ItemStack tmpRecipe = (ItemStack) recipes.get(scan);
		 if (ItemStack.areItemStacksEqual(resultStack, recipeResult)) {
			 System.out.println(modID + " Removed Smelting: " + recipes.get(scan) + " -> " + recipeResult);
			 recipes.remove(scan);
		 }
	}
}
}

 

Removes a crafting or smelting recipe that has a result of the given item, stacksize, and metadata.

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

package com.draco18s.hardlib;

import java.util.ArrayList;
import java.util.Map;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;

public class RecipesUtil {
public static void RemoveRecipe(Item resultItem, int stacksize, int meta, String modID) {
	ItemStack resultStack = new ItemStack(resultItem, stacksize, meta);
	ItemStack recipeResult = null;
	ArrayList recipes = (ArrayList) 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();
		 }
		 if (ItemStack.areItemStacksEqual(resultStack, recipeResult)) {
			 System.out.println(modID + " Removed Recipe: " + recipes.get(scan) + " -> " + recipeResult);
			 recipes.remove(scan);
		 }
	}
}

public static void RemoveSmelting(Item resultItem, int stacksize, int meta, String modID) {
	ItemStack resultStack = new ItemStack(resultItem, stacksize, meta);
	ItemStack recipeResult = null;
	Map recipes = FurnaceRecipes.smelting().getSmeltingList();
	for (int scan = 0; scan < recipes.size(); scan++) {
		 ItemStack tmpRecipe = (ItemStack) recipes.get(scan);
		 if (ItemStack.areItemStacksEqual(resultStack, recipeResult)) {
			 System.out.println(modID + " Removed Smelting: " + recipes.get(scan) + " -> " + recipeResult);
			 recipes.remove(scan);
		 }
	}
}
}

 

Removes a crafting or smelting recipe that has a result of the given item, stacksize, and metadata.

 

Ok thanks. I can probably get a config system working if I look into it (completely new to config files at the moment). Can I still use IDs to remove recipes?

I have no idea what I'm doing.

Link to comment
Share on other sites

Ok so what do I use instead now, especially because I want this to be universal and support all mods?

Use textual IDs in the form of "minecraft:stone" / "modid:item".
Also, I'm not copying any code (or did you mean you did?)

It was directed at Draco who just threw a wall of code into his post as an "answer".

 

Ok thanks I should be able to get this to work now, assuming I can figure out how to have an array in a config file (I assume it can't be that hard). Thanks for the help and I'll report back if I need more.

 

EDIT: I can just use a string config and split it into an array.

I have no idea what I'm doing.

Link to comment
Share on other sites

Config files support arrays already.

 

config.get(String category, String key, String[] defaultValues)

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

Config arrays are a little weird.  Essentially yes, but I'd suggest having a config option you don't use that contains 3 values so there's an example of the correct syntax.  I'm pretty sure the whitespace Forge adds isn't required, but it does format nicely.

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

Config arrays are a little weird.  Essentially yes, but I'd suggest having a config option you don't use that contains 3 values so there's an example of the correct syntax.  I'm pretty sure the whitespace Forge adds isn't required, but it does format nicely.

 

Ok I've managed to get the config file working and I have each string from inside of it readily available, and I've got the code to remove the recipe, my problem now is getting the string array from the config file and locating the block associated with it. I'm not really sure how to do this.

I have no idea what I'm doing.

Link to comment
Share on other sites

You should probably only use Items, since Blocks cannot be crafted, only Items.

(Item) Item.itemRegistry.getObject(<name>)

does the same for Items.

 

Ok thanks. I think I've got that working. 1 last thing though (hopefully) - I'm a bit confused with getting the itemstack to compare the stacks. I've got the item using the method you put above but I don't know how to properly compare the stacks. Here is my method:

 

 

 

  private void removeRecipes(String toDelete)
  {
  ArrayList<?> defaultRecipes = (ArrayList<?>) CraftingManager.getInstance().getRecipeList();
  ItemStack recipeResult = null;
  ItemStack	resultStack = new ItemStack((Item)Item.itemRegistry.getObject(toDelete));
  
  for (int scan = 0; scan < defaultRecipes.size(); scan++) 
  {
	 IRecipe tmpRecipe = (IRecipe) defaultRecipes.get(scan);
	 if (tmpRecipe instanceof ShapedRecipes) {
		 ShapedRecipes recipe = (ShapedRecipes)tmpRecipe;
		 recipeResult = recipe.getRecipeOutput();
	 }
	 if (tmpRecipe instanceof ShapelessRecipes) 
	 {
		 ShapelessRecipes recipe = (ShapelessRecipes)tmpRecipe;
		 recipeResult = recipe.getRecipeOutput();
	 }
	 if (ItemStack.areItemStacksEqual(resultStack, recipeResult)) 
	 {
		 System.out.println("Recipe Remover -  Removed Recipe: " + defaultRecipes.get(scan) + " -> " + recipeResult);
		 defaultRecipes.remove(scan);
	 }
 }
  }

 

 

I have no idea what I'm doing.

Link to comment
Share on other sites

ItemStack.areItemStacksEqual(resultStack, recipeResult)

should compare the two stacks.  What seems to be the problem?

 

Keep in mind that you have to set the resultStack stackSize and ItemDamage as well, otherwise it won't see the two stacks as equal (think about crafting torches: the result isn't 1 torch, it's 4!).

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

ItemStack.areItemStacksEqual(resultStack, recipeResult)

should compare the two stacks.  What seems to be the problem?

 

Keep in mind that you have to set the resultStack stackSize and ItemDamage as well, otherwise it won't see the two stacks as equal (think about crafting torches: the result isn't 1 torch, it's 4!).

 

Well my code (I've included the entire class below) outputs nothing and doesn't disable the recipe. I've also placed the config file below.

 

Code:

 

package roboguy99.foodTech;

import java.util.ArrayList;

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.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

@Mod(modid="RecipeRemover", name="Recipe Remover", version="1.1")
public class RecipeRemover
{
  Configuration config;
  private static final String[] DEFAULT_RECIPE_LIST = {"minecraft:stone", "modid:item"};
  
  @EventHandler
  public void preInit(FMLPreInitializationEvent e)
  {
    Configuration config = new Configuration(e.getSuggestedConfigurationFile());
    
    config.load();
    	Property recipeList = config.get(Configuration.CATEGORY_GENERAL, "disabledRecipes", DEFAULT_RECIPE_LIST);
    	String[] recipeListS = recipeList.getStringList();
    	recipeList.comment = "Place the block ID on each separate line";
    config.save();
    
    for(int i = 0; i < recipeListS.length; i++)
    {
    	this.removeRecipes(recipeListS[i]);
    }
  }
  
  private void removeRecipes(String toDelete)
  {
  ArrayList<?> defaultRecipes = (ArrayList<?>) CraftingManager.getInstance().getRecipeList();
  ItemStack recipeResult = null;
  ItemStack	resultStack = new ItemStack((Item) Item.itemRegistry.getObject(toDelete));
  
  resultStack.stackSize = 1;
  resultStack.setItemDamage(0);
   
  for (int scan = 0; scan < defaultRecipes.size(); scan++) 
  {
	 IRecipe tmpRecipe = (IRecipe) defaultRecipes.get(scan);
	 if (tmpRecipe instanceof ShapedRecipes) {
		 ShapedRecipes recipe = (ShapedRecipes)tmpRecipe;
		 recipeResult = recipe.getRecipeOutput();

		 recipeResult.stackSize = 1;
		 recipeResult.setItemDamage(0);
	 }
	 if (tmpRecipe instanceof ShapelessRecipes) 
	 {
		 ShapelessRecipes recipe = (ShapelessRecipes)tmpRecipe;
		 recipeResult = recipe.getRecipeOutput();

		 recipeResult.stackSize = 1;
		 recipeResult.setItemDamage(0);
	 }
	 if (ItemStack.areItemStacksEqual(resultStack, recipeResult)) 
	 {
		 System.out.println("Recipe Remover -  Removed Recipe: " + defaultRecipes.get(scan) + " -> " + recipeResult);
		 defaultRecipes.remove(scan);
	 }
 }
  }
}

 

 

Config:

 

 

# Configuration file

 

general {

    # Place the block ID on each separate line

    S:disabledRecipes <

        minecraft:crafting_table

    >

}

 

 

I have no idea what I'm doing.

Link to comment
Share on other sites

Start adding system.out lines to figure out what the program is doing and narrow down the line that isn't doing what you expect.

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

Start adding system.out lines to figure out what the program is doing and narrow down the line that isn't doing what you expect.

 

Hmmm... resultStack is set to 1xtile.workbench@0, as expected. recipeResult is set to 1xitem.dyePowder@0. That's obviously not correct.

I have no idea what I'm doing.

Link to comment
Share on other sites

At what point in the program are you getting that?  And it is correct for some points in the program: 1xitem.dyePowder@0 is a recipe result in the recipes list.

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

At what point in the program are you getting that?  And it is correct for some points in the program: 1xitem.dyePowder@0 is a recipe result in the recipes list.

 

I put a print line in the beginning of the loop and at the end of every if statement. Only the ones in the loop are visible (either they're so dominant there is no room for the if statement ones or the ifs are returning false). I get spammed with the same result from the loop every time.

At least 1 part is working.

I have no idea what I'm doing.

Link to comment
Share on other sites

I get spammed with the same result from the loop every time.

 

That sounds like your loop isn't....looping.

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

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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