Jump to content

(SOLVED) -=[1.7.2]=- Crafting item durability does not work!


mission712

Recommended Posts

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

hi :)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.