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.

Featured Replies

Posted

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

  • Author

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:

@Override
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;
}

 

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.