Removes the specified amount of the given item from the given inventory @param inv The inventory to remove the items from @param item The item to be removed @param amount The amount of items to remove @param comparison A filter to compare items for removal @return Whether the amoun
(Inventory inv, ItemStack item, int amount, BiPredicate<ItemStack, ItemStack> comparison)
| 396 | * @return Whether the amount specified could be removed. False if it removed less than specified. |
| 397 | */ |
| 398 | public static boolean remove(Inventory inv, ItemStack item, int amount, BiPredicate<ItemStack, ItemStack> comparison) { |
| 399 | ItemStack[] contents = inv.getContents(); |
| 400 | for (int i = 0; i < contents.length && amount > 0; i++) { |
| 401 | if (!comparison.test(item, contents[i])) { |
| 402 | continue; |
| 403 | } |
| 404 | if (amount >= contents[i].getAmount()) { |
| 405 | amount -= contents[i].getAmount(); |
| 406 | contents[i] = null; |
| 407 | if (amount == 0) { |
| 408 | inv.setContents(contents); |
| 409 | return true; |
| 410 | } |
| 411 | continue; |
| 412 | } |
| 413 | contents[i].setAmount(contents[i].getAmount() - amount); |
| 414 | inv.setContents(contents); |
| 415 | return true; |
| 416 | } |
| 417 | inv.setContents(contents); |
| 418 | return false; |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Removes the specified amount of the given item from the given inventory |
no test coverage detected