Fixes a bug in multi-item salvage
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good

This commit is contained in:
2023-01-14 17:46:29 +01:00
parent 7cc2aef9d4
commit bbb93bb0eb
2 changed files with 49 additions and 3 deletions

View File

@ -72,12 +72,28 @@ public final class SalvageHelper {
}
//Make sure to give salvage for all items if a stack > 1 is provided
List<ItemStack> salvage = new ArrayList<>();
List<ItemStack> allSalvage = new ArrayList<>();
for (int i = 0; i < salvagedItem.getAmount(); i++) {
salvage.addAll(getSalvage(ingredients, salvagedItem));
allSalvage.addAll(getSalvage(copyItems(ingredients), salvagedItem));
}
return combineStacks(salvage);
return combineStacks(allSalvage);
}
/**
* Copies a list of items
*
* <p>Note: This does not copy any metadata. It only copies the item type and the amount.</p>
*
* @param itemsToCopy <p>The items to make a copy of</p>
* @return <p>A copy of the given items</p>
*/
private static List<ItemStack> copyItems(List<ItemStack> itemsToCopy) {
List<ItemStack> copies = new ArrayList<>(itemsToCopy.size());
for (ItemStack itemStack : itemsToCopy) {
copies.add(new ItemStack(itemStack.getType(), itemStack.getAmount()));
}
return copies;
}
/**