Posted November 2, 201510 yr Hi ! I wanted to create a type of recipe that damages a tool you put in the crafting inventory. It's based on ShapelessRecipes. The tool should remain after crafting in the left part, but with -1 damage. For example, a sword and a zombie head gives rotten meat and the sword is damaged. The matches() works, but the getRemainingItems() has a problem. public ItemStack[] getRemainingItems(InventoryCrafting inv) { ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()]; for (int i = 0; i < aitemstack.length; ++i) { ItemStack itemstack = inv.getStackInSlot(i); if (isTool(itemstack)) itemstack.attemptDamageItem(1, new Random()); else aitemstack[i] = net.minecraftforge.common.ForgeHooks .getContainerItem(itemstack); } return aitemstack; } It crashes when trying to take the result. I know the error is in the lines if (isTool(itemstack)) itemstack.attemptDamageItem(1, new Random()); But I haven't managed to fix it. I think it has something to do with the tool being "consumed" along the recipeItems during the process, but the process itself is fairly magic. I don't know how the games know which items it should consume, there is no explicit method for that, as the getRemainingItems() just returns everything from the left area (except the tool in my method of course but it doesn't work).
November 2, 201510 yr Post the isTool method and the crash report. I'm guessing you're calling ItemStack#getItem on a null value. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
November 2, 201510 yr Author The method works when used in matches() but I think you're right, it's probably called on null in getRemainingItems() because the tool is probably already consumed but I don't know how to avoid it. I can avoid the crash by not calling the function when null (easy) but then I don't receive the tool at all, it's just plainly consume like the recipeItems. isTool() method : protected boolean isTool(ItemStack itemstack) { return ToolClass.isInstance(itemstack.getItem()); } Crash report : http://hastebin.com/tefukadada.vhdl I think my actual problem can therefore be resumed by : how to NOT consume an item while still keeping it as important in the matches() method.
November 2, 201510 yr The actual exception that caused the crash is being hidden by an exception thrown from the crash report code. This is due to Minecraft being rebuilt without debug information by ForgeGradle and has been fixed in ForgeGradle 2.0.2. I'd suggest updating the plugin in your build.gradle, re-running setupDecompWorkspace , refreshing your IDE project and posting the new crash report. Edit: The itemstack argument of isTool will be null if there was no item in the slot. Check that it's not null before calling ItemStack#getItem on it. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
November 2, 201510 yr Author Yeah it doesn't crash anymore but there is nothing left in the left area. The condition is never satisfied because everything is consumed in the crafting inventory and I don't know how to change that.
November 2, 201510 yr In getRemainingItems , you're overwriting the damaged tool with the default container item returned by ForgeHooks.getContainerItem . This will be null unless the item has a container item specified. You should only call ForgeHooks.getContainerItem when the item isn't a tool. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
November 2, 201510 yr Author After a few bugfixes, it seems to work, thank you. I have now a generic class allowing me to create shapeless recipes that uses whatever tool I want. Fantastic.
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.