Posted March 28, 201411 yr NEW PROBLEM: Now the item wont break even thou the durability is below 0. CODE: Main Class (Recipe & Registration of handler) : GameRegistry.registerCraftingHandler(new CraftingHandler()); GameRegistry.addShapelessRecipe(new ItemStack(SiliconMixture), new Object[]{ new ItemStack(CopperIngot), new ItemStack(Item.ingotIron), new ItemStack(ShapingHammer, 0, -1) }); Crafting Handler: public class CraftingHandler 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() == main_ProcessCraft.ShapingHammer) { ItemStack k = new ItemStack(main_ProcessCraft.ShapingHammer, 2, (j.getItemDamage() + 1)); inv.setInventorySlotContents(i, k); } } } } @Override public void onSmelting(EntityPlayer player, ItemStack item) { // TODO Auto-generated method stub } } Item File: package gmod.mods.ProcessingCraft.main.item; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; public class ItemShapingHammer extends Item { public ItemShapingHammer(int par1) { super(par1); this.setCreativeTab(CreativeTabs.tabBlock); this.bFull3D = true; this.maxStackSize = 1; this.canRepair = true; this.setMaxDamage(128); } } Any Help to my problem will be appreciated! Not new to java >> New to modding.
March 28, 201411 yr Are you trying to get it to take 1 damage when used in crafting each time and once the durability hits 0, you can't use it for crafting anymore until repaired? If I helped then you help, hit that Thank You button or Applaud.
March 28, 201411 yr Author well I tried adding this, but it did not help int d = j.getItemDamage(); if(d > 128) { inv.setInventorySlotContents(i, null); } Not new to java >> New to modding.
March 28, 201411 yr Is it supposed to just disappear like a sword when it brakes? If I helped then you help, hit that Thank You button or Applaud.
March 28, 201411 yr I taught I knew it but then I tried it myself so I don't give false info and it didn't work.... Too much for my brain to handle sorry. If I helped then you help, hit that Thank You button or Applaud.
March 29, 201411 yr I hope you know what this is doing. int d = j.getItemDamage(); if(d > 128) { inv.setInventorySlotContents(i, null); } This is checking when - your item is above the max damage (greater than 128). You can check if it is at 0, then remove the item, but the problem is that you probably don't even know what (d>128) really means - d (greater than) 128. You should use (checks if it is equal to 0 or below 0. [0,-1,-2,-3,etc.]) int d = j.getItemDamage(); if(d <= 0) { //break / delete item }
March 30, 201411 yr Author I was told that damage is inverted... 128 Damage taken to the item. Not new to java >> New to modding.
April 1, 201411 yr I hope you know what this is doing. int d = j.getItemDamage(); if(d > 128) { inv.setInventorySlotContents(i, null); } This is checking when - your item is above the max damage (greater than 128). You can check if it is at 0, then remove the item, but the problem is that you probably don't even know what (d>128) really means - d (greater than) 128. You should use (checks if it is equal to 0 or below 0. [0,-1,-2,-3,etc.]) int d = j.getItemDamage(); if(d <= 0) { //break / delete item } you really should get your facts straight before you go around insulting people.. @gmod622 an easier way to do what you want is this if(j.getItem() != null && j.getItem() == main_ProcessCraft.ShapingHammer) { if (!j.attemptDamageItem(1, player.getRNG())) { j.stackSize++; } } although, this should already work fine assuming you added it to the rest of your code correctly int d = j.getItemDamage(); if(d > 128) { inv.setInventorySlotContents(i, null); }
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.