Advertisement
Guest User

Untitled

a guest
May 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. public static void removeItemStack(Player player, ItemStack item, int amount) {
  2. Inventory inventory = player.getInventory();
  3. Iterator<Slot> slotIterator = inventory.<Slot>slots().iterator();
  4. while (slotIterator.hasNext() && amount > 0) {
  5. Slot slot = slotIterator.next();
  6. Optional<ItemStack> optionalInventoryItem = slot.peek();
  7. if (optionalInventoryItem.isPresent()) {
  8. ItemStack inventoryItem = optionalInventoryItem.get();
  9. if (ItemStackComparators.IGNORE_SIZE.compare(inventoryItem, item) == 0) {
  10. int itemQuantity = inventoryItem.getQuantity();
  11. if (itemQuantity > amount) {
  12. item.setQuantity(itemQuantity - amount);
  13. slot.set(item);
  14. amount = 0;
  15. } else {
  16. slot.set(ItemStack.of(ItemTypes.NONE, amount));
  17. amount -= itemQuantity;
  18. }
  19. }
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement