Jump to content

[Solved]Trying to make an item take damage when you craft with it


shmcrae

Recommended Posts

I'm trying to make a grinder where you put a grinder and one ore and it returns 2 dust. It works to some extent but when i put a whole stack in, it takes the whole stack and only returns 2 dust. Here's my code:

 

Recipe: GameRegistry.addRecipe(new ItemStack (CopperDust, 2), new Object [] {

"GO ", "  ", "  ", 'G', (new ItemStack(AlchemyMain.Grinder, 1, Short.MAX_VALUE)), 'O', AlchemyMain.CopperOre

});

 

 

Crafting Handler: public class AlchemyCraftingHandler implements ICraftingHandler

{

@Override

public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix)

{

for(int i = 0 ; i < craftMatrix.getSizeInventory(); i++)

{

if(craftMatrix.getStackInSlot(i) != null)

{

ItemStack j = craftMatrix.getStackInSlotOnClosing(i);

 

if(j.getItem() != null && j.getItem() == AlchemyMain.Grinder)

{

ItemStack k = new ItemStack(AlchemyMain.Grinder, 2, (j.getItemDamage() + 1));

 

if(k.getItemDamage() >= k.getMaxDamage())

{

k.stackSize--;

}

craftMatrix.setInventorySlotContents(i, k);

}

}

}

}

 

@Override

public void onSmelting(EntityPlayer player, ItemStack item)

{

 

}

}

 

Grinder Class: public class ItemGrinder extends Item

{

private ItemStack emptyItem = null;

public ItemGrinder(int par1, EnumToolMaterial toolGrinder)

{

super(par1);

maxStackSize = 1;

this.setMaxDamage(1000);

this.setCreativeTab(AlchemyMain.TabAlchemy);

}

public void registerIcons(IconRegister iconRegister)

{

itemIcon = iconRegister.registerIcon("alchemy:Grinder");

}

}

 

 

If you need anything else ill post it. Thanks

Link to comment
Share on other sites

Ah, pls use spoiler and code tags.

I will have a look at it as soon as I am back at my pc.

 

Ok:

 

You loop through the crafting matrix to find your grinder. Good

 

You get your grinder. Good

 

You set the damage and place it in the correct slot. Good

 

But you never check how many items are crafted. You have to check the output stack size and than add it to the damage from j.

Here could be your advertisement!

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.