gmod622 Posted March 28, 2014 Posted March 28, 2014 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! Quote Not new to java >> New to modding.
Z@Nka Posted March 28, 2014 Posted March 28, 2014 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? Quote If I helped then you help, hit that Thank You button or Applaud.
gmod622 Posted March 28, 2014 Author Posted March 28, 2014 well I tried adding this, but it did not help int d = j.getItemDamage(); if(d > 128) { inv.setInventorySlotContents(i, null); } Quote Not new to java >> New to modding.
Z@Nka Posted March 28, 2014 Posted March 28, 2014 Is it supposed to just disappear like a sword when it brakes? Quote If I helped then you help, hit that Thank You button or Applaud.
gmod622 Posted March 28, 2014 Author Posted March 28, 2014 yes. Quote Not new to java >> New to modding.
Z@Nka Posted March 28, 2014 Posted March 28, 2014 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. Quote If I helped then you help, hit that Thank You button or Applaud.
gmod622 Posted March 28, 2014 Author Posted March 28, 2014 its ok Thanks for trying thou Quote Not new to java >> New to modding.
coolboy4531 Posted March 29, 2014 Posted March 29, 2014 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 } Quote
gmod622 Posted March 30, 2014 Author Posted March 30, 2014 I was told that damage is inverted... 128 Damage taken to the item. Quote Not new to java >> New to modding.
pelep Posted April 1, 2014 Posted April 1, 2014 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); } Quote
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.