Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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?

  • Author

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.