Jump to content

Item damage on crafting


mydeblob

Recommended Posts

Ya ya, im sure you get ton of these threads, but for some reason this isn't working. Im using forge 1.6.2, and I want an item to take 1 damage out of 64 when used to craft something. I made some code for it but I can only use it 3 times before it won't let me craft anymore but the item still has durability. Thanks for your help.

Base Mod class (the knife item is the one that should be able to be used more than once)

 

package mydeblob.mineedibles;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;

@Mod(modid="mineedibles", name="MineEdibles", version="1.0.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class MineEdibles {


        // The instance of your mod that Forge uses.
        @Instance("Sandwich")
        public static MineEdibles instance;
        private static Item breadslice;
        private static Item chickensandwich;
        private static Item steaksandwich;
        private static Item hamsandwich;
        private static Item supersandwich;
        private static Item chickenbit;
        private static Item steakbit;
        private static Item porkbit;
        public static Item tomatoseeds;
        public static Item tomatofruit;
        public static Block tomatocrop;
        public static Item rawbacon;
        private static Item cookedbacon;
        private static Item rawchickenbit;
        private static Item rawsteakbit;
        private static Item rawporkbit;
        public static Item knife;
        
        //Item Ids for the config file
        int breadsliceID;
        int chickensandwichID;
        int steaksandwichID;
        int hamsandwichID;
        int supersandwichID;
        int chickenbitID;
        int steakbitID;
        int porkbitID;
        int tomatoseedsID;
        int tomatocropID;
        int tomatofruitID;
        int rawbaconID;
        int cookedbaconID;
        int rawchickenbitID;
        int rawsteakbitID;
        int rawporkbitID;
        int knifeID;

        
        // Says where the client and server 'proxy' code is loaded.
        @SidedProxy(clientSide="mydeblob.mineedibles.client.ClientProxy", serverSide="mydeblob.mineedibles.CommonProxy")
        public static CommonProxy proxy;
        
        @EventHandler
        public void preInit(FMLPreInitializationEvent event) {
        	//Basic Configuration file
        	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
        	config.load();
        	breadsliceID = config.get("Item IDs", "Bread Slice", 5000).getInt();
        	chickensandwichID = config.get("Item IDs", "Chicken Sandwich", 5001).getInt();
        	steaksandwichID = config.get("Item IDs", "Steak Sandwich", 5002).getInt();
        	hamsandwichID = config.get("Item IDs", "Ham Sandwich", 5003).getInt();
        	supersandwichID = config.get("Item IDs", "Super Sandwich", 5004).getInt();
        	chickenbitID = config.get("Item IDs", "Slice of Chicken", 5005).getInt();
        	steakbitID = config.get("Item IDs", "Slice of Steak", 5006).getInt();
        	porkbitID = config.get("Item IDs", "Slice of Pork", 5007).getInt();
        	tomatoseedsID = config.get("Item IDs", "Tomato Seeds", 5008).getInt();
        	tomatofruitID = config.get("Item IDs", "Tomato Fruit", 5009).getInt();
        	rawbaconID = config.get("Item IDs", "Raw Bacon", 50010).getInt();
        	cookedbaconID = config.get("Item IDs", "Cooked Bacon", 5011).getInt();
        	rawchickenbitID = config.get("Item IDs", "Raw Slice of Chicken", 5012).getInt();
        	rawsteakbitID = config.get("Item IDs", "Raw Slice of Beef", 5013).getInt();
        	rawporkbitID = config.get("Item IDs", "Raw Slice of Ham", 5014).getInt();
        	knifeID = config.get("Item IDs", "Knife", 5015).getInt();
        	config.save();
        }
        
        @EventHandler
        public void load(FMLInitializationEvent event) {
                proxy.registerRenderers();
                //Items
               breadslice = new Item(breadsliceID).setUnlocalizedName("breadslice").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:slicebread");
               chickensandwich = new ItemFood(chickensandwichID, 9, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("chickensandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:chickensandwich");
               steaksandwich = new ItemFood(steaksandwichID, 9, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("steaksandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:steaksandwich");
               hamsandwich = new ItemFood(hamsandwichID, 9, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("hamsandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:hamsandwich");
               supersandwich = new ItemFood(supersandwichID, 18, 1.4f, false).setAlwaysEdible().setPotionEffect(Potion.regeneration.id, 6, 1, 0.8f).setPotionEffect(Potion.moveSpeed.id, 6, 1, 0.8f).setUnlocalizedName("supersandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:supersandwich");
               chickenbit = new ItemFood(chickenbitID, 2, 0.4f, false).setUnlocalizedName("chickenbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:chickenbit");
               steakbit = new ItemFood(steakbitID, 2, 0.4f, false).setUnlocalizedName("steakbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:steakbit");
               porkbit = new ItemFood(porkbitID, 2, 0.4f, false).setUnlocalizedName("porkbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:porkbit");
               tomatocrop = new TomatoCrop(tomatocropID).setUnlocalizedName("tomatocrop").func_111022_d("mineedibles:tomatocrop");
               tomatoseeds = new ItemSeeds(tomatoseedsID, tomatocrop.blockID, Block.tilledField.blockID).setUnlocalizedName("tomatoseeds").func_111206_d("mineedibles:tomatoseeds");
               tomatofruit = new ItemFood(tomatofruitID, 6, 0.8f, false).setUnlocalizedName("tomatofruit").func_111206_d("mineedibles:tomatofruit");
               rawbacon = new ItemFood(rawbaconID, 3, 0.3f, false).setUnlocalizedName("baconraw").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawbacon");
               cookedbacon = new ItemFood(cookedbaconID, 7, 0.6f, false).setUnlocalizedName("baconcooked").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:cookedbacon");
               rawchickenbit = new ItemFood(rawchickenbitID, 1, 0.2f, false).setUnlocalizedName("rawchickenbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawchickenbit");
               rawsteakbit = new ItemFood(rawsteakbitID, 1, 0.2f, false).setUnlocalizedName("rawsteakbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawsteakbit");
               rawporkbit = new ItemFood(rawporkbitID, 1, 0.2f, false).setUnlocalizedName("rawporkbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawporkbit");
               knife = new Item(knifeID).setUnlocalizedName("knife").setMaxDamage(64).setMaxStackSize(1).setCreativeTab(CreativeTabs.tabTools).func_111206_d("mineedibles:knifeBlack");
               MinecraftForge.addGrassSeed(new ItemStack (tomatoseeds), 10);
               gameRegisters();
               languageRegisters();
               craftingRecipes();
               	//Smelting
               GameRegistry.addSmelting(MineEdibles.rawbacon.itemID, new ItemStack(MineEdibles.cookedbacon, 1), 0.1f);
               GameRegistry.addSmelting(MineEdibles.rawchickenbit.itemID, new ItemStack(MineEdibles.chickenbit, 1), 0.1f);
               GameRegistry.addSmelting(MineEdibles.rawsteakbit.itemID, new ItemStack(MineEdibles.steakbit, 1), 0.1f);
               GameRegistry.addSmelting(MineEdibles.rawporkbit.itemID, new ItemStack(MineEdibles.porkbit, 1), 0.1f);




        }

        //Item and Block registeration
        private static void gameRegisters(){
        	GameRegistry.registerItem(breadslice, "Bread Slice");
        	GameRegistry.registerItem(chickensandwich, "Chicken Sandwich");
        	GameRegistry.registerItem(steaksandwich, "Steak Sandwich");
        	GameRegistry.registerItem(hamsandwich, "Ham Sandwich");
        	GameRegistry.registerItem(supersandwich, "Super Sandwich");
        	GameRegistry.registerItem(chickenbit, "Slice of Chicken");
        	GameRegistry.registerItem(steakbit, "Slice of Steak");
        	GameRegistry.registerItem(porkbit, "Slice of Ham");
        	GameRegistry.registerItem(tomatoseeds, "Tomato Seeds");
        	GameRegistry.registerItem(tomatofruit, "Tomato");
        	GameRegistry.registerBlock(tomatocrop, "Tomato Crop");
        	GameRegistry.registerItem(rawbacon, "Raw Bacon");
        	GameRegistry.registerItem(cookedbacon, "Cooked Bacon");
        	GameRegistry.registerItem(rawchickenbit, "Raw Slice of Chicken");
        	GameRegistry.registerItem(rawsteakbit, "Raw Slice of Steak");
        	GameRegistry.registerItem(rawporkbit, "Raw Slice of Ham");
        	GameRegistry.registerItem(knife, "Knife");
        	GameRegistry.registerCraftingHandler(new KnifeCraftingHandler());
        }
        //Item and Block in game name, languageregistry
        private static void languageRegisters(){
        	LanguageRegistry.addName(breadslice, "Bread Slice");
        	LanguageRegistry.addName(chickensandwich, "Chicken Sandwich");
        	LanguageRegistry.addName(steaksandwich, "Steak Sandwich");
        	LanguageRegistry.addName(hamsandwich, "Ham Sandwich");
        	LanguageRegistry.addName(supersandwich, "Super Sandwich");
        	LanguageRegistry.addName(chickenbit, "Slice of Chicken");
        	LanguageRegistry.addName(steakbit, "Slice of Steak");
        	LanguageRegistry.addName(porkbit, "Slice of Ham");
        	LanguageRegistry.addName(tomatoseeds, "Tomato Seeds");
        	LanguageRegistry.addName(tomatofruit, "Tomato");
        	LanguageRegistry.addName(rawbacon, "Raw Bacon");
        	LanguageRegistry.addName(rawchickenbit, "Raw Slice of Chicken");
        	LanguageRegistry.addName(rawsteakbit, "Raw Slice of Steak");
        	LanguageRegistry.addName(rawporkbit, "Raw Slice of Ham");
        	LanguageRegistry.addName(knife, "Knife");
        }
        //Crafting Recipes
        public void craftingRecipes(){
        	//Cooked meat slices
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.breadslice, 6), new ItemStack(ItemFood.bread));
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.chickenbit, 3), new Object[]{ItemFood.chickenCooked, (new ItemStack(knife, 1, 0 ))});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.steakbit, 3), new Object[]{ItemFood.beefCooked, (new ItemStack(knife, 1, 0))});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.porkbit, 3), new Object[]{ItemFood.porkCooked, (new ItemStack(knife, 1, 0))});
        	//Raw Meat Slices
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawchickenbit, 3), new Object[]{ItemFood.chickenRaw, (new ItemStack(knife, 1, 0))});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawsteakbit, 3), new Object[]{ItemFood.beefRaw, (new ItemStack(knife, 1, 0))});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawporkbit, 3), new Object[]{ItemFood.porkRaw, (new ItemStack(knife, 1, 0))});
        	//Sandwiches
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawchickenbit, 3), new ItemStack(ItemFood.chickenRaw));
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawsteakbit, 3), new ItemStack(ItemFood.beefRaw));
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawporkbit, 3), new ItemStack(ItemFood.porkRaw));
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.chickensandwich, 1), new Object[]{" B ", " C ", " B ", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked });
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.steaksandwich, 1), new Object[]{" B ", " S ", " B ", 'B', MineEdibles.breadslice, 'S', ItemFood.beefCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.hamsandwich, 1), new Object[]{" B ", " P ", " B ", 'B', MineEdibles.breadslice, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "SCP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "SPC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        
        	
        }
        @EventHandler
        public void postInit(FMLPostInitializationEvent event) {
                
        }
}

 

CraftingHandlerClass for the Item Knife

 

package mydeblob.mineedibles;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.ICraftingHandler;

public class KnifeCraftingHandler implements ICraftingHandler {

@Override
public void onCrafting(EntityPlayer player, ItemStack item,
		IInventory craftMatrix) {
	for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {

		if (craftMatrix.getStackInSlot(i) != null) {
			ItemStack j = craftMatrix.getStackInSlot(i);

			if (j.getItem() != null && j.getItem() == MineEdibles.knife) {
				ItemStack k = new ItemStack(MineEdibles.knife, 2, (j.getItemDamage() + 1));

				if (k.getItemDamage() >= k.getMaxDamage()) {
					k.stackSize--;
				}
				craftMatrix.setInventorySlotContents(i, k);
			}
		}
	}

}

@Override
public void onSmelting(EntityPlayer player, ItemStack item) {
	// TODO Auto-generated method stub

}

}

 

Link to comment
Share on other sites

No need for a crafting handler. In your ItemKnife.java:

 

@Override
public ItemStack getContainerItemStack(ItemStack itemStack)
{
	int alter = itemStack.getItemDamage() - 1;
	if(alter >= itemStack.getMaxDamage())
	{
		return null;
	}
	itemStack.setItemDamage(alter);
	return itemStack;
}

 

Will return the same stack that was used with the damage minus 1. If the changed damage is greater/equal compared to the maximum allowed damage, will 'break' the item by returning null.

Link to comment
Share on other sites

Ok, I must be doing something wrong... I copied your code, and removed the craftinghandler class and now when I use the knife to craft something it allows me to use it once and then it disappears. Here is the new code

ItemKnife Class

 

package mydeblob.mineedibles;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.BlockCocoa;
import net.minecraft.block.BlockColored;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.BlockLog;
import net.minecraft.block.BlockMushroom;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.BlockStem;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.FakePlayerFactory;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.entity.player.BonemealEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ItemKnife extends Item
{

public ItemKnife(int par1) {
	super(par1);
	setMaxDamage(64);
	setMaxStackSize(1);
	setCreativeTab(CreativeTabs.tabTools);
}
@Override
public ItemStack getContainerItemStack(ItemStack itemStack)
{
	int alter = itemStack.getItemDamage() - 1;
	if(alter >= itemStack.getMaxDamage())
	{
		return null;
	}
	itemStack.setItemDamage(alter);
	return itemStack;
}
    
}

 

MainClass

 

package mydeblob.mineedibles;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;

@Mod(modid="mineedibles", name="MineEdibles", version="1.0.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class MineEdibles {


        // The instance of your mod that Forge uses.
        @Instance("Sandwich")
        public static MineEdibles instance;
        private static Item breadslice;
        private static Item chickensandwich;
        private static Item steaksandwich;
        private static Item hamsandwich;
        private static Item supersandwich;
        private static Item chickenbit;
        private static Item steakbit;
        private static Item porkbit;
        public static Item tomatoseeds;
        public static Item tomatofruit;
        public static Block tomatocrop;
        public static Item rawbacon;
        private static Item cookedbacon;
        private static Item rawchickenbit;
        private static Item rawsteakbit;
        private static Item rawporkbit;
        public static Item knife;
        
        //Item Ids for the config file
        int breadsliceID;
        int chickensandwichID;
        int steaksandwichID;
        int hamsandwichID;
        int supersandwichID;
        int chickenbitID;
        int steakbitID;
        int porkbitID;
        int tomatoseedsID;
        int tomatocropID;
        int tomatofruitID;
        int rawbaconID;
        int cookedbaconID;
        int rawchickenbitID;
        int rawsteakbitID;
        int rawporkbitID;
        int knifeID;

        
        // Says where the client and server 'proxy' code is loaded.
        @SidedProxy(clientSide="mydeblob.mineedibles.client.ClientProxy", serverSide="mydeblob.mineedibles.CommonProxy")
        public static CommonProxy proxy;
        
        @EventHandler
        public void preInit(FMLPreInitializationEvent event) {
        	//Basic Configuration file
        	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
        	config.load();
        	breadsliceID = config.get("Item IDs", "Bread Slice", 5000).getInt();
        	chickensandwichID = config.get("Item IDs", "Chicken Sandwich", 5001).getInt();
        	steaksandwichID = config.get("Item IDs", "Steak Sandwich", 5002).getInt();
        	hamsandwichID = config.get("Item IDs", "Ham Sandwich", 5003).getInt();
        	supersandwichID = config.get("Item IDs", "Super Sandwich", 5004).getInt();
        	chickenbitID = config.get("Item IDs", "Slice of Chicken", 5005).getInt();
        	steakbitID = config.get("Item IDs", "Slice of Steak", 5006).getInt();
        	porkbitID = config.get("Item IDs", "Slice of Pork", 5007).getInt();
        	tomatoseedsID = config.get("Item IDs", "Tomato Seeds", 5008).getInt();
        	tomatofruitID = config.get("Item IDs", "Tomato Fruit", 5009).getInt();
        	rawbaconID = config.get("Item IDs", "Raw Bacon", 50010).getInt();
        	cookedbaconID = config.get("Item IDs", "Cooked Bacon", 5011).getInt();
        	rawchickenbitID = config.get("Item IDs", "Raw Slice of Chicken", 5012).getInt();
        	rawsteakbitID = config.get("Item IDs", "Raw Slice of Beef", 5013).getInt();
        	rawporkbitID = config.get("Item IDs", "Raw Slice of Ham", 5014).getInt();
        	knifeID = config.get("Item IDs", "Knife", 5015).getInt();
        	config.save();
        }
        
        @EventHandler
        public void load(FMLInitializationEvent event) {
                proxy.registerRenderers();
                //Items
               breadslice = new Item(breadsliceID).setUnlocalizedName("breadslice").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:slicebread");
               chickensandwich = new ItemFood(chickensandwichID, 9, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("chickensandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:chickensandwich");
               steaksandwich = new ItemFood(steaksandwichID, 9, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("steaksandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:steaksandwich");
               hamsandwich = new ItemFood(hamsandwichID, 9, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("hamsandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:hamsandwich");
               supersandwich = new ItemFood(supersandwichID, 18, 1.4f, false).setAlwaysEdible().setPotionEffect(Potion.regeneration.id, 6, 1, 0.8f).setPotionEffect(Potion.moveSpeed.id, 6, 1, 0.8f).setUnlocalizedName("supersandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:supersandwich");
               chickenbit = new ItemFood(chickenbitID, 2, 0.4f, false).setUnlocalizedName("chickenbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:chickenbit");
               steakbit = new ItemFood(steakbitID, 2, 0.4f, false).setUnlocalizedName("steakbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:steakbit");
               porkbit = new ItemFood(porkbitID, 2, 0.4f, false).setUnlocalizedName("porkbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:porkbit");
               tomatocrop = new TomatoCrop(tomatocropID).setUnlocalizedName("tomatocrop").func_111022_d("mineedibles:tomatocrop");
               tomatoseeds = new ItemSeeds(tomatoseedsID, tomatocrop.blockID, Block.tilledField.blockID).setUnlocalizedName("tomatoseeds").func_111206_d("mineedibles:tomatoseeds");
               tomatofruit = new ItemFood(tomatofruitID, 6, 0.8f, false).setUnlocalizedName("tomatofruit").func_111206_d("mineedibles:tomatofruit");
               rawbacon = new ItemFood(rawbaconID, 3, 0.3f, false).setUnlocalizedName("baconraw").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawbacon");
               cookedbacon = new ItemFood(cookedbaconID, 7, 0.6f, false).setUnlocalizedName("baconcooked").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:cookedbacon");
               rawchickenbit = new ItemFood(rawchickenbitID, 1, 0.2f, false).setUnlocalizedName("rawchickenbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawchickenbit");
               rawsteakbit = new ItemFood(rawsteakbitID, 1, 0.2f, false).setUnlocalizedName("rawsteakbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawsteakbit");
               rawporkbit = new ItemFood(rawporkbitID, 1, 0.2f, false).setUnlocalizedName("rawporkbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawporkbit");
               knife = new ItemKnife(knifeID).setUnlocalizedName("knife").func_111206_d("mineedibles:knifeBlack");
               MinecraftForge.addGrassSeed(new ItemStack (tomatoseeds), 10);
               gameRegisters();
               languageRegisters();
               craftingRecipes();
               	//Smelting
               GameRegistry.addSmelting(MineEdibles.rawbacon.itemID, new ItemStack(MineEdibles.cookedbacon, 1), 0.1f);
               GameRegistry.addSmelting(MineEdibles.rawchickenbit.itemID, new ItemStack(MineEdibles.chickenbit, 1), 0.1f);
               GameRegistry.addSmelting(MineEdibles.rawsteakbit.itemID, new ItemStack(MineEdibles.steakbit, 1), 0.1f);
               GameRegistry.addSmelting(MineEdibles.rawporkbit.itemID, new ItemStack(MineEdibles.porkbit, 1), 0.1f);




        }

        //Item and Block registeration
        private static void gameRegisters(){
        	GameRegistry.registerItem(breadslice, "Bread Slice");
        	GameRegistry.registerItem(chickensandwich, "Chicken Sandwich");
        	GameRegistry.registerItem(steaksandwich, "Steak Sandwich");
        	GameRegistry.registerItem(hamsandwich, "Ham Sandwich");
        	GameRegistry.registerItem(supersandwich, "Super Sandwich");
        	GameRegistry.registerItem(chickenbit, "Slice of Chicken");
        	GameRegistry.registerItem(steakbit, "Slice of Steak");
        	GameRegistry.registerItem(porkbit, "Slice of Ham");
        	GameRegistry.registerItem(tomatoseeds, "Tomato Seeds");
        	GameRegistry.registerItem(tomatofruit, "Tomato");
        	GameRegistry.registerBlock(tomatocrop, "Tomato Crop");
        	GameRegistry.registerItem(rawbacon, "Raw Bacon");
        	GameRegistry.registerItem(cookedbacon, "Cooked Bacon");
        	GameRegistry.registerItem(rawchickenbit, "Raw Slice of Chicken");
        	GameRegistry.registerItem(rawsteakbit, "Raw Slice of Steak");
        	GameRegistry.registerItem(rawporkbit, "Raw Slice of Ham");
        	GameRegistry.registerItem(knife, "Knife");

        }
        //Item and Block in game name, languageregistry
        private static void languageRegisters(){
        	LanguageRegistry.addName(breadslice, "Bread Slice");
        	LanguageRegistry.addName(chickensandwich, "Chicken Sandwich");
        	LanguageRegistry.addName(steaksandwich, "Steak Sandwich");
        	LanguageRegistry.addName(hamsandwich, "Ham Sandwich");
        	LanguageRegistry.addName(supersandwich, "Super Sandwich");
        	LanguageRegistry.addName(chickenbit, "Slice of Chicken");
        	LanguageRegistry.addName(steakbit, "Slice of Steak");
        	LanguageRegistry.addName(porkbit, "Slice of Ham");
        	LanguageRegistry.addName(tomatoseeds, "Tomato Seeds");
        	LanguageRegistry.addName(tomatofruit, "Tomato");
        	LanguageRegistry.addName(rawbacon, "Raw Bacon");
        	LanguageRegistry.addName(rawchickenbit, "Raw Slice of Chicken");
        	LanguageRegistry.addName(rawsteakbit, "Raw Slice of Steak");
        	LanguageRegistry.addName(rawporkbit, "Raw Slice of Ham");
        	LanguageRegistry.addName(knife, "Knife");
        }
        //Crafting Recipes
        public void craftingRecipes(){
        	//Cooked meat slices
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.breadslice, 6), new ItemStack(ItemFood.bread));
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.chickenbit, 3), new Object[]{ItemFood.chickenCooked, knife});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.steakbit, 3), new Object[]{ItemFood.beefCooked, (new ItemStack(knife, 1, 0))});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.porkbit, 3), new Object[]{ItemFood.porkCooked, (new ItemStack(knife, 1, 0))});
        	//Raw Meat Slices
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawchickenbit, 3), new Object[]{ItemFood.chickenRaw, (new ItemStack(knife, 1, 0))});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawsteakbit, 3), new Object[]{ItemFood.beefRaw, (new ItemStack(knife, 1, 0))});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawporkbit, 3), new Object[]{ItemFood.porkRaw, (new ItemStack(knife, 1, 0))});
        	//Sandwiches
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawchickenbit, 3), new ItemStack(ItemFood.chickenRaw));
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawsteakbit, 3), new ItemStack(ItemFood.beefRaw));
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawporkbit, 3), new ItemStack(ItemFood.porkRaw));
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.chickensandwich, 1), new Object[]{" B ", " C ", " B ", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked });
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.steaksandwich, 1), new Object[]{" B ", " S ", " B ", 'B', MineEdibles.breadslice, 'S', ItemFood.beefCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.hamsandwich, 1), new Object[]{" B ", " P ", " B ", 'B', MineEdibles.breadslice, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "SCP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "SPC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        
        	
        }
        @EventHandler
        public void postInit(FMLPostInitializationEvent event) {
                
        }
}

 

I appreciate your help

Link to comment
Share on other sites

Ok, Its only letting me use it once and then it is braking. Maybe something with the crafting recipes?

Heres the new code:

ItemKnife class

 

package mydeblob.mineedibles;

import net.minecraft.item.ItemStack;

public class ItemKnife extends ItemME{

public ItemKnife(int par1, String par2) {
	super(par1, par2);

}
@Override
public boolean hasContainerItem()
{
     return true;
}
@Override
public ItemStack getContainerItemStack(ItemStack itemStack)
{
	int alter = itemStack.getItemDamage() + 1;
	if(alter >= itemStack.getMaxDamage())
	{
		return null;
	}
	itemStack.setItemDamage(alter);
	return itemStack;
}

}

 

Main class

 

package mydeblob.mineedibles;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid="mineedibles", name="MineEdibles", version="1.0.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class MineEdibles {


// The instance of your mod that Forge uses.
@Instance("Sandwich")
public static MineEdibles instance;
private static Item breadslice;
private static Item chickensandwich;
private static Item steaksandwich;
private static Item hamsandwich;
private static Item supersandwich;
private static Item chickenbit;
private static Item steakbit;
private static Item porkbit;
public static Item tomatoseeds;
public static Item tomatofruit;
public static Block tomatocrop;
public static Item rawbacon;
private static Item cookedbacon;
private static Item rawchickenbit;
private static Item rawsteakbit;
private static Item rawporkbit;
public static Item knife;
public static Item cream;

//Item Ids for the config file
int breadsliceID;
int chickensandwichID;
int steaksandwichID;
int hamsandwichID;
int supersandwichID;
int chickenbitID;
int steakbitID;
int porkbitID;
int tomatoseedsID;
int tomatocropID;
int tomatofruitID;
int rawbaconID;
int cookedbaconID;
int rawchickenbitID;
int rawsteakbitID;
int rawporkbitID;
int knifeID;
int creamID;


// Says where the client and server 'proxy' code is loaded.
@SidedProxy(clientSide="mydeblob.mineedibles.client.ClientProxy", serverSide="mydeblob.mineedibles.CommonProxy")
public static CommonProxy proxy;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	//Basic Configuration file
	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
	config.load();
	breadsliceID = config.get("Item IDs", "Bread Slice", 5000).getInt();
	chickensandwichID = config.get("Item IDs", "Chicken Sandwich", 5001).getInt();
	steaksandwichID = config.get("Item IDs", "Steak Sandwich", 5002).getInt();
	hamsandwichID = config.get("Item IDs", "Ham Sandwich", 5003).getInt();
	supersandwichID = config.get("Item IDs", "Super Sandwich", 5004).getInt();
	chickenbitID = config.get("Item IDs", "Slice of Chicken", 5005).getInt();
	steakbitID = config.get("Item IDs", "Slice of Steak", 5006).getInt();
	porkbitID = config.get("Item IDs", "Slice of Pork", 5007).getInt();
	tomatoseedsID = config.get("Item IDs", "Tomato Seeds", 5008).getInt();
	tomatocropID = config.get("Block IDs", "Tomato Crop", 500).getInt();
	tomatofruitID = config.get("Item IDs", "Tomato Fruit", 5009).getInt();
	rawbaconID = config.get("Item IDs", "Raw Bacon", 5010).getInt();
	cookedbaconID = config.get("Item IDs", "Cooked Bacon", 5011).getInt();
	rawchickenbitID = config.get("Item IDs", "Raw Slice of Chicken", 5012).getInt();
	rawsteakbitID = config.get("Item IDs", "Raw Slice of Beef", 5013).getInt();
	rawporkbitID = config.get("Item IDs", "Raw Slice of Ham", 5014).getInt();
	knifeID = config.get("Item IDs", "Knife", 5015).getInt();
	knifeID = config.get("Item IDs", "Bucket of Cream", 5016).getInt();
	config.save();
}

@EventHandler
public void load(FMLInitializationEvent event) {
	proxy.register();
	//Items
	breadslice = new ItemME(breadsliceID, "breadslice").setUnlocalizedName("breadslice").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood);
	chickensandwich = new ItemFoodME(chickensandwichID, 9, 0.8f, false, "chickensandwich").setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("chickensandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood);
	steaksandwich = new ItemFoodME(steaksandwichID, 9, 0.8f, false, "steaksandwich").setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("steaksandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood);
	hamsandwich = new ItemFoodME(hamsandwichID, 9, 0.8f, false, "hamsandwich").setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("hamsandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood);
	supersandwich = new ItemFoodME(supersandwichID, 18, 1.4f, false, "supersandwich").setAlwaysEdible().setPotionEffect(Potion.regeneration.id, 6, 1, 0.8f).setPotionEffect(Potion.moveSpeed.id, 6, 1, 0.8f).setUnlocalizedName("supersandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood);
	chickenbit = new ItemFoodME(chickenbitID, 2, 0.4f, false, "chickenbit").setUnlocalizedName("chickenbit").setCreativeTab(CreativeTabs.tabFood);
	steakbit = new ItemFoodME(steakbitID, 2, 0.4f, false, "steakbit").setUnlocalizedName("steakbit").setCreativeTab(CreativeTabs.tabFood);
	porkbit = new ItemFoodME(porkbitID, 2, 0.4f, false, "porkbit").setUnlocalizedName("porkbit").setCreativeTab(CreativeTabs.tabFood);
	tomatocrop = new BlockCropME(tomatocropID, "tomatocrop", this.tomatoseedsID, this.tomatocropID).setUnlocalizedName("tomatocrop");
	tomatoseeds = new ItemSeedsME(tomatoseedsID, tomatocrop.blockID, 60).setUnlocalizedName("tomatoseeds").func_111206_d("mineedibles:tomatoseeds");
	tomatofruit = new ItemFoodME(tomatofruitID, 6, 0.8f, false, "tomatofruit").setUnlocalizedName("tomatofruit");
	rawbacon = new ItemFoodME(rawbaconID, 3, 0.3f, false, "rawbacon").setUnlocalizedName("baconraw").setCreativeTab(CreativeTabs.tabFood);
	cookedbacon = new ItemFoodME(cookedbaconID, 7, 0.6f, false, "cookedbacon").setUnlocalizedName("baconcooked").setCreativeTab(CreativeTabs.tabFood);
	rawchickenbit = new ItemFoodME(rawchickenbitID, 1, 0.2f, false, "rawchickenbit").setUnlocalizedName("rawchickenbit").setCreativeTab(CreativeTabs.tabFood);
	rawsteakbit = new ItemFoodME(rawsteakbitID, 1, 0.2f, false, "rawsteakbit").setUnlocalizedName("rawsteakbit").setCreativeTab(CreativeTabs.tabFood);
	rawporkbit = new ItemFoodME(rawporkbitID, 1, 0.2f, false, "rawporkbit").setUnlocalizedName("rawporkbit").setCreativeTab(CreativeTabs.tabFood);
	knife = new ItemME(knifeID, "knifeBlack").setUnlocalizedName("knifeBlack").setMaxDamage(64).setMaxStackSize(1).setCreativeTab(CreativeTabs.tabTools);
	cream = new ItemCream(creamID, "cream").setUnlocalizedName("cream");
	MinecraftForge.addGrassSeed(new ItemStack (tomatoseeds), 10);
	gameRegisters();
	languageRegisters();
	craftingRecipes();
	//Smelting
	GameRegistry.addSmelting(MineEdibles.rawbacon.itemID, new ItemStack(MineEdibles.cookedbacon, 1), 0.1f);
	GameRegistry.addSmelting(MineEdibles.rawchickenbit.itemID, new ItemStack(MineEdibles.chickenbit, 1), 0.1f);
	GameRegistry.addSmelting(MineEdibles.rawsteakbit.itemID, new ItemStack(MineEdibles.steakbit, 1), 0.1f);
	GameRegistry.addSmelting(MineEdibles.rawporkbit.itemID, new ItemStack(MineEdibles.porkbit, 1), 0.1f);




}

//Item and Block registeration
private static void gameRegisters(){
	GameRegistry.registerItem(breadslice, "Bread Slice");
	GameRegistry.registerItem(chickensandwich, "Chicken Sandwich");
	GameRegistry.registerItem(steaksandwich, "Steak Sandwich");
	GameRegistry.registerItem(hamsandwich, "Ham Sandwich");
	GameRegistry.registerItem(supersandwich, "Super Sandwich");
	GameRegistry.registerItem(chickenbit, "Slice of Chicken");
	GameRegistry.registerItem(steakbit, "Slice of Steak");
	GameRegistry.registerItem(porkbit, "Slice of Ham");
	GameRegistry.registerItem(tomatoseeds, "Tomato Seeds");
	GameRegistry.registerItem(tomatofruit, "Tomato");
	GameRegistry.registerBlock(tomatocrop, "Tomato Crop");
	GameRegistry.registerItem(rawbacon, "Raw Bacon");
	GameRegistry.registerItem(cookedbacon, "Cooked Bacon");
	GameRegistry.registerItem(rawchickenbit, "Raw Slice of Chicken");
	GameRegistry.registerItem(rawsteakbit, "Raw Slice of Steak");
	GameRegistry.registerItem(rawporkbit, "Raw Slice of Ham");
	GameRegistry.registerItem(knife, "Knife");

}
//Item and Block in game name, languageregistry
private static void languageRegisters(){
	LanguageRegistry.addName(breadslice, "Bread Slice");
	LanguageRegistry.addName(chickensandwich, "Chicken Sandwich");
	LanguageRegistry.addName(steaksandwich, "Steak Sandwich");
	LanguageRegistry.addName(hamsandwich, "Ham Sandwich");
	LanguageRegistry.addName(supersandwich, "Super Sandwich");
	LanguageRegistry.addName(chickenbit, "Slice of Chicken");
	LanguageRegistry.addName(steakbit, "Slice of Steak");
	LanguageRegistry.addName(porkbit, "Slice of Ham");
	LanguageRegistry.addName(tomatoseeds, "Tomato Seeds");
	LanguageRegistry.addName(tomatofruit, "Tomato");
	LanguageRegistry.addName(rawbacon, "Raw Bacon");
	LanguageRegistry.addName(cookedbacon, "Cooked Bacon");
	LanguageRegistry.addName(rawchickenbit, "Raw Slice of Chicken");
	LanguageRegistry.addName(rawsteakbit, "Raw Slice of Steak");
	LanguageRegistry.addName(rawporkbit, "Raw Slice of Ham");
	LanguageRegistry.addName(knife, "Knife");
}
//Crafting Recipes
public void craftingRecipes(){
	//Cooked meat slices
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.breadslice, 6), new ItemStack(ItemFood.bread));
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.chickenbit, 3), new Object[]{ItemFood.chickenCooked, (new ItemStack(knife, 1, 0))});
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.steakbit, 3), new Object[]{ItemFood.beefCooked, (new ItemStack(knife, 1, 0))});
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.porkbit, 3), new Object[]{ItemFood.porkCooked, (new ItemStack(knife, 1, 0))});
	//Raw Meat Slices
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawchickenbit, 3), new Object[]{ItemFood.chickenRaw, (new ItemStack(knife, 1, 0))});
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawsteakbit, 3), new Object[]{ItemFood.beefRaw, (new ItemStack(knife, 1, 0))});
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawporkbit, 3), new Object[]{ItemFood.porkRaw, (new ItemStack(knife, 1, 0))});
	//Sandwiches
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawchickenbit, 3), new ItemStack(ItemFood.chickenRaw));
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawsteakbit, 3), new ItemStack(ItemFood.beefRaw));
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawporkbit, 3), new ItemStack(ItemFood.porkRaw));
	GameRegistry.addRecipe(new ItemStack(MineEdibles.chickensandwich, 1), new Object[]{" B ", " C ", " B ", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked });
	GameRegistry.addRecipe(new ItemStack(MineEdibles.steaksandwich, 1), new Object[]{" B ", " S ", " B ", 'B', MineEdibles.breadslice, 'S', ItemFood.beefCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.hamsandwich, 1), new Object[]{" B ", " P ", " B ", 'B', MineEdibles.breadslice, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "SCP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "SPC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	//cream
	GameRegistry.addShapelessRecipe(new ItemStack(MineEdibles.cream, 1), new Object []{ItemFood.bucketMilk, ItemFood.sugar});

}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {

}

 

Link to comment
Share on other sites

Your knife has to have a maxDamage lol. In the constructor or the initialization, add:

 

setMaxDamage(maxDmgInteger);

 

Also, unless you make a new IRecipe instance, you'll have to do this to add your recipes:

 

for(int i = 0; i < knife.getMaxDamage(); i++)
{
     GameRegistry.addRecipe(new ItemStack(myCarvedItem), new Object[]
     {
          "top", "mid", "bot", 't', new ItemStack(knife, 1, i)
     });
}

Obviously that wouldn't be your recipe but any character that represents your knife will need to use i as the damage. This will actually add as many recipes as your item has max damage.

 

Remove:

if(alter > stack.getMaxDamage())
{
	return null;
}

Link to comment
Share on other sites

Still doesn't work :/ I have no idea what I'm doing wrong. Spent about a hour looking through my code looking for any error that would cause it to not work. It still only lets me use it once.

ItemKnife Class

 

package mydeblob.mineedibles;

import net.minecraft.item.ItemStack;

public class ItemKnife extends ItemME{

public ItemKnife(int par1, String par2) {
	super(par1, par2);
	this.setMaxDamage(64);


}
@Override
public boolean hasContainerItem()
{
     return true;
}
@Override
public ItemStack getContainerItemStack(ItemStack itemStack)
{
	int alter = itemStack.getItemDamage() + 1;
	itemStack.setItemDamage(alter);
	return itemStack;
}


}

 

Main Class

 

package mydeblob.mineedibles;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid="mineedibles", name="MineEdibles", version="1.0.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class MineEdibles {


// The instance of your mod that Forge uses.
@Instance("Sandwich")
public static MineEdibles instance;
public static Item breadslice;
public static Item chickensandwich;
public static Item steaksandwich;
public static Item hamsandwich;
public static Item supersandwich;
public static Item chickenbit;
public static Item steakbit;
public static Item porkbit;
public static Item tomatoseeds;
public static Item tomatofruit;
public static Block tomatocrop;
public static Item rawbacon;
public static Item cookedbacon;
public static Item rawchickenbit;
public static Item rawsteakbit;
public static Item rawporkbit;
public static Item knife;
public static Item cream;
public static Item lettuceseeds;
public static Item lettuce;
public static Block lettucecrop;
public static Item fertilizer;
public static Item manure;


//Item Ids for the config file
int breadsliceID;
int chickensandwichID;
int steaksandwichID;
int hamsandwichID;
int supersandwichID;
int chickenbitID;
int steakbitID;
int porkbitID;
int tomatoseedsID;
int tomatocropID;
int tomatofruitID;
int rawbaconID;
int cookedbaconID;
int rawchickenbitID;
int rawsteakbitID;
int rawporkbitID;
int knifeID;
int creamID;
int lettuceseedsID;
int lettuceID;
int lettucecropID;
int fertilizerID;
int manureID;

public static CreativeTabs tabMineEdibles = new CreativeTabs("tabMineEdibles")
{
	public ItemStack getIconItemStack()
	{
		return new ItemStack(hamsandwich, 1);
	}
};


// Says where the client and server 'proxy' code is loaded.
@SidedProxy(clientSide="mydeblob.mineedibles.client.ClientProxy", serverSide="mydeblob.mineedibles.CommonProxy")
public static CommonProxy proxy;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	//Basic Configuration file
	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
	config.load();
	breadsliceID = config.get("Item IDs", "Bread Slice", 5000).getInt();
	chickensandwichID = config.get("Item IDs", "Chicken Sandwich", 5001).getInt();
	steaksandwichID = config.get("Item IDs", "Steak Sandwich", 5002).getInt();
	hamsandwichID = config.get("Item IDs", "Ham Sandwich", 5003).getInt();
	supersandwichID = config.get("Item IDs", "Super Sandwich", 5004).getInt();
	chickenbitID = config.get("Item IDs", "Slice of Chicken", 5005).getInt();
	steakbitID = config.get("Item IDs", "Slice of Steak", 5006).getInt();
	porkbitID = config.get("Item IDs", "Slice of Pork", 5007).getInt();
	tomatoseedsID = config.get("Item IDs", "Tomato Seeds", 5008).getInt();
	tomatocropID = config.get("Block IDs", "Tomato Crop", 500).getInt();
	tomatofruitID = config.get("Item IDs", "Tomato Fruit", 5009).getInt();
	rawbaconID = config.get("Item IDs", "Raw Bacon", 5010).getInt();
	cookedbaconID = config.get("Item IDs", "Cooked Bacon", 5011).getInt();
	rawchickenbitID = config.get("Item IDs", "Raw Slice of Chicken", 5012).getInt();
	rawsteakbitID = config.get("Item IDs", "Raw Slice of Beef", 5013).getInt();
	rawporkbitID = config.get("Item IDs", "Raw Slice of Ham", 5014).getInt();
	knifeID = config.get("Item IDs", "Knife", 5015).getInt();
	creamID = config.get("Item IDs", "Bucket of Cream", 5016).getInt();
	lettuceseedsID = config.get("Item IDs", "Lettuce Seeds", 5017).getInt();
	lettuceID = config.get("Item IDs", "Lettuce", 5018).getInt();
	lettucecropID = config.get("Block IDs", "Lettuce Crop", 501).getInt();
	fertilizerID = config.get("Item IDs", "Fertilizer", 5019).getInt();
	manureID = config.get("Item IDs", "Manure", 5020).getInt();
	config.save();
}

@EventHandler
public void load(FMLInitializationEvent event) {
	proxy.register();
	//Items
	breadslice = new ItemME(breadsliceID, "breadslice").setUnlocalizedName("breadslice").setMaxStackSize(64).setCreativeTab(tabMineEdibles);
	chickensandwich = new ItemFoodME(chickensandwichID, 9, 0.8f, false, "chickensandwich").setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("chickensandwich").setMaxStackSize(64).setCreativeTab(tabMineEdibles);
	steaksandwich = new ItemFoodME(steaksandwichID, 9, 0.8f, false, "steaksandwich").setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("steaksandwich").setMaxStackSize(64).setCreativeTab(tabMineEdibles);
	hamsandwich = new ItemFoodME(hamsandwichID, 9, 0.8f, false, "hamsandwich").setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("hamsandwich").setMaxStackSize(64).setCreativeTab(tabMineEdibles);
	supersandwich = new ItemFoodME(supersandwichID, 18, 1.4f, false, "supersandwich").setAlwaysEdible().setPotionEffect(Potion.regeneration.id, 6, 1, 0.8f).setPotionEffect(Potion.moveSpeed.id, 6, 1, 0.8f).setUnlocalizedName("supersandwich").setMaxStackSize(64).setCreativeTab(tabMineEdibles);
	chickenbit = new ItemFoodME(chickenbitID, 2, 0.4f, false, "chickenbit").setUnlocalizedName("chickenbit").setCreativeTab(tabMineEdibles);
	steakbit = new ItemFoodME(steakbitID, 2, 0.4f, false, "steakbit").setUnlocalizedName("steakbit").setCreativeTab(tabMineEdibles);
	porkbit = new ItemFoodME(porkbitID, 2, 0.4f, false, "porkbit").setUnlocalizedName("porkbit").setCreativeTab(tabMineEdibles);
	tomatocrop = new BlockCropME(tomatocropID, "tomatocrop", this.tomatoseedsID, this.tomatocropID, .setUnlocalizedName("tomatocrop");
	tomatoseeds = new ItemSeedsME(tomatoseedsID, tomatocrop.blockID, 60, "tomatoseeds").setUnlocalizedName("tomatoseeds").setCreativeTab(tabMineEdibles);
	tomatofruit = new ItemFoodME(tomatofruitID, 6, 0.8f, false, "tomatofruit").setUnlocalizedName("tomatofruit").setCreativeTab(tabMineEdibles);
	rawbacon = new ItemFoodME(rawbaconID, 3, 0.3f, false, "rawbacon").setUnlocalizedName("baconraw").setCreativeTab(tabMineEdibles);
	cookedbacon = new ItemFoodME(cookedbaconID, 7, 0.6f, false, "cookedbacon").setUnlocalizedName("baconcooked").setCreativeTab(tabMineEdibles);
	rawchickenbit = new ItemFoodME(rawchickenbitID, 1, 0.2f, false, "rawchickenbit").setUnlocalizedName("rawchickenbit").setCreativeTab(tabMineEdibles);
	rawsteakbit = new ItemFoodME(rawsteakbitID, 1, 0.2f, false, "rawsteakbit").setUnlocalizedName("rawsteakbit").setCreativeTab(tabMineEdibles);
	rawporkbit = new ItemFoodME(rawporkbitID, 1, 0.2f, false, "rawporkbit").setUnlocalizedName("rawporkbit").setCreativeTab(tabMineEdibles);
	knife = new ItemME(knifeID, "knifeBlack").setUnlocalizedName("knifeBlack").setMaxStackSize(1).setCreativeTab(tabMineEdibles);
	cream = new ItemCream(creamID, "cream").setUnlocalizedName("cream").setCreativeTab(tabMineEdibles);
	lettucecrop = new BlockCropME(lettucecropID, "lettucecrop", this.lettuceseedsID, this.lettucecropID, 5).setUnlocalizedName("lettucecrop");
	lettuceseeds = new ItemSeedsME(lettuceseedsID, lettucecrop.blockID, 60, "lettuceseeds").setUnlocalizedName("lettuceseeds").setCreativeTab(tabMineEdibles);
	lettuce = new ItemFoodME(lettuceID, 6, 0.8f, false, "lettuce").setUnlocalizedName("lettuce").setCreativeTab(tabMineEdibles);
	fertilizer = new ItemFertilizer(fertilizerID, "fertilizer").setUnlocalizedName("fertilizer").setCreativeTab(tabMineEdibles);
	manure = new ItemME(manureID, "manure").setUnlocalizedName("manure").setCreativeTab(tabMineEdibles);
	MinecraftForge.addGrassSeed(new ItemStack (tomatoseeds), 10);
	gameRegisters();
	languageRegisters();
	craftingRecipes();
	//Smelting
	GameRegistry.addSmelting(MineEdibles.rawbacon.itemID, new ItemStack(MineEdibles.cookedbacon, 1), 0.1f);
	GameRegistry.addSmelting(MineEdibles.rawchickenbit.itemID, new ItemStack(MineEdibles.chickenbit, 1), 0.1f);
	GameRegistry.addSmelting(MineEdibles.rawsteakbit.itemID, new ItemStack(MineEdibles.steakbit, 1), 0.1f);
	GameRegistry.addSmelting(MineEdibles.rawporkbit.itemID, new ItemStack(MineEdibles.porkbit, 1), 0.1f);




}

//Item and Block registeration
private static void gameRegisters(){
	GameRegistry.registerItem(breadslice, "Bread Slice");
	GameRegistry.registerItem(chickensandwich, "Chicken Sandwich");
	GameRegistry.registerItem(steaksandwich, "Steak Sandwich");
	GameRegistry.registerItem(hamsandwich, "Ham Sandwich");
	GameRegistry.registerItem(supersandwich, "Super Sandwich");
	GameRegistry.registerItem(chickenbit, "Slice of Chicken");
	GameRegistry.registerItem(steakbit, "Slice of Steak");
	GameRegistry.registerItem(porkbit, "Slice of Ham");
	GameRegistry.registerItem(tomatoseeds, "Tomato Seeds");
	GameRegistry.registerItem(tomatofruit, "Tomato");
	GameRegistry.registerBlock(tomatocrop, "Tomato Crop");
	GameRegistry.registerItem(rawbacon, "Raw Bacon");
	GameRegistry.registerItem(cookedbacon, "Cooked Bacon");
	GameRegistry.registerItem(rawchickenbit, "Raw Slice of Chicken");
	GameRegistry.registerItem(rawsteakbit, "Raw Slice of Steak");
	GameRegistry.registerItem(rawporkbit, "Raw Slice of Ham");
	GameRegistry.registerItem(knife, "Knife");
	GameRegistry.registerItem(lettuceseeds, "Lettuce Seeds");
	GameRegistry.registerItem(lettuce, "Lettuce Fruit");
	GameRegistry.registerBlock(lettucecrop, "Lettuce Crop");
	GameRegistry.registerItem(fertilizer, "Fertilizer");
	GameRegistry.registerItem(manure, "Manure");

}
//Item and Block in game name, language registry
private static void languageRegisters(){
	LanguageRegistry.addName(breadslice, "Bread Slice");
	LanguageRegistry.addName(chickensandwich, "Chicken Sandwich");
	LanguageRegistry.addName(steaksandwich, "Steak Sandwich");
	LanguageRegistry.addName(hamsandwich, "Ham Sandwich");
	LanguageRegistry.addName(supersandwich, "Super Sandwich");
	LanguageRegistry.addName(chickenbit, "Slice of Chicken");
	LanguageRegistry.addName(steakbit, "Slice of Steak");
	LanguageRegistry.addName(porkbit, "Slice of Ham");
	LanguageRegistry.addName(tomatoseeds, "Tomato Seeds");
	LanguageRegistry.addName(tomatofruit, "Tomato");
	LanguageRegistry.addName(rawbacon, "Raw Bacon");
	LanguageRegistry.addName(cookedbacon, "Cooked Bacon");
	LanguageRegistry.addName(rawchickenbit, "Raw Slice of Chicken");
	LanguageRegistry.addName(rawsteakbit, "Raw Slice of Steak");
	LanguageRegistry.addName(rawporkbit, "Raw Slice of Ham");
	LanguageRegistry.addName(knife, "Knife");
	LanguageRegistry.addName(lettuceseeds, "Lettuce Seeds");
	LanguageRegistry.addName(lettuce, "Lettuce");
	LanguageRegistry.addName(fertilizer, "Fertilizer");
	LanguageRegistry.addName(manure, "Manure");
	LanguageRegistry.instance().addStringLocalization("itemGroup.tabMineEdibles", "en_US", "MineEdibles");
}
//Crafting Recipes
public void craftingRecipes(){
	//Cooked meat slices
	for(int i = 0; i < knife.getMaxDamage(); i++)

	{
		GameRegistry.addShapelessRecipe(new ItemStack(MineEdibles.chickenbit, 3), new Object[]{ItemFood.chickenCooked, (new ItemStack(knife, 1, i))});
	}
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.breadslice, 6), new ItemStack(ItemFood.bread));
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.chickenbit, 3), new Object[]{ItemFood.chickenCooked, (new ItemStack(knife, 1, 0))});
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.steakbit, 3), new Object[]{ItemFood.beefCooked, (new ItemStack(knife, 1, 0))});
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.porkbit, 3), new Object[]{ItemFood.porkCooked, (new ItemStack(knife, 1, 0))});
	//Raw Meat Slices
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawchickenbit, 3), new Object[]{ItemFood.chickenRaw, (new ItemStack(knife, 1, 0))});
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawsteakbit, 3), new Object[]{ItemFood.beefRaw, (new ItemStack(knife, 1, 0))});
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawporkbit, 3), new Object[]{ItemFood.porkRaw, (new ItemStack(knife, 1, 0))});
	//Sandwiches
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawchickenbit, 3), new ItemStack(ItemFood.chickenRaw));
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawsteakbit, 3), new ItemStack(ItemFood.beefRaw));
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawporkbit, 3), new ItemStack(ItemFood.porkRaw));
	GameRegistry.addRecipe(new ItemStack(MineEdibles.chickensandwich, 1), new Object[]{" B ", " C ", " B ", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked });
	GameRegistry.addRecipe(new ItemStack(MineEdibles.steaksandwich, 1), new Object[]{" B ", " S ", " B ", 'B', MineEdibles.breadslice, 'S', ItemFood.beefCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.hamsandwich, 1), new Object[]{" B ", " P ", " B ", 'B', MineEdibles.breadslice, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "SCP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "SPC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
	//creamy goodness
	GameRegistry.addShapelessRecipe(new ItemStack(MineEdibles.cream, 1), new Object []{ItemFood.bucketMilk, ItemFood.sugar});
	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.fertilizer), new Object []{ItemFood.fishRaw, MineEdibles.manure});

}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {

}

 

Link to comment
Share on other sites

Guff is right but his code has mistakes!

 

First everything else 1 which is in the Item class is right.

You should change the - into a + (inside of the getContainerItemStack function) or you get problems^^

But eveything else is wrong what he made!

 

So first you register your item like that:

 

public static Item test = new yourItem(ItemID).setContainerItem(test);

 

now the Recipe!

You do not need to make a for loop. That make only lag. (I know it i made with this way about 2Million Recipes)

Its alot easier!

GameRegistry.addRecipe(new ItemStack(Item.diamond), new Object[]{"X", 'X', new ItemStack(test, 1, OreDictionary.WildCardValue)});

 

The WildCardValue or something like that (look inside of forge ordictionary class for the right name).

Is like 1.4.7 new ItemStack(item, 1,-1) this means he uses any damage he gets.

I hope it helps you,

 

Now to Guff.

You can use ForLoops. But at 100.000 Recipes the craftingtable starts to lag everytime you place or drag an item in/out of the craftingtabel.

 

So why don't you change your recipe because the way i explained makes only 1 recipe instead of how many your ItemDamage is.

Good Luck

Link to comment
Share on other sites

Ya ya, im sure you get ton of these threads, but for some reason this isn't working. Im using forge 1.6.2, and I want an item to take 1 damage out of 64 when used to craft something. I made some code for it but I can only use it 3 times before it won't let me craft anymore but the item still has durability. Thanks for your help.

Base Mod class (the knife item is the one that should be able to be used more than once)

 

package mydeblob.mineedibles;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;

@Mod(modid="mineedibles", name="MineEdibles", version="1.0.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class MineEdibles {


        // The instance of your mod that Forge uses.
        @Instance("Sandwich")
        public static MineEdibles instance;
        private static Item breadslice;
        private static Item chickensandwich;
        private static Item steaksandwich;
        private static Item hamsandwich;
        private static Item supersandwich;
        private static Item chickenbit;
        private static Item steakbit;
        private static Item porkbit;
        public static Item tomatoseeds;
        public static Item tomatofruit;
        public static Block tomatocrop;
        public static Item rawbacon;
        private static Item cookedbacon;
        private static Item rawchickenbit;
        private static Item rawsteakbit;
        private static Item rawporkbit;
        public static Item knife;
        
        //Item Ids for the config file
        int breadsliceID;
        int chickensandwichID;
        int steaksandwichID;
        int hamsandwichID;
        int supersandwichID;
        int chickenbitID;
        int steakbitID;
        int porkbitID;
        int tomatoseedsID;
        int tomatocropID;
        int tomatofruitID;
        int rawbaconID;
        int cookedbaconID;
        int rawchickenbitID;
        int rawsteakbitID;
        int rawporkbitID;
        int knifeID;

        
        // Says where the client and server 'proxy' code is loaded.
        @SidedProxy(clientSide="mydeblob.mineedibles.client.ClientProxy", serverSide="mydeblob.mineedibles.CommonProxy")
        public static CommonProxy proxy;
        
        @EventHandler
        public void preInit(FMLPreInitializationEvent event) {
        	//Basic Configuration file
        	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
        	config.load();
        	breadsliceID = config.get("Item IDs", "Bread Slice", 5000).getInt();
        	chickensandwichID = config.get("Item IDs", "Chicken Sandwich", 5001).getInt();
        	steaksandwichID = config.get("Item IDs", "Steak Sandwich", 5002).getInt();
        	hamsandwichID = config.get("Item IDs", "Ham Sandwich", 5003).getInt();
        	supersandwichID = config.get("Item IDs", "Super Sandwich", 5004).getInt();
        	chickenbitID = config.get("Item IDs", "Slice of Chicken", 5005).getInt();
        	steakbitID = config.get("Item IDs", "Slice of Steak", 5006).getInt();
        	porkbitID = config.get("Item IDs", "Slice of Pork", 5007).getInt();
        	tomatoseedsID = config.get("Item IDs", "Tomato Seeds", 5008).getInt();
        	tomatofruitID = config.get("Item IDs", "Tomato Fruit", 5009).getInt();
        	rawbaconID = config.get("Item IDs", "Raw Bacon", 50010).getInt();
        	cookedbaconID = config.get("Item IDs", "Cooked Bacon", 5011).getInt();
        	rawchickenbitID = config.get("Item IDs", "Raw Slice of Chicken", 5012).getInt();
        	rawsteakbitID = config.get("Item IDs", "Raw Slice of Beef", 5013).getInt();
        	rawporkbitID = config.get("Item IDs", "Raw Slice of Ham", 5014).getInt();
        	knifeID = config.get("Item IDs", "Knife", 5015).getInt();
        	config.save();
        }
        
        @EventHandler
        public void load(FMLInitializationEvent event) {
                proxy.registerRenderers();
                //Items
               breadslice = new Item(breadsliceID).setUnlocalizedName("breadslice").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:slicebread");
               chickensandwich = new ItemFood(chickensandwichID, 9, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("chickensandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:chickensandwich");
               steaksandwich = new ItemFood(steaksandwichID, 9, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("steaksandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:steaksandwich");
               hamsandwich = new ItemFood(hamsandwichID, 9, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("hamsandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:hamsandwich");
               supersandwich = new ItemFood(supersandwichID, 18, 1.4f, false).setAlwaysEdible().setPotionEffect(Potion.regeneration.id, 6, 1, 0.8f).setPotionEffect(Potion.moveSpeed.id, 6, 1, 0.8f).setUnlocalizedName("supersandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:supersandwich");
               chickenbit = new ItemFood(chickenbitID, 2, 0.4f, false).setUnlocalizedName("chickenbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:chickenbit");
               steakbit = new ItemFood(steakbitID, 2, 0.4f, false).setUnlocalizedName("steakbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:steakbit");
               porkbit = new ItemFood(porkbitID, 2, 0.4f, false).setUnlocalizedName("porkbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:porkbit");
               tomatocrop = new TomatoCrop(tomatocropID).setUnlocalizedName("tomatocrop").func_111022_d("mineedibles:tomatocrop");
               tomatoseeds = new ItemSeeds(tomatoseedsID, tomatocrop.blockID, Block.tilledField.blockID).setUnlocalizedName("tomatoseeds").func_111206_d("mineedibles:tomatoseeds");
               tomatofruit = new ItemFood(tomatofruitID, 6, 0.8f, false).setUnlocalizedName("tomatofruit").func_111206_d("mineedibles:tomatofruit");
               rawbacon = new ItemFood(rawbaconID, 3, 0.3f, false).setUnlocalizedName("baconraw").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawbacon");
               cookedbacon = new ItemFood(cookedbaconID, 7, 0.6f, false).setUnlocalizedName("baconcooked").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:cookedbacon");
               rawchickenbit = new ItemFood(rawchickenbitID, 1, 0.2f, false).setUnlocalizedName("rawchickenbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawchickenbit");
               rawsteakbit = new ItemFood(rawsteakbitID, 1, 0.2f, false).setUnlocalizedName("rawsteakbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawsteakbit");
               rawporkbit = new ItemFood(rawporkbitID, 1, 0.2f, false).setUnlocalizedName("rawporkbit").setCreativeTab(CreativeTabs.tabFood).func_111206_d("mineedibles:rawporkbit");
               knife = new Item(knifeID).setUnlocalizedName("knife").setMaxDamage(64).setMaxStackSize(1).setCreativeTab(CreativeTabs.tabTools).func_111206_d("mineedibles:knifeBlack");
               MinecraftForge.addGrassSeed(new ItemStack (tomatoseeds), 10);
               gameRegisters();
               languageRegisters();
               craftingRecipes();
               	//Smelting
               GameRegistry.addSmelting(MineEdibles.rawbacon.itemID, new ItemStack(MineEdibles.cookedbacon, 1), 0.1f);
               GameRegistry.addSmelting(MineEdibles.rawchickenbit.itemID, new ItemStack(MineEdibles.chickenbit, 1), 0.1f);
               GameRegistry.addSmelting(MineEdibles.rawsteakbit.itemID, new ItemStack(MineEdibles.steakbit, 1), 0.1f);
               GameRegistry.addSmelting(MineEdibles.rawporkbit.itemID, new ItemStack(MineEdibles.porkbit, 1), 0.1f);




        }

        //Item and Block registeration
        private static void gameRegisters(){
        	GameRegistry.registerItem(breadslice, "Bread Slice");
        	GameRegistry.registerItem(chickensandwich, "Chicken Sandwich");
        	GameRegistry.registerItem(steaksandwich, "Steak Sandwich");
        	GameRegistry.registerItem(hamsandwich, "Ham Sandwich");
        	GameRegistry.registerItem(supersandwich, "Super Sandwich");
        	GameRegistry.registerItem(chickenbit, "Slice of Chicken");
        	GameRegistry.registerItem(steakbit, "Slice of Steak");
        	GameRegistry.registerItem(porkbit, "Slice of Ham");
        	GameRegistry.registerItem(tomatoseeds, "Tomato Seeds");
        	GameRegistry.registerItem(tomatofruit, "Tomato");
        	GameRegistry.registerBlock(tomatocrop, "Tomato Crop");
        	GameRegistry.registerItem(rawbacon, "Raw Bacon");
        	GameRegistry.registerItem(cookedbacon, "Cooked Bacon");
        	GameRegistry.registerItem(rawchickenbit, "Raw Slice of Chicken");
        	GameRegistry.registerItem(rawsteakbit, "Raw Slice of Steak");
        	GameRegistry.registerItem(rawporkbit, "Raw Slice of Ham");
        	GameRegistry.registerItem(knife, "Knife");
        	GameRegistry.registerCraftingHandler(new KnifeCraftingHandler());
        }
        //Item and Block in game name, languageregistry
        private static void languageRegisters(){
        	LanguageRegistry.addName(breadslice, "Bread Slice");
        	LanguageRegistry.addName(chickensandwich, "Chicken Sandwich");
        	LanguageRegistry.addName(steaksandwich, "Steak Sandwich");
        	LanguageRegistry.addName(hamsandwich, "Ham Sandwich");
        	LanguageRegistry.addName(supersandwich, "Super Sandwich");
        	LanguageRegistry.addName(chickenbit, "Slice of Chicken");
        	LanguageRegistry.addName(steakbit, "Slice of Steak");
        	LanguageRegistry.addName(porkbit, "Slice of Ham");
        	LanguageRegistry.addName(tomatoseeds, "Tomato Seeds");
        	LanguageRegistry.addName(tomatofruit, "Tomato");
        	LanguageRegistry.addName(rawbacon, "Raw Bacon");
        	LanguageRegistry.addName(rawchickenbit, "Raw Slice of Chicken");
        	LanguageRegistry.addName(rawsteakbit, "Raw Slice of Steak");
        	LanguageRegistry.addName(rawporkbit, "Raw Slice of Ham");
        	LanguageRegistry.addName(knife, "Knife");
        }
        //Crafting Recipes
        public void craftingRecipes(){
        	//Cooked meat slices
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.breadslice, 6), new ItemStack(ItemFood.bread));
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.chickenbit, 3), new Object[]{ItemFood.chickenCooked, (new ItemStack(knife, 1, 0 ))});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.steakbit, 3), new Object[]{ItemFood.beefCooked, (new ItemStack(knife, 1, 0))});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.porkbit, 3), new Object[]{ItemFood.porkCooked, (new ItemStack(knife, 1, 0))});
        	//Raw Meat Slices
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawchickenbit, 3), new Object[]{ItemFood.chickenRaw, (new ItemStack(knife, 1, 0))});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawsteakbit, 3), new Object[]{ItemFood.beefRaw, (new ItemStack(knife, 1, 0))});
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawporkbit, 3), new Object[]{ItemFood.porkRaw, (new ItemStack(knife, 1, 0))});
        	//Sandwiches
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawchickenbit, 3), new ItemStack(ItemFood.chickenRaw));
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawsteakbit, 3), new ItemStack(ItemFood.beefRaw));
        	GameRegistry.addShapelessRecipe(new ItemStack (MineEdibles.rawporkbit, 3), new ItemStack(ItemFood.porkRaw));
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.chickensandwich, 1), new Object[]{" B ", " C ", " B ", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked });
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.steaksandwich, 1), new Object[]{" B ", " S ", " B ", 'B', MineEdibles.breadslice, 'S', ItemFood.beefCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.hamsandwich, 1), new Object[]{" B ", " P ", " B ", 'B', MineEdibles.breadslice, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "SCP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "SPC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(MineEdibles.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', MineEdibles.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        
        	
        }
        @EventHandler
        public void postInit(FMLPostInitializationEvent event) {
                
        }
}

 

CraftingHandlerClass for the Item Knife

 

package mydeblob.mineedibles;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.ICraftingHandler;

public class KnifeCraftingHandler implements ICraftingHandler {

@Override
public void onCrafting(EntityPlayer player, ItemStack item,
		IInventory craftMatrix) {
	for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {

		if (craftMatrix.getStackInSlot(i) != null) {
			ItemStack j = craftMatrix.getStackInSlot(i);

			if (j.getItem() != null && j.getItem() == MineEdibles.knife) {
				ItemStack k = new ItemStack(MineEdibles.knife, 2, (j.getItemDamage() + 1));

				if (k.getItemDamage() >= k.getMaxDamage()) {
					k.stackSize--;
				}
				craftMatrix.setInventorySlotContents(i, k);
			}
		}
	}

}

@Override
public void onSmelting(EntityPlayer player, ItemStack item) {
	// TODO Auto-generated method stub

}

}

 

 

Ok look here buddy. I'm going to rock your world just use this. The code is a bit outdated but it should work mostly. Hope it works!

 

Crafting Handler:

package cyphereion.mods.patches.yogpack;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.ICraftingHandler;

public class CraftingHandler implements ICraftingHandler {
@Override
public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) {
	for (int i = 0; i < craftMatrix.getSizeInventory(); i++)
	{
		if (craftMatrix.getStackInSlot(i) != null)
		{
			ItemStack j = craftMatrix.getStackInSlot(i);
			if (j.getItem() != null && j.getItem() == ITEM) 
			{
				ItemStack k = new ItemStack(ITEM, 2, (j.getItemDamage() + 1)); 
				if (k.getItemDamage() >= k.getMaxDamage()) { 
					k.stackSize--; 
				}
				craftMatrix.setInventorySlotContents(i, k);
			}
		}
	}

}


@Override
public void onSmelting(EntityPlayer player, ItemStack item) {
}
}

 

Item Class (Just for reference):

package cyphereion.mods.patches.yogpack;

import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class ItemTransmorgrificationCrystal extends Item {
private int index;
public ItemTransmorgrificationCrystal(int par1, int index)
{
	super(par1);
	this.index = index;
	this.setMaxStackSize(1);
	this.setMaxDamage(150);
	this.setCreativeTab(CreativeTabs.tabMaterials);
}
@SideOnly(Side.CLIENT)
public String getTextureFile(){
	return "/cyphereion/mods/patches/yogpack/Cyphereion.png";
}

public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
	par3List.add("Stone brick to hold it together.");
	par3List.add("Obsidian to make it tough to break");
	par3List.add("Diamond for good looks.");
}

@SideOnly(Side.CLIENT)
public int getIconFromDamage(int i){
	return index;
}

}

 

 

Recipes:

GameRegistry.addShapelessRecipe(new ItemStack(TransmorgrificationCrystal, 1, 0), Block.stoneBrick, Block.stoneBrick, Block.stoneBrick, Block.stoneBrick, Block.obsidian, Block.obsidian, Block.obsidian, Block.obsidian, Item.diamond);

GameRegistry.addRecipe(new ItemStack(Item.blazeRod, 7),new Object[] { "OTG",'O', Block.obsidian, 'G', Block.blockGold, 'T', (new ItemStack(TransmorgrificationCrystal,1,-1))});

Link to comment
Share on other sites

@deadrecon98, did you even read his post? you posted exactly the same code he was already using

 

@OP

just do a combination of what guff and moritz said. don't use a crafting handler since you don't need one. use hasContainerItem and getContainerItemStack like guff said. and like moritz said, you don't need the for loop when registering the recipe. but, you don't need to register the item in the way moritz suggested since you're already overriding getContainerItemStack(ItemStack).

 

anyway, wrote the following to make absolutely sure it works and it does. just replace the stuff there with what you need. if you want it to stay in the crafting grid, use doesContainerItemLeaveCraftingGrid(ItemStack)

 

package pelep.zzzzz;

import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;

@Mod(modid = "ZZZZZ", name = "ZZZZZ", version = "ZZZZZ")

public class ZZZZZ
{
@Instance("ZZZZZ")
public static ZZZZZ instance;

@EventHandler
public void init(FMLInitializationEvent e)
{
	GameRegistry.registerItem(new ItemDamageable(ID), "itemDamageable");
	GameRegistry.addRecipe(new ItemStack(1, 1, 0), new Object[] {"d", 'd', new ItemStack(IDSHIFTEDINDEX, 1, OreDictionary.WILDCARD_VALUE)});
}
}

 

package pelep.zzzzz;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class ItemDamageable extends Item
{
public ItemDamageable(int id)
{
	super(id);
	this.setMaxDamage(64);
}

@Override
public boolean hasContainerItem()
{
	return true;
}

@Override
public ItemStack getContainerItemStack(ItemStack ist)
{
	ist.setItemDamage(ist.getItemDamage() + 1);

	if (ist.getItemDamage() > ist.getMaxDamage())
	{
		ist = null;
	}

	return ist;
}
}

Link to comment
Share on other sites

I did this with an item that has 2048 max damage just to help him, and it doesn't make the crafting table lag. The only time it lags is if you shift-click the output.

 

I Said at 100.000 recipes everything what the craftingManager uses start to lag!

But 2048 recipes are to much!

 

Link to comment
Share on other sites

package pelep.zzzzz;
@Override
public ItemStack getContainerItemStack(ItemStack ist)
{
	ist.setItemDamage(ist.getItemDamage() + 1);

	if (ist.getItemDamage() > ist.getMaxDamage())
	{
		ist = null;
	}

	return ist;
}

Don't return a null itemstack. I attempted that at first but I had him change it since it was giving a NPE. The crafting bench attempts to check for item damage already for some reason, and if you return null and it tries to check it, it doesn't protect itself against NPE. Damaging the item and returning the stack will suffice. If you didn't get a NPE then that's just weird because I had to trace it back to this and remove setting the return to null.

Link to comment
Share on other sites

well, to be honest, i didn't test it all the way until the item went past the max damage.. kinda got too lazy. lol. anyway, just checked it now and you're right.

 

@OP

just take this part out

	if (ist.getItemDamage() > ist.getMaxDamage())
	{
		ist = null;
	}

Link to comment
Share on other sites

well, to be honest, i didn't test it all the way until the item went past the max damage.. kinda got too lazy. lol. anyway, just checked it now and you're right.

 

@OP

just take this part out

	if (ist.getItemDamage() > ist.getMaxDamage())
	{
		ist = null;
	}

 

Yeah lol I kept trying it with something similar and I took it out and it worked.

Link to comment
Share on other sites

@deadrecon98, did you even read his post? you posted exactly the same code he was already using

 

@OP

just do a combination of what guff and moritz said. don't use a crafting handler since you don't need one. use hasContainerItem and getContainerItemStack like guff said. and like moritz said, you don't need the for loop when registering the recipe. but, you don't need to register the item in the way moritz suggested since you're already overriding getContainerItemStack(ItemStack).

 

anyway, wrote the following to make absolutely sure it works and it does. just replace the stuff there with what you need. if you want it to stay in the crafting grid, use doesContainerItemLeaveCraftingGrid(ItemStack)

 

package pelep.zzzzz;

import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;

@Mod(modid = "ZZZZZ", name = "ZZZZZ", version = "ZZZZZ")

public class ZZZZZ
{
@Instance("ZZZZZ")
public static ZZZZZ instance;

@EventHandler
public void init(FMLInitializationEvent e)
{
	GameRegistry.registerItem(new ItemDamageable(ID), "itemDamageable");
	GameRegistry.addRecipe(new ItemStack(1, 1, 0), new Object[] {"d", 'd', new ItemStack(IDSHIFTEDINDEX, 1, OreDictionary.WILDCARD_VALUE)});
}
}

 

package pelep.zzzzz;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class ItemDamageable extends Item
{
public ItemDamageable(int id)
{
	super(id);
	this.setMaxDamage(64);
}

@Override
public boolean hasContainerItem()
{
	return true;
}

@Override
public ItemStack getContainerItemStack(ItemStack ist)
{
	ist.setItemDamage(ist.getItemDamage() + 1);

	if (ist.getItemDamage() > ist.getMaxDamage())
	{
		ist = null;
	}

	return ist;
}
}

 

It doesn't matter how you do it because I know for a fact my way works. It may just take a little tweaking but it is working fine for me.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm developing a dimension, but it's kinda resource intensive so some times during player teleporting it lags behind making the player phase down into the void, so im trying to implement some kind of pregeneration to force the game loading a small set of chunks in the are the player will teleport to. Some of the things i've tried like using ServerLevel and ServerChunkCache methods like getChunk() dont actually trigger chunk generation if the chunk isn't already on persistent storage (already generated) or placing tickets, but that doesn't work either. Ideally i should be able to check when the task has ended too. I've peeked around some pregen engines, but they're too complex for my current understanding of the system of which I have just a basic understanding (how ServerLevel ,ServerChunkCache  and ChunkMap work) of. Any tips or other classes I should be looking into to understand how to do this correctly?
    • https://mclo.gs/4UC49Ao
    • Way back in the Forge 1.17 days, work started for adding JPMS (Java Platform Module Support) to ModLauncher and ForgeModLoader. This has been used internally by Forge and some libraries for a while now, but mods (those with mods.toml specifically) have not been able to take advantage of it. As of Forge 1.21.1 and 1.21.3, this is now possible!   What is JPMS and what does it mean for modders? JPMS is the Java Platform Module System, introduced in Java 9. It allows you to define modules, which are collections of packages and resources that can be exported or hidden from other modules. This allows for much more fine-tuned control over visibility, cleaner syntax for service declarations and support for sealed types across packages. For example, you might have a mod with a module called `com.example.mod` that exports `com.example.mod.api` and `com.example.mod.impl` to other mods, but hides `com.example.mod.internal` from them. This would allow you to have a clean API for other mods to use, while keeping your internal implementation details hidden from IDE hints, helping prevent accidental usage of internals that might break without prior notice. This is particularly useful if you'd like to use public records with module-private constructors or partially module-private record components, as you can create a sealed interface that only your record implements, having the interface be exported and the record hidden. It's also nice for declaring and using services, as you'll get compile-time errors from the Java compiler for typos and the like, rather than deferring to runtime errors. In more advanced cases, you can also have public methods that are only accessible to specific other modules -- handy if you want internal interactions between multiple of your own mods.   How do I bypass it? We understand there may be drama in implementing a system that prevents mods from accessing each other's internals when necessary (like when a mod is abandoned or you need to fix a compat issue) -- after all, we are already modding a game that doesn't have explicit support for Java mods yet. We have already thought of this and are offering APIs from day one to selectively bypass module restrictions. Let me be clear: Forge mods are not required to use JPMS. If you don't want to use it, you don't have to. The default behaviour is to have fully open, fully exported automatic modules. In Java, you can use the `Add-Opens` and `Add-Exports` manifest attributes to selectively bypass module restrictions of other mods at launch time, and we've added explicit support for these when loading your Forge mods. At compile-time, you can use existing solutions such as the extra-java-module-info Gradle plugin to deal with non-modular dependencies and add extra opens and exports to other modules. Here's an example on how to make the internal package `com.example.examplemod.internal` open to your mod in your build.gradle: tasks.named('jar', Jar) { manifest { attributes([ 'Add-Opens' : 'com.example.examplemod/com.example.examplemod.internal' 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors // (...) ]) } } With the above in your mod's jar manifest, you can now reflectively access the classes inside that internal package. Multiple entries are separated with a space, as per Java's official spec. You can also use Add-Exports to directly call without reflection, however you'd need to use the Gradle plugin mentioned earlier to be able to compile. The syntax for Add-Exports is the same as Add-Opens, and instructions for the compile-time step with the Gradle plugin are detailed later in this post. Remember to prefer the opens and exports keywords inside module-info.java for sources you control. The Add-Opens/Add-Exports attributes are only intended for forcing open other mods.   What else is new with module support? Previously, the runtime module name was always forced to the first mod ID in your `mods.toml` file and all packages were forced fully open and exported. Module names are now distinguished from mod IDs, meaning the module name in your module-info.java can be different from the mod ID in your `mods.toml`. This allows you to have a more descriptive module name that doesn't have to be the same as your mod ID, however we strongly recommend including your mod ID as part of your module name to aid troubleshooting. The `Automatic-Module-Name` manifest attribute is now also honoured, allowing you to specify a module name for your mod without needing to create a `module-info.java` file. This is particularly useful for mods that don't care about JPMS features but want to have a more descriptive module name and easier integration with other mods that do use JPMS.   How do I use it? The first step is to create a `module-info.java` file in your mod's source directory. This file should be in the same package as your main mod class, and should look something like this: open module com.example.examplemod { requires net.minecraftforge.eventbus; requires net.minecraftforge.fmlcore; requires net.minecraftforge.forge; requires net.minecraftforge.javafmlmod; requires net.minecraftforge.mergetool.api; requires org.slf4j; requires logging; } For now, we're leaving the whole module open to reflection, which is a good starting point. When we know we want to close something off, we can remove the open modifier from the module and open or export individual packages instead. Remember that you need to be open to Forge (module name net.minecraftforge.forge), otherwise it can't call your mod's constructor. Next is fixing modules in Gradle. While Forge and Java support modules properly, Gradle does not put automatic modules on the module path by default, meaning that the logging module (from com.mojang:logging) is not found. To fix this, add the Gradle plugin and add a compile-time module definition for that Mojang library: plugins { // (...) id 'org.gradlex.extra-java-module-info' version "1.9" } // (...) extraJavaModuleInfo { failOnMissingModuleInfo = false automaticModule("com.mojang:logging", "logging") } The automatic module override specified in your build.gradle should match the runtime one to avoid errors. You can do the same for any library or mod dependency that is missing either a module-info or explicit Automatic-Module-Name, however be aware that you may need to update your mod once said library adds one. That's all you need to get started with module support in your mods. You can learn more about modules and how to use them at dev.java.
    • Faire la mise à jour grâce à ce lien m'a aider personnellement, merci à @Paint_Ninja. https://www.amd.com/en/support 
    • When I came across the 'Exit Code: I got a 1 error in my Minecraft mods, so I decided to figure out what was wrong. First, I took a look at the logs. In the mods folder (usually where you'd find logs or crash reports), I found the latest.log file or the corresponding crash report. I read it through carefully, looking for any lines with errors or warnings. Then I checked the Minecraft Forge support site, where you can often find info on what causes errors and how to fix them. I then disabled half of my mods and tried running the game. If the error disappeared, it meant that the problem was with the disabled mod. I repeated this several times to find the problem mod.
  • Topics

×
×
  • Create New...

Important Information

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