Jump to content

[1.6.4] [NEW PROBLEM] Problem with damaging an item after crafted with.


gmod622

Recommended Posts

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.

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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

 

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.

Announcements



×
×
  • Create New...

Important Information

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