Posted March 5, 20214 yr 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 March 5, 20214 yr by A Soulspark
March 7, 20214 yr 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.