int invenIndex = 0;
boolean changed = false;
try {
for (int cartSlot = 0; cartSlot < fromItems.length; cartSlot++) {
Item cartItem = fromItems[cartSlot];
if (cartItem == null || cartItem.count == 0) {
continue;
}
try {
for (; invenIndex < inventories.length; invenIndex++) {
Item[] chestItems = inventories[invenIndex].getItems();
for (int chestSlot = 0; chestSlot < chestItems.length; chestSlot++) {
Item chestItem = chestItems[chestSlot];
if (chestItem.id == 0 || chestItem.count == 0) {
chestItems[chestSlot] = cartItem;
fromItems[cartSlot] = null;
setContents(inventories[invenIndex], chestItems);
changed = true;
throw new TransferredItemException();
} else if (chestItem.id == cartItem.id
&& chestItem.count < 64
&& chestItem.count >= 0) {
int spaceAvailable = 64 - chestItem.count;
if (spaceAvailable >= cartItem.count) {
chestItem = chestItem.addItems(cartItem.count);
fromItems[cartSlot] = null;
setContents(inventories[invenIndex], chestItems);
changed = true;
throw new TransferredItemException();
} else {
cartItem = cartItem.removeItems(spaceAvailable);
chestItem = new Item(chestItem.id, 64);
changed = true;
}
}
}
}