Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

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


nexusrightsi
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

	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

Link to comment
Share on other sites

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();
				}
			}
		}
	}

 

  • Like 1

Classes: 94

Lines of code: 12173

Other files: 206

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

Link to comment
Share on other sites

Oh and in 1.11.x and onward ItemStacks can never be null. And the Item in an ItemStack has never been null either, so those two checks can go as well...

 

And now that we've simplified it down so much, why not do:

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

It's up to you. It's not wrong to use an Iterator, it's just nice to have the code concise and without all the boilerplate of iterating. Being able to say "hey, just remove anything that matches this description" instead of saying "ok, give me the next element, does it match? No, ok next element" is very valuable for the readability of your code.

Link to comment
Share on other sites

Just now, nexusrightsi said:

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!

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

Link to comment
Share on other sites

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();
            }
        }
    }

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

	@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 

Link to comment
Share on other sites

2 hours ago, nexusrightsi said:

Okay... that was random, without me changing absolutely anything it decided to work... my code is being haunted, I need an exorcist to cleanse my project please!

Someone, get an exorcist!

My code is haunted too. O.o

YouTube:

https://www.youtube.com/channel/UCaK5oRw4yd7PurBWww9tVhA

Kuribo64 (where I am most active):

http://kuribo64.net/board/profile.php?id=1423

 

Thanks for your answer!

 

Current projects:

 

3D Geometry Dash: 13%

Terracraft (MC Mod): 8%

New Super Kaizo Bros DS: 100% (no download for now :'( )

New Super Kaizo Bros. Wii: 12%

Super Mario Galaxy 1.5: 96%

New Super Mario Bros Galaxy: 85%

Kerbal Space Program Advance: 47%

MC CREATE: 20%

Mystery Projects: 10%, 40%, 13%, and 94%

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
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.

 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.