Jump to content

Damage Item when use in craft recipes code works, but crafting item with itself?


Frontsalat

Recommended Posts

Basically I was using code from inside this thread, to make items getting damaged when used in certain crafting recipes. This turned out to be working very good, but unfortunately rendered one nasty bug, that I can't get seem to get solved.

 

What happens if I use two of the same damageable items in the crafting menu, it will craft the same item, see this picture to understand what I mean:

 

2j53.png

 

What you see in the picture is a mortar and pestle that should regularily be used to crush sugar cane, which, like mentioned before, works perfectly fine. But getting an undamaged item out of crafting the item with itself, was not exactly what I wanted. It does not matter if I use two damaged or two undamaged items, or combine damaged and undamaged items, it does however, not do that when I put more then two item into the crafting menu. Here's the code I'm using...

 

 

Item:

 

package MetallurgyRealism;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;

public class ToolMortarPestle extends Item {

    public ToolMortarPestle(int id) {
            super(id); 
            this.setMaxStackSize(1);
            this.setMaxDamage(10);
            this.setCreativeTab(MetallurgyRealismModBase.MetallurgyRealismTab);
            this.setUnlocalizedName("mortarpestle");
            
    }
    
    public String getTextureFile() {
    		return CommonProxy.ITEMS_PNG;
    }
    
    public void registerIcons(IconRegister iconRegister)
    {
             itemIcon = iconRegister.registerIcon("MetallurgyRealism:mortarpestle");
    }
    
    @Override
    public boolean hasContainerItem()
    {
         return true;
    }

    @Override
    public ItemStack getContainerItemStack(ItemStack itemStack) {

    itemStack.setItemDamage(itemStack.getItemDamage() + 1);

    return itemStack;
    }


}

 

Main Class:

 

ToolMortarPestle = new ToolMortarPestle(ToolMortarPestleID).setContainerItem(ToolMortarPestle);

GameRegistry.addShapelessRecipe(new ItemStack(Item.sugar, 3), new ItemStack(Item.reed), new ItemStack(ToolMortarPestle, 1, OreDictionary.WILDCARD_VALUE));

 

 

Any idea?

Link to comment
Share on other sites

That's the repair recipe function of the Crafting system (you can combine two damaged Items). To disable use setNoRepair on your item.

 

So items will always repair themselfs if not the setNoRepair flag set? Interesting. I'd swear I haven't noticed that before.

 

However, works brilliantly perfect now. Thank you very much friend.

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.