Posted September 25, 201411 yr I want to check if the result of a crafting recipe is a block (planks, gold blocks, etc...) rather than an item. Is this the right way to check? ItemStack result = recipe.getRecipeOutput(); Block result_block = Block.getBlockFromItem(result .getItem()); if (result_block != null) System.out.println("Yup the result is a block"); Likewise if I want to check if the result is an Item (fish, diamond sword, etc...): ItemStack result = recipe.getRecipeOutput(); Item result_item = Item.getItemById(Item.getIdFromItem(result.getItem())); if (result_item != null) System.out.println("Yup the result is an item"); Is this right? I like trains.
September 25, 201411 yr The top one for blocks is right. For items just use ItemStack#getItem directly. BEFORE ASKING FOR HELP READ THE EAQ! I'll help if I can. Apologies if I do something obviously stupid. If you don't know basic Java yet, go and follow these tutorials.
September 25, 201411 yr It may be easier to do ItemStack.getItem() and check if it is an instance of ItemBlock. If it is, it is a block, if not it is an item. if (result.getItem() instanceof ItemBlock) { //Code if the item is a block } else { //Code if the item is an item }
September 25, 201411 yr Author It may be easier to do ItemStack.getItem() and check if it is an instance of ItemBlock. If it is, it is a block, if not it is an item. That's exactly what I want, thanks. I like trains.
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.