mission712 Posted May 9, 2014 Posted May 9, 2014 Hello, I am developing a mod that has an item called a "knife" which, when I use it on the crafting table, should not get used on the crafting table but get 1 damage and get back into the player's inventory. Instead when I use the recipe the knife gets consumed with the other ingredient. Do you know how to fix this? My codes: ItemKnife.java: package notgonna.getmah.modname; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class ItemKnife extends Item { public ItemKnife() { super(); this.setCreativeTab(CreativeTabs.tabTools); this.maxStackSize = 1; this.setMaxDamage(128); } @Override public boolean doesContainerItemLeaveCraftingGrid(ItemStack itemstack) { return true; } @Override public ItemStack getContainerItem(ItemStack itemStack) { ItemStack cStack = itemStack.copy(); cStack.setItemDamage(cStack.getItemDamage() + 1); cStack.stackSize = 1; return cStack; } } MainClass.java: @EventHandler public void preinit(FMLPreInitializationEvent event) { //Item attributes and registry //Attributes of the knife knife = new ItemKnife().setTextureName(MainClass.modid + ":knife").setUnlocalizedName("knife"); GameRegistry.registerItem(knife, "no_knife"); appleIceCream = new ItemFood(4, 0.5F, false).setTextureName(MainClass.modid + ":appleIceCream").setUnlocalizedName("appleIceCream"); GameRegistry.registerItem(appleIceCream, "nope_appleIceCream"); appleChunks = new ItemFood(4, 0.5F, false).setTextureName(MainClass.modid + ":appleChunks").setUnlocalizedName("appleChunks"); GameRegistry.registerItem(appleChunks, "nothappenin_appleChunks"); appleSnowball = new Item().setCreativeTab(CreativeTabs.tabFood).setTextureName(MainClass.modid + ":appleSnowball").setUnlocalizedName("appleSnowball"); GameRegistry.registerItem(appleSnowball, "yournot_appleSnowball"); melonIceCream = new ItemFood(1, 0.3F, false).setTextureName(MainClass.modid + ":melonIceCream").setUnlocalizedName("melonIceCream"); GameRegistry.registerItem(melonIceCream, "gettinmy_melonIceCream"); melonChunks = new ItemFood(1, 0.3F, false).setTextureName(MainClass.modid + ":melonChunks").setUnlocalizedName("melonChunks"); GameRegistry.registerItem(melonChunks, "mods_melonChunks"); melonSnowball = new Item().setCreativeTab(CreativeTabs.tabFood).setTextureName(MainClass.modid + ":melonSnowball").setUnlocalizedName("melonSnowball"); GameRegistry.registerItem(melonSnowball, "name_melonSnowball"); iceCreamCone = new ItemFood(0, 0.1F, false).setTextureName(MainClass.modid + ":iceCreamCone").setUnlocalizedName("iceCreamCone"); GameRegistry.registerItem(iceCreamCone, "brah_iceCreamCone"); caramel = new ItemCaramel(1, 0.2F, false).setTextureName(MainClass.modid + ":caramel").setUnlocalizedName("caramel"); GameRegistry.registerItem(caramel, "dunno_caramel"); caramelSnowball = new Item().setCreativeTab(CreativeTabs.tabFood).setTextureName(MainClass.modid + ":caramelSnowball").setUnlocalizedName("caramelSnowball"); GameRegistry.registerItem(caramelSnowball, "whatto_caramelSnowball"); caramelIceCream = new ItemFood(3, 0.6F, false).setTextureName(MainClass.modid + ":caramelIceCream").setUnlocalizedName("caramelIceCream"); GameRegistry.registerItem(caramelIceCream, "fillwith_caramelIceCream"); //Crafting recipes GameRegistry.addRecipe(new ItemStack(iceCreamCone, 3, 0), new Object[]{ "WSW", " W ", 'W', Items.wheat, 'S', Items.sugar }); //The recipes I use with the knife GameRegistry.addRecipe(new ItemStack(appleChunks), new Object[]{ "K", "M", 'M', new ItemStack(Items.apple), 'K', new ItemStack(knife, 1, OreDictionary.WILDCARD_VALUE) }); GameRegistry.addRecipe(new ItemStack(melonChunks), new Object[]{ "K", "M", 'M', new ItemStack(Items.melon), 'K', new ItemStack(knife, 1, OreDictionary.WILDCARD_VALUE) }); GameRegistry.addShapelessRecipe(new ItemStack(appleSnowball), new Object[]{ new ItemStack(Items.snowball), new ItemStack(appleChunks) }); GameRegistry.addShapelessRecipe(new ItemStack(melonSnowball), new Object[]{ new ItemStack(Items.snowball), new ItemStack(melonChunks) }); GameRegistry.addShapelessRecipe(new ItemStack(caramelSnowball), new Object[]{ new ItemStack(Items.snowball), new ItemStack(caramel) }); //Knife recipe GameRegistry.addShapelessRecipe(new ItemStack(knife), new Object[]{ new ItemStack(Items.stick), new ItemStack(Items.iron_ingot) }); GameRegistry.addRecipe(new ItemStack(appleIceCream), new Object[]{ "M", "A", 'M', appleSnowball, 'A', iceCreamCone }); GameRegistry.addRecipe(new ItemStack(melonIceCream), new Object[]{ "M", "A", 'M', melonSnowball, 'A', iceCreamCone }); GameRegistry.addRecipe(new ItemStack(caramelIceCream), new Object[]{ "M", "A", 'M', caramelSnowball, 'A', iceCreamCone }); //Smelting recipes GameRegistry.addSmelting(Items.sugar,new ItemStack(caramel), 0.1F); } Best regards, mission712 Quote hi
mission712 Posted May 9, 2014 Author Posted May 9, 2014 Excuse me, can you explain me that please? Best regards, mission712 Quote hi
darty11 Posted May 9, 2014 Posted May 9, 2014 public boolean hasContainerItem(ItemStack stack) { return true; } public boolean hasContainerItem(ItemStack stack) { return stack.getItemDamage()<127;; } Quote
mission712 Posted May 9, 2014 Author Posted May 9, 2014 Thank you very much, I will reply as soon as I get the result. Best regards, mission712 Quote hi
mission712 Posted May 9, 2014 Author Posted May 9, 2014 THANK YOU! OMG it finally worked. Thank you for your support. Best regards, mission712 Quote hi
Recommended Posts
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.