Jump to content

If item exists then add recipes


Recommended Posts

Hi, I'm sorta new to Minecraft modding but am learning the best I can.


My issue is I want to check if an item exists(from other mods), and then if it does to add recipes for it. If it doesn't then it should skip adding the recipes. I've tried what I can but even if I nestle the registerRecipes command under some if statement, it gets checked and Minecraft crashes saying the item doesn't exist.


In pseudo code I'm looking for this, but without crashing the game if the items don't exist.


If item exists


registerRecipes involving item



Don't crash


Can anyone point me in the right direction? I've been Googling and looking at http://linode.narc.ro/forge-javadoc/ for an hour trying to find something to help. I remember finding something a few days ago that checks for items, probably should have bookmarked it.

Link to comment
Share on other sites

It depends on how you're trying to check for an existing item. I think the best way would be to use it's unlocalized name, since IDs can be changed in config files which will result in the item being incorrect. Your method should be something like the following:


public static boolean itemExists(String name)
     for(Item item : Item.itemsList)
    	if(item != null)
    		if(item.getUnlocalizedName() == name)
    			return true;
    return false;


This will check all of the available items, and if the item's unloc'd name is equal to the passed String, it will tell that the item exists and break out of the method. For example, if you want to check if the Item called diamond exists, you'd do this:


itemExists("item.diamond") and it will return true once it reaches the first Item that has that. For blocks, you'll need a new method that runs through the blocks list instead of items list, and instead of "item.name" it is "tile.name". I'm sure you can figure it out from what I've already given you. You'll need to know the unlocalized names of the mod items you're looking for, but this should help you.

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.

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 figured out what was wrong ... you can spot it pretty quick most likely: { "type": "minecraft:smelting", "ingredient": { "item": "minecraft:gold_nugget_ore" }, "result": "minecraft:gold_nugget", "experience": 0.25, "cookingtime": 150 }   ... so, after changing `minecraft` to `foundations` for all the custom items and all the recipes work. Well that's what copy/paste will get you. One last question about recipes, though. What does the following json key/value do in the game? "group": "copper_ingot"  
    • # Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # #     rhino.acme.com          # source server #     x.acme.com              # x client host # localhost name resolution is handled within DNS itself. #       localhost #    ::1             localhost ### apps.corel.com ### mc.corel.com origin-mc.corel.com ### iws.corel.com
    • Is there a way to create a custom map marker for a custom structure/biome (same as a vanilla mansion)?
    • I’ve scrounged the Internet for solutions and found absolutely nothing that has worked for me I have posted my code in a GitHub Repository. I bet the culprit is somewhere in the Container or TileEntity classes (Furnace packages are in blocks/coke_furnace or blocks/foundry) PS I know I’m on 1.12.2 and that it’s not supported I don’t want to update my game or my code. Lol It’s my favorite version and the most widely modded. I don’t plan to release the mod, I’m just customizing my game to my will. I’ll send it to friends but that’s it.
    • 1.19.2 With forge 43.2.4   https://mclo.gs/zCAx1MG      
  • Topics

  • Create New...

Important Information

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