Posted July 6, 201312 yr 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 } else 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.
July 6, 201312 yr can't you just loop trough all items and if != null check if item.name == whateverTheNameIs then add the recipe? If you guys dont get it.. then well ya.. try harder...
July 6, 201312 yr 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.
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.