MCPcopy Create free account
hub / github.com/boxbeam/RedLib / remove

Method remove

src/redempt/redlib/itemutils/ItemUtils.java:398–419  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

countAndRemoveMethod · 0.95

Calls 4

compareMethod · 0.95
getContentsMethod · 0.80
testMethod · 0.80
setContentsMethod · 0.80

Tested by

no test coverage detected