Jump to content

Recommended Posts

Posted

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

}

}

 

Posted

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.

Posted

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

Posted

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) {

}

 

Posted

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;
}

Posted

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) {

}

 

Posted

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

Posted

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.

Posted

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))});

Posted

@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;
}
}

Posted

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!

 

Posted

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.

Posted

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;
	}

Posted

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.

Posted

@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.

Posted

...you completely missed the point, so forget it. anyway, i never said crafting handlers wouldn't work. i just said they were unnecessary in his case

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
  • Topics

×
×
  • Create New...

Important Information

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