ps_psycho Posted December 23, 2012 Posted December 23, 2012 Hello everyone. I'am aware that there are several of these posts already on the forums, but none of them are working for me. I am trying to make a saw that get's damaged when its crafted, and its just not working. Whenever I craft with the Item it dissapears. I am using Forge 471 for 1.4.6. Here is my code : Base Mod File package psychocraft.common; 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.ItemStack; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid = "ps_psycho_psychocraft", name = "Psychocraft", version = "0.01") @NetworkMod(clientSideRequired = true, serverSideRequired = false) public class PsychocraftMain { //blocks public static Block asphalt; public static Block SmoothR; //Items public static Item Tar; public static Item SawI; @SidedProxy(clientSide = "psychocraft.common.ClientProxyPsychocraft", serverSide = "psychocraft.common.CommonProxyPsychocraft") public static CommonProxyPsychocraft proxy; @Init public void load(FMLInitializationEvent event) { proxy.registerRenderThings(); //crafting handler //blocks asphalt = new BlockAsphalt(1538, 0, Material.sand, 1.06F).setBlockName("asphalt").setHardness(0.5F).setStepSound(Block.soundGravelFootstep).setCreativeTab(CreativeTabs.tabTransport); SmoothR = new BlockAsphalt(1539, 1, Material.sand, 1.10F).setBlockName("SR").setHardness(0.5F).setStepSound(Block.soundStoneFootstep).setCreativeTab(CreativeTabs.tabTransport); //items final Item Tar = new ItemTar(5001).setMaxStackSize(64).setCreativeTab(CreativeTabs.tabMaterials) .setIconIndex(0).setItemName("Tar"); final Item SawI = new ItemSaw(5002).setMaxStackSize(64).setCreativeTab(CreativeTabs.tabMaterials) .setIconIndex(1).setItemName("SawI").setMaxDamage(10); //Efectivity MinecraftForge.setBlockHarvestLevel(asphalt, "shovel", 0); //Registry //Blocks GameRegistry.registerBlock(asphalt, "Asphalt"); GameRegistry.registerBlock(SmoothR, "SmoothR"); GameRegistry.registerCraftingHandler(new SawCraftingHandler()); //names LanguageRegistry.addName(asphalt, "Asphalt Road"); LanguageRegistry.addName(Tar, "Tar Ball"); LanguageRegistry.addName(SawI, "Iron Saw"); //crafting GameRegistry.addRecipe(new ItemStack(SmoothR, 1), "xxx", "xxx", "xxx", 'x', new ItemStack(Tar)); GameRegistry.addRecipe(new ItemStack(SawI, 1), "xii","xi ", 'x', new ItemStack(Item.stick), 'i', new ItemStack(Item.ingotIron)); GameRegistry.addShapelessRecipe(new ItemStack(Tar, 6), new ItemStack(SawI), new ItemStack(Block.wood, 0)); //smelting GameRegistry.addSmelting(Block.gravel.blockID, new ItemStack(asphalt), 0.5f); } } SawCraftingHandle.class: package psychocraft.common; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import cpw.mods.fml.common.ICraftingHandler; public class SawCraftingHandler implements ICraftingHandler { @Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory inv) { for(int i=0; i < inv.getSizeInventory(); i++) { if(inv.getStackInSlot(i) != null) { ItemStack j = inv.getStackInSlot(i); if(j.getItem() != null && j.getItem() == PsychocraftMain.SawI) { ItemStack k = new ItemStack(PsychocraftMain.SawI, 2, (j.getItemDamage() + 1)); inv.setInventorySlotContents(i, k); } } } } @Override public void onSmelting(EntityPlayer player, ItemStack item) { // TODO Auto-generated method stub } } Could someone tell me what I am doing wrong? All Help is much apriciated. Quote
Chibill Posted December 23, 2012 Posted December 23, 2012 unless you make your own block to craft with it it will disapper because it was took to craft the item. Quote
vdvman1 Posted December 23, 2012 Posted December 23, 2012 You can use a crafting handler, I have never used them myself so I can't tell you how to use one Quote
nickfromgreek Posted December 23, 2012 Posted December 23, 2012 just make a crafting handler: 1st register it: GameRegistry.registerCraftingHandler(new yourcraftinghandlerclassname()); import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import cpw.mods.fml.common.ICraftingHandler; public class DamageCraftingHandler implements ICraftingHandler{ @Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory inv) { for(int i=0; i < inv.getSizeInventory(); i++) { if(inv.getStackInSlot(i) != null) { ItemStack j = inv.getStackInSlot(i); if(j.getItem() != null && j.getItem() == Yourclass.youritem) { ItemStack k = new ItemStack(Yourclass.youritem, 2, (j.getItemDamage() + 1)); // the damage your item will get if(k.getItemDamage() >= k.getMaxDamage()) k = null; inv.setInventorySlotContents(i, k); } } } } @Override public void onSmelting(EntityPlayer player, ItemStack item) { // TODO Auto-generated method stub } } Quote
Kore Posted December 23, 2012 Posted December 23, 2012 Here it is: Inside Mod Base Class GameRegistry.registerCraftingHandler(new urClassHere()); Inside Crafting Manager Class public class NewCraftingHandler implements ICraftingHandler { public NewCraftingHandler() { } @Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory inv) { for(int i=0; i < inv.getSizeInventory(); i++) { if(inv.getStackInSlot(i) != null) { ItemStack j = inv.getStackInSlot(i); if(j.getItem() != null && j.getItem() == TestMod.item) { ItemStack k = new ItemStack(TestMod.item, 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) { } } What this is doing is checking your entire inv for any item and if a slot has item and it is yours then it damages item by one unless it only has 1 use less and then it will destroy it.. unless you want a repair then you can put if(j.getItemDamage() < j.getMaxDamage){ //around this \/ ItemStack j = inv.getStackInSlot(i); if(j.getItem() != null && j.getItem() == TestMod.item) { ItemStack k = new ItemStack(TestMod.item, 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 } } Also realize that this is not actually damaging the item, it is merely destroying one and then making another with 1 more damage Your simple fix should be to reload all of the imports by ctrl+shift+o Quote The Korecraft Mod
vroominator Posted December 23, 2012 Posted December 23, 2012 Someone needs to keep count of how many times this question comes up per month. Quote
ps_psycho Posted December 23, 2012 Author Posted December 23, 2012 just make a crafting handler: 1st register it: GameRegistry.registerCraftingHandler(new yourcraftinghandlerclassname()); import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import cpw.mods.fml.common.ICraftingHandler; public class DamageCraftingHandler implements ICraftingHandler{ @Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory inv) { for(int i=0; i < inv.getSizeInventory(); i++) { if(inv.getStackInSlot(i) != null) { ItemStack j = inv.getStackInSlot(i); if(j.getItem() != null && j.getItem() == Yourclass.youritem) { ItemStack k = new ItemStack(Yourclass.youritem, 2, (j.getItemDamage() + 1)); // the damage your item will get if(k.getItemDamage() >= k.getMaxDamage()) k = null; inv.setInventorySlotContents(i, k); } } } } @Override public void onSmelting(EntityPlayer player, ItemStack item) { // TODO Auto-generated method stub } } Here it is: Inside Mod Base Class GameRegistry.registerCraftingHandler(new urClassHere()); Inside Crafting Manager Class public class NewCraftingHandler implements ICraftingHandler { public NewCraftingHandler() { } @Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory inv) { for(int i=0; i < inv.getSizeInventory(); i++) { if(inv.getStackInSlot(i) != null) { ItemStack j = inv.getStackInSlot(i); if(j.getItem() != null && j.getItem() == TestMod.item) { ItemStack k = new ItemStack(TestMod.item, 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) { } } What this is doing is checking your entire inv for any item and if a slot has item and it is yours then it damages item by one unless it only has 1 use less and then it will destroy it.. unless you want a repair then you can put if(j.getItemDamage() < j.getMaxDamage){ //around this \/ ItemStack j = inv.getStackInSlot(i); if(j.getItem() != null && j.getItem() == TestMod.item) { ItemStack k = new ItemStack(TestMod.item, 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 } } Also realize that this is not actually damaging the item, it is merely destroying one and then making another with 1 more damage Your simple fix should be to reload all of the imports by ctrl+shift+o This is the same as I have isn't it? I tried your crafting manager code, but my Item still just dissapears when I craft w/ it. Do I need some kind of special crafting recipe? Here's mine: Saw = # Wood= * #* = Tar Yet the Saw, which I have a crafting Handler for, dissapears! I cant figure out my mistake, I posted all the relevant code already at the main post of this thread, plz help! Quote
Kore Posted December 23, 2012 Posted December 23, 2012 you may be having trouble that you imported the wrong block or items, so remove all of your imports and do ctrl+shift+o to readd them and select the minecraft.block not the forge one Quote The Korecraft Mod
ps_psycho Posted December 23, 2012 Author Posted December 23, 2012 you may be having trouble that you imported the wrong block or items, so remove all of your imports and do ctrl+shift+o to readd them and select the minecraft.block not the forge one I deleted and redid the imports for all classes, to no avail :'(. Do I need to put something in the Item class? Quote
Kore Posted December 23, 2012 Posted December 23, 2012 well yes, you do need to make the item an ItemTool with an enumToolMaterial so it can actually get damaged, I completely forgot about that Quote The Korecraft Mod
ps_psycho Posted December 23, 2012 Author Posted December 23, 2012 well yes, you do need to make the item an ItemTool with an enumToolMaterial so it can actually get damaged, I completely forgot about that Thx so much, do you mind putting how to do that here so I don't have to dig it up (Get It)? Quote
Kore Posted December 23, 2012 Posted December 23, 2012 In your main class(If you want a custom durability public static final EnumToolMaterial yourCustomMaterial = EnumHelper.addToolMaterial(name, harvestLevel, maxUses, efficiency, damage, enchantability); In your Item Class it has to extend ItemTool and set the params in your main to =new ItemSaw(id, Mod.yourCustomMaterial) Quote The Korecraft Mod
Kore Posted December 23, 2012 Posted December 23, 2012 all you need is name and max uses for yours, the others are for tools name = String harvestLevel = Integer(0 to 3, 1 as wood, 3 as diamond) maxUses = Integer(number of times able to be used) efficiency = Float(Speed of breaking) damage = Int(half hearts, when attacking mobs) enchantability = Int(1-30, highest level that will be given with a lvl 30 enchant eg. as a 1 with a 30 enchant you can only get a lvl 1) Quote The Korecraft Mod
ps_psycho Posted December 23, 2012 Author Posted December 23, 2012 Wait, that still dosen't work I must be doing something wrong! Your code pieces are for 1.4.6 correct? Is there anything else I need??? Update: ok I just tried the crafting handler w/ an axe instead of my saw and it worked so I can rule that out as the problem. Here is my code : Main: package psychocraft.common; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.EnumToolMaterial; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.EnumHelper; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid = "ps_psycho_psychocraft", name = "Psychocraft", version = "0.01") @NetworkMod(clientSideRequired = true, serverSideRequired = false) public class PsychocraftMain { //blocks public static Block asphalt; public static Block SmoothR; //Items public static Item Tar; public static Item SawI; @SidedProxy(clientSide = "psychocraft.common.ClientProxyPsychocraft", serverSide = "psychocraft.common.CommonProxyPsychocraft") public static CommonProxyPsychocraft proxy; @Init public void load(FMLInitializationEvent event) { proxy.registerRenderThings(); //crafting handler //blocks asphalt = new BlockAsphalt(1538, 0, Material.sand, 1.06F).setBlockName("asphalt").setHardness(0.5F).setStepSound(Block.soundGravelFootstep).setCreativeTab(CreativeTabs.tabTransport); SmoothR = new BlockAsphalt(1539, 1, Material.sand, 1.10F).setBlockName("SR").setHardness(0.5F).setStepSound(Block.soundStoneFootstep).setCreativeTab(CreativeTabs.tabTransport); final EnumToolMaterial sawIron = EnumHelper.addToolMaterial("sawIron", 0, 100, 0.0F,0, 0); //items final Item Tar = new ItemTar(5001).setMaxStackSize(64).setCreativeTab(CreativeTabs.tabMaterials) .setIconIndex(0).setItemName("Tar"); final Item SawI = new ItemSaw(5002, sawIron).setMaxStackSize(64).setCreativeTab(CreativeTabs.tabMaterials) .setIconIndex(1).setItemName("SawI"); //Efectivity MinecraftForge.setBlockHarvestLevel(asphalt, "shovel", 0); //Registry //Blocks GameRegistry.registerBlock(asphalt, "Asphalt"); GameRegistry.registerBlock(SmoothR, "SmoothR"); GameRegistry.registerCraftingHandler(new SawCraftingHandler()); //names LanguageRegistry.addName(asphalt, "Asphalt Road"); LanguageRegistry.addName(Tar, "Tar Ball"); LanguageRegistry.addName(SawI, "Iron Saw"); //crafting GameRegistry.addRecipe(new ItemStack(SmoothR, 1), "xxx", "xxx", "xxx", 'x', new ItemStack(Tar)); GameRegistry.addRecipe(new ItemStack(SawI, 1), "xii","xi ", 'x', new ItemStack(Item.stick), 'i', new ItemStack(Item.ingotIron)); GameRegistry.addShapelessRecipe(new ItemStack(Tar, 6), new ItemStack(Item.axeWood), new ItemStack(Block.wood, 0)); //smelting GameRegistry.addSmelting(Block.gravel.blockID, new ItemStack(asphalt), 0.5f); } } Item Saw: package psychocraft.common; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.EnumToolMaterial; import net.minecraft.item.Item; import net.minecraft.item.ItemTool; public class ItemSaw extends ItemTool { public static final Block[] blocksEffectiveAgainst = new Block[] {}; public ItemSaw(int par1, EnumToolMaterial par2EnumToolMaterial) { super(par1, 0, par2EnumToolMaterial, blocksEffectiveAgainst); } public String getTextureFile () { return ("/GFX/psychocraftitems.png"); } } Crafting Handler: import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import cpw.mods.fml.common.ICraftingHandler; public class SawCraftingHandler implements ICraftingHandler { @Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory inv) { for(int i=0; i < inv.getSizeInventory(); i++) { if(inv.getStackInSlot(i) != null) { ItemStack j = inv.getStackInSlot(i); if(j.getItem() != null && j.getItem() == PsychocraftMain.sawI) { ItemStack k = new ItemStack(PsychocraftMain.sawI, 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 } } Quote
Kore Posted December 23, 2012 Posted December 23, 2012 replace GameRegistry.addShapelessRecipe(new ItemStack(Tar, 6), new ItemStack(Item.sawI), new ItemStack(Block.wood, 1)); with GameRegistry.addShapelessRecipe(new ItemStack(Tar, 6), new ItemStack(Item.sawI, 1, -1), new ItemStack(Block.wood, 1)); You need to set the allowed damage levels in the crafting, by just saying Itemstack(sawI) you are saying one of a full iron saw Quote The Korecraft Mod
ps_psycho Posted December 23, 2012 Author Posted December 23, 2012 um, K, guess i should have said that the item still disappears. Quote
Kore Posted December 24, 2012 Posted December 24, 2012 remove the .setMaxStackSize() Quote The Korecraft Mod
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.