Jump to content

[1.11.2][solved] Removal from Creative tabs + Recipe


Recommended Posts

Posted (edited)

Just as the title says, I'm looking for a way to remove vanila items from creative tabs and also to remove their recipes. Back in 1.7.10 I had at least the recipe part working but when I updated it to 1.11.2 it stopped working entirely.

I can't really see the issue as to why it shouldn't work as it was a very minor adjustment code wise.

1.7.10 class:

	public class RecipeHandler {
    
    public static void removeRecipes(ItemStack stack)
    {    
        ItemStack resultItem = stack;
        resultItem.stackSize = 1;
	        List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
	        for (int i = 0; i < recipes.size(); i++)
        {
            IRecipe tmpRecipe = recipes.get(i);
	            ItemStack recipeResult = tmpRecipe.getRecipeOutput();
            if(recipeResult != null) 
            {
                recipeResult.stackSize = 1;
            }
	            if (ItemStack.areItemStacksEqual(resultItem, recipeResult))
            {
                System.out.println(Reference.MOD_NAME + " || Removed Recipe: " +recipes.get(i)+ " <--> " +recipeResult);
                recipes.remove(i--);
            }
        }
    }
}
Edited by nexusrightsi
Posted (edited)

All that had do be done was change both

resultItem.stackSize = 1;

and

recipeResult.stackSize = 1;

to this:

.setCount(1);

Before anyone asks, yes I am most certainly calling the method that removes the recipes from my post init. I posted this in a new reply since it wouldn't allowe me to post this in the original post...

Edited by nexusrightsi
Posted

Here is my code using an Iterator

	private void removeCraftRecipe(ItemStack stack) {
		Iterator recipes =  CraftingManager.getInstance().getRecipeList().iterator();
		while (recipes.hasNext()) {
			ItemStack output = ((IRecipe) recipes.next()).getRecipeOutput();
			if(output != null && output.getItem() != null) {
				if(output.isItemEqual(stack)) {
					recipes.remove();
				}
			}
		}
	}

 

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Posted
	private void removeCraftRecipe(ItemStack stack) {
		Iterator<IRecipe> recipes =  CraftingManager.getInstance().getRecipeList().iterator();
		while (recipes.hasNext()) {
			ItemStack output = ((IRecipe) recipes.next()).getRecipeOutput();
			if(output != null && output.getItem() != null) {
				if(output.isItemEqual(stack)) {
					recipes.remove();
				}
			}
		}
	}

 

1 minute ago, diesieben07 said:

Ewww, raw types...

Here you go...

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Posted

OK SENSEI

	private void removeCraftRecipe(ItemStack stack) {
		Iterator<IRecipe> recipes =  CraftingManager.getInstance().getRecipeList().iterator();
		while (recipes.hasNext()) {
			ItemStack output = recipes.next().getRecipeOutput();
			if(output != null && output.getItem() != null) {
				if(output.isItemEqual(stack)) {
					recipes.remove();
				}
			}
		}
	}

 

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Posted

This is the furthest I'll go

	private void removeCraftRecipe(ItemStack stack) {
		Iterator<IRecipe> recipes = CraftingManager.getInstance().getRecipeList().iterator();
		while (recipes.hasNext()) {
			ItemStack output = recipes.next().getRecipeOutput();
			if (output.isItemEqual(stack)) {
				recipes.remove();
			}
		}
	}

 

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Posted

Diesieben please, your last comment made me facepalm so hard xD Why the frig did I want this code... when its just as easy as 

CraftingManager.getInstance().getRecipeList().removeIf(stack -> stack.getItem() == Items.STICK);

You sir, ruined my day! xD nah just kidding. Thank you for the easy solution though, less code is always better and if I can slim it down to a mere line who am I to moan!

Posted
8 minutes ago, diesieben07 said:

Well, removeIf (and lambdas) are a pretty new feature, available since Java 8. So nothing wrong with not knowing about them yet.

Quite unfortunate that neither solutions work though, the recipe is still there for some reason...

Posted
8 minutes ago, diesieben07 said:

Post updated code.

Its pretty much the solution koekkie came up, scratch that. Its just a copy and paste. 

	public class RecipeHandler {
    
    public static void removeRecipes()
    {
        /*
         * Items
         */
        removeRecipes(new ItemStack(Items.DIAMOND_HOE));
        removeRecipes(new ItemStack(Items.IRON_HOE));
        removeRecipes(new ItemStack(Items.GOLDEN_HOE));
        removeRecipes(new ItemStack(Items.STONE_HOE));
        //recipe.removeRecipes(new ItemStack(Items.DYE, 0, 15));
        
        /*
         * Blocks
         */
        //recipe.RemoveRecipe(new ItemStack(Block.workbench));
    }
	    private static void removeRecipes(ItemStack stack)
    {    
        Iterator<IRecipe> recipes = CraftingManager.getInstance().getRecipeList().iterator();
        while (recipes.hasNext()) 
        {
            ItemStack output = recipes.next().getRecipeOutput();
            if (output.isItemEqual(stack)) 
            {
                recipes.remove();
            }
        }
    }

 

Posted
4 minutes ago, diesieben07 said:

That should work, although I am not sure why you would do this in your proxy.

Is the code getting called? Does it get to the part where recipes are removed?

I have no clue what is going on right now... I switched the call of removeRecipes() from the proxy post init to the main class post init not that that should matter in the slightest... However the method isn't even being called...

Posted

	@Mod(modid = Reference.MOD_ID, version = Reference.VERSION)
public class NagaCore
{    
    @Instance(Reference.MOD_ID)
    public static NagaCore instance;
	    /*
     * Sets the proxies up for usage.
     */
    @SidedProxy(
            clientSide = Reference.CLIENT_PROXY_LOCATION,
            serverSide = Reference.COMMON_PROXY_LOCATION)
    public static CommonProxy proxy;
	    public static CreativeTabs tabBlocks = new CreativeTabNFOBlocks("nfo_blocks");
    public static CreativeTabs tabItems = new CreativeTabNFOItems("nfo_items");
	    /*
     * This loads in all the given methods upon the start of the game, commonly used for important systems such as packets, handlers and other
     * important stuff.
     * take note of the hierarchy in which order everything is getting loaded into the game.
     */
    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
        proxy.preInit();
        BlockHandler.BlockInit();
        ItemHandler.ItemInit();
        ItemHandler.registerRecipes();
        ItemHandler.registerOreItems();
    }
	    /*
     * This loads in all the given methods upon the start of the game, commonly used for blocks, items and varius other things.
     * take note of the hierarchy in which order everything is getting loaded into the game.
     */
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
        proxy.init();
    }
	    /*
     * This loads in all the given methods upon the start of the game, commonly used for Gui's and stuff that are allowed to be initialized
     * at the very end of the minecraft boot up.
     * take note of the hierarchy in which order everything is getting loaded into the game.
     */
    @EventHandler
    public void postInit(FMLPostInitializationEvent event)
    {
        proxy.postInit();
        RecipeHandler.removeRecipes();
    }
}

I try to keep this as clean as possible that is why I try to move everything into the proxy but sadly i can't do that for the items and blocks. They will crash the game when I do that :P 

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.