public void removeItem(byte slot, short quantity, boolean allowZero) { IItem item = inventory.get(slot); if (item == null) { // TODO is it ok not to throw an exception here? return; } item.setQuantity((short) (item.getQuantity() - quantity)); if (item.getQuantity() < 0) { item.setQuantity((short) 0); } if (item.getQuantity() == 0 && !allowZero) { removeSlot(slot); } }
public int countById(int itemId) { int possesed = 0; for (IItem item : inventory.values()) { if (item.getItemId() == itemId) { possesed += item.getQuantity(); } } return possesed; }