Jump to content

How to use tools in a crafting recipe


sefodopo

Recommended Posts

(I'm not sure if I understood your question.) If you want the recipe to accept any damage value then use OreDictionary.WILDCARD_VALUE in dmg of ItemStack in the recipe.

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

(I'm not sure if I understood your question.) If you want the recipe to accept any damage value then use OreDictionary.WILDCARD_VALUE in dmg of ItemStack in the recipe.

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

EE3 (Equilant Exchange 3)

Does have the easiest way i know:

 

Look at this mod.

 

These Classes Are important:

ModItems

ItemMiniumstone

 

Look what he is doing with ContainerItem.

 

I mean these functions are needed:

ModItems: SetContainerItem,

ItemMiniumStone: GetContainerItemStack

 

with that you should get what you need^^

Link to comment
Share on other sites

EE3 (Equilant Exchange 3)

Does have the easiest way i know:

 

Look at this mod.

 

These Classes Are important:

ModItems

ItemMiniumstone

 

Look what he is doing with ContainerItem.

 

I mean these functions are needed:

ModItems: SetContainerItem,

ItemMiniumStone: GetContainerItemStack

 

with that you should get what you need^^

Link to comment
Share on other sites

What I mean is I have an Item that is used only in crafting recipes but when I craft with that Item I have a handler that checks if my Item is in the crafting table then it adds damage to my Item and it shows the damage in Minecraft but when I use It up it doesn't break any suggestions?

Mine.java:

package sefodopo.mine;


import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.common.Mod;
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;

@Mod(modid="sefodopoMine", name="Mine", version="1.0.1")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class Mine {
final static Item mineGrind = new mainItem(5000, 64, "mineGrind").setMaxDamage(64).setNoRepair();
public static int mineGrindID = mineGrind.itemID;
public static CreativeTabs mineMain = new CreativeTabs("mineMain") {
        public ItemStack getIconItemStack() {
                return new ItemStack(mineGrind, 1, 0);
        }
};
        // The instance of your mod that Forge uses.
        @Instance("Generic")
        public static Mine instance;
       
        // Says where the client and server 'proxy' code is loaded.
        @SidedProxy(clientSide="sefodopo.mine.client.ClientProxy", serverSide="sefodopo.mine.CommonProxy")
        public static CommonProxy proxy;
       
        @PreInit
        public void preInit(FMLPreInitializationEvent event) {
                // Stub Method
        }
       
        @Init
        public void load(FMLInitializationEvent event) {
                proxy.registerRenderers();
                LanguageRegistry.instance().addStringLocalization("itemGroup.mineMain", "en_US", "Mine");
                LanguageRegistry.addName(mineGrind, "Grind");
                mineGrind.setCreativeTab(mineMain);
                recipes();
                GameRegistry.registerCraftingHandler(new craftingHandler());
        }
       
        private void recipes() {
		GameRegistry.addRecipe(new ItemStack(mineGrind), "xxx", "xxx", "xxx", 'x', new ItemStack(Block.gravel));
		GameRegistry.addShapelessRecipe(new ItemStack(Block.sand, 3), new ItemStack(Block.dirt), new ItemStack(mineGrind, 1, OreDictionary.WILDCARD_VALUE));
		GameRegistry.addShapelessRecipe(new ItemStack(Block.sand, 5), new ItemStack(Block.cobblestone), new ItemStack(mineGrind), new ItemStack(mineGrind, 1, OreDictionary.WILDCARD_VALUE));
		GameRegistry.addShapelessRecipe(new ItemStack(Block.sand, 3), new ItemStack(Block.gravel), new ItemStack(mineGrind, 1, OreDictionary.WILDCARD_VALUE));
		GameRegistry.addShapelessRecipe(new ItemStack(Item.silk), new ItemStack(Block.cloth, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(mineGrind, 1, OreDictionary.WILDCARD_VALUE));
	}

	@PostInit
        public void postInit(FMLPostInitializationEvent event) {
                // Stub Method
        }
}

mainItem.java:

package sefodopo.mine;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class mainItem extends Item {
public mainItem(int par1, int maxStackSize, String Name, Item item) {
	super(par1);
	setMaxStackSize(maxStackSize);
	setUnlocalizedName(Name);
	setContainerItem(item);

}
public mainItem(int par1, int maxStackSize, String Name) {
	super(par1);
	setMaxStackSize(maxStackSize);
	setUnlocalizedName(Name);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) {
	this.itemIcon=iconRegister.registerIcon("sefodopo:mineGrind");
}

}

craftingHandler.java:

package sefodopo.mine;

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 inv) {
	// TODO Auto-generated method stub
	 for(int i=0; i < inv.getSizeInventory(); i++)
	  {
	   if(inv.getStackInSlot(i) != null)
	   {
	    ItemStack j = inv.getStackInSlot(i);
	    if(j.getItem() != null && j.getItem() == Mine.mineGrind)
	    {
	     ItemStack k = new ItemStack(Mine.mineGrind, 2, (j.getItemDamage() + 1));//makes 2 items, 1 that is used and 1 that is damaged
	      inv.setInventorySlotContents(i, k);//i is slot, k is Item
	     }
	    }
	   }
	  }


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

}

}

Link to comment
Share on other sites

What I mean is I have an Item that is used only in crafting recipes but when I craft with that Item I have a handler that checks if my Item is in the crafting table then it adds damage to my Item and it shows the damage in Minecraft but when I use It up it doesn't break any suggestions?

Mine.java:

package sefodopo.mine;


import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.common.Mod;
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;

@Mod(modid="sefodopoMine", name="Mine", version="1.0.1")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class Mine {
final static Item mineGrind = new mainItem(5000, 64, "mineGrind").setMaxDamage(64).setNoRepair();
public static int mineGrindID = mineGrind.itemID;
public static CreativeTabs mineMain = new CreativeTabs("mineMain") {
        public ItemStack getIconItemStack() {
                return new ItemStack(mineGrind, 1, 0);
        }
};
        // The instance of your mod that Forge uses.
        @Instance("Generic")
        public static Mine instance;
       
        // Says where the client and server 'proxy' code is loaded.
        @SidedProxy(clientSide="sefodopo.mine.client.ClientProxy", serverSide="sefodopo.mine.CommonProxy")
        public static CommonProxy proxy;
       
        @PreInit
        public void preInit(FMLPreInitializationEvent event) {
                // Stub Method
        }
       
        @Init
        public void load(FMLInitializationEvent event) {
                proxy.registerRenderers();
                LanguageRegistry.instance().addStringLocalization("itemGroup.mineMain", "en_US", "Mine");
                LanguageRegistry.addName(mineGrind, "Grind");
                mineGrind.setCreativeTab(mineMain);
                recipes();
                GameRegistry.registerCraftingHandler(new craftingHandler());
        }
       
        private void recipes() {
		GameRegistry.addRecipe(new ItemStack(mineGrind), "xxx", "xxx", "xxx", 'x', new ItemStack(Block.gravel));
		GameRegistry.addShapelessRecipe(new ItemStack(Block.sand, 3), new ItemStack(Block.dirt), new ItemStack(mineGrind, 1, OreDictionary.WILDCARD_VALUE));
		GameRegistry.addShapelessRecipe(new ItemStack(Block.sand, 5), new ItemStack(Block.cobblestone), new ItemStack(mineGrind), new ItemStack(mineGrind, 1, OreDictionary.WILDCARD_VALUE));
		GameRegistry.addShapelessRecipe(new ItemStack(Block.sand, 3), new ItemStack(Block.gravel), new ItemStack(mineGrind, 1, OreDictionary.WILDCARD_VALUE));
		GameRegistry.addShapelessRecipe(new ItemStack(Item.silk), new ItemStack(Block.cloth, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(mineGrind, 1, OreDictionary.WILDCARD_VALUE));
	}

	@PostInit
        public void postInit(FMLPostInitializationEvent event) {
                // Stub Method
        }
}

mainItem.java:

package sefodopo.mine;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class mainItem extends Item {
public mainItem(int par1, int maxStackSize, String Name, Item item) {
	super(par1);
	setMaxStackSize(maxStackSize);
	setUnlocalizedName(Name);
	setContainerItem(item);

}
public mainItem(int par1, int maxStackSize, String Name) {
	super(par1);
	setMaxStackSize(maxStackSize);
	setUnlocalizedName(Name);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) {
	this.itemIcon=iconRegister.registerIcon("sefodopo:mineGrind");
}

}

craftingHandler.java:

package sefodopo.mine;

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 inv) {
	// TODO Auto-generated method stub
	 for(int i=0; i < inv.getSizeInventory(); i++)
	  {
	   if(inv.getStackInSlot(i) != null)
	   {
	    ItemStack j = inv.getStackInSlot(i);
	    if(j.getItem() != null && j.getItem() == Mine.mineGrind)
	    {
	     ItemStack k = new ItemStack(Mine.mineGrind, 2, (j.getItemDamage() + 1));//makes 2 items, 1 that is used and 1 that is damaged
	      inv.setInventorySlotContents(i, k);//i is slot, k is Item
	     }
	    }
	   }
	  }


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

}

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

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

×   Your previous content has been restored.   Clear editor

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



×
×
  • Create New...

Important Information

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