Posted June 15, 20178 yr So far, I have created an item that takes damage in a crafting table, but it doesn't get destroyed when all of the durability is used, and also crashes the game when it is used after shift-clicking an amount of items over the durability. Here is the Item class: Spoiler package items; import com.Cmonster.OreMod.Reference; import com.Cmonster.OreMod.creativetabs.TabElements; import init.ModItems; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class ItemOxygen_extractor extends Item { public ItemOxygen_extractor() { setUnlocalizedName(Reference.OreModItems.OXYGEN_EXTRACTOR.getUnlocalizedName()); setRegistryName(Reference.OreModItems.OXYGEN_EXTRACTOR.getRegistryName()); setCreativeTab(TabElements.tab_elements); maxStackSize = 1; setMaxDamage(10); setNoRepair(); } @Override public boolean hasContainerItem(ItemStack stack) { return true; } @Override public ItemStack getContainerItem(ItemStack itemStack) { if (itemStack.getMaxDamage() == itemStack.getItemDamage()) { return (ItemStack) null; } else { ItemStack newItemStack = itemStack.copy(); newItemStack.setItemDamage(itemStack.getItemDamage() + 1); return newItemStack; } } } And here is the crafting recipe code: GameRegistry.addShapelessRecipe(new ItemStack(ModItems.lithium_carbonate), ModItems.lithium_ingot, Items.COAL, new ItemStack(ModItems.oxygen_extractor, 1, OreDictionary.WILDCARD_VALUE)); Coal is used as a placeholder here.
June 16, 20178 yr you need to return ItemStack.EMPTY rather than null. Parameterizing a null still gives a null variable, and looking at the ForgeHooks class (and the Shaped Recipe class, but this is more irrelevant), the passed in ItemStack from the getContainerItem method calls !stack.isEmpty(), which if the passed in stack is null, can't be done. Edited June 16, 20178 yr by draganz
June 17, 20178 yr Author Thanks for the answers It works, but after the first use, I can't use it again. Code: Spoiler package items; import com.Cmonster.OreMod.Reference; import com.Cmonster.OreMod.creativetabs.TabElements; import init.ModItems; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class ItemOxygen_extractor extends Item { public ItemOxygen_extractor() { setUnlocalizedName(Reference.OreModItems.OXYGEN_EXTRACTOR.getUnlocalizedName()); setRegistryName(Reference.OreModItems.OXYGEN_EXTRACTOR.getRegistryName()); setCreativeTab(TabElements.tab_elements); maxStackSize = 1; setMaxDamage(10); setNoRepair(); } @Override public boolean hasContainerItem(ItemStack stack) { return true; } @Override public ItemStack getContainerItem(ItemStack itemStack) { if (itemStack.getMaxDamage() == itemStack.getItemDamage()) { return ItemStack.EMPTY; } else { ItemStack newItemStack = itemStack.copy(); newItemStack.setItemDamage(itemStack.getItemDamage() + 1); return newItemStack; } } } Edited June 17, 20178 yr by Cmonster
June 17, 20178 yr Author After I use the item in the craftin table the first time, it takes one durability value, but after I try to use the same item, the recipe does not work. EDIT: Mistake on my part, I needed to save the code Edited June 17, 20178 yr by Cmonster
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.