Jump to content

[1.16] Making a recipe damage an item on use

A Soulspark

Recommended Posts

So, I want to add shapeless recipes where you use Shears + (some item) to craft another item, but the shears stay, albeit with -1 durability. After a bit of a search, it seems like you can use getContainerItem() and similar methods to achieve this, but that's out of scope here with a vanilla item.


Then, how am I supposed to approach this? Maybe through a custom recipe type where one of the ingredients stay after crafting, but how do I even do that?

Edited by A Soulspark
Link to comment
Share on other sites

Ok, that seems to make sense! Though I'm having a bit of trouble with the damaging part, since the getRemainingItems() function only gives you an Inventory. I believe the best way to damage the item is through attemptDamageItem(), but idk how to get a java.util.Random instance in this context.


Here's the code for reference:

public NonNullList<ItemStack> getRemainingItems(CraftingInventory inv) {
  // get the default remaining items for a shapeless recipe 
  NonNullList<ItemStack> remainingItems = super.getRemainingItems(inv);

  // loop through each slot in the crafting inventory
  for (int i = 0; i < remainingItems.size(); i++) {
    ItemStack stack = inv.getStackInSlot(i);
    // if the item in the slot are shears
    if (stack.getItem() instanceof ShearsItem) {
      // try to damage the item, but this is *ugly*
      // how do I get a Random instance here ▬-▬
      stack.attemptDamageItem(1, [insert java.util.Random instance], null); // (int amount, Random random, ServerPlayerEntity entity)
      remainingItems.set(i, stack);

  return remainingItems;


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.

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.

  • Create New...

Important Information

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