inventory.setInventorySlotContents(i, newStack);
}
// Compact
for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
final ItemIdentifierStack stackInSlot = inventory.getIDStackInSlot(i);
if (stackInSlot == null) {
continue;
}
final ItemIdentifier itemInSlot = stackInSlot.getItem();
for (int j = i + 1; j < inventory.getSizeInventory() - 2; j++) {
final ItemIdentifierStack stackInOtherSlot = inventory.getIDStackInSlot(j);
if (stackInOtherSlot == null) {
continue;
}
if (itemInSlot.equals(stackInOtherSlot.getItem())) {
stackInSlot.setStackSize(stackInSlot.getStackSize() + stackInOtherSlot.getStackSize());
inventory.setInventorySlotContents(i,stackInSlot);
inventory.clearInventorySlotContents(j);
}
}
}