VirtualInventory#canHold

This commit is contained in:
NichtStudioCode 2021-04-30 19:03:46 +02:00
parent 1b60239b34
commit dd80927b46

@ -420,6 +420,19 @@ public class VirtualInventory implements ConfigurationSerializable {
return result; return result;
} }
/**
* Checks if the {@link VirtualInventory} could theoretically hold the
* provided {@link ItemStack}.
*
* @param itemStacks The {@link ItemStack}s
* @return If the {@link VirtualInventory} can fit all these items
*/
public boolean canHold(List<ItemStack> itemStacks) {
if (itemStacks.size() == 0) return true;
else if (itemStacks.size() == 1) return simulateAdd(itemStacks.get(0)) == 0;
else return Arrays.stream(simulateMultiAdd(itemStacks)).allMatch(i -> i == 0);
}
public int collectToCursor(@Nullable UpdateReason updateReason, ItemStack itemStack) { public int collectToCursor(@Nullable UpdateReason updateReason, ItemStack itemStack) {
int amount = itemStack.getAmount(); int amount = itemStack.getAmount();
int maxStackSize = itemStack.getMaxStackSize(); int maxStackSize = itemStack.getMaxStackSize();