}
cursorItem.setAmount(cursorItem.getAmount() - paintedSlotSet.size());
resetPaint();
return true;
}
ItemStack clicked = s.get();
if (args.isShiftClick()) {
debug("[Window] Shift-Clicked slot " + slot);
if (clicked != null) {
return onShiftClick(clicked, slot, inventory);
} else {
return true;
}
}
switch (args.getAction()) {
case RIGHT_CLICK:
debug("[Window - " + title + "] Right-Clicked slot " + slot + " using Cursor: " + cursorItem);
debug("[Window] Item at clicked slot: " + (clicked == null ? "Empty" : clicked.getMaterial().getName()));
if (clicked == null) {
if (cursorItem != null) {
debug("[Window] Add one");
// slot is empty with a not empty cursor
// add one
clicked = cursorItem.clone();
clicked.setAmount(1);
// Can it be set?
if (canSet(inventory, slot, clicked)) {
inventory.set(slot, clicked);
// remove from cursor
cursorItem.setAmount(cursorItem.getAmount() - 1);
if (cursorItem.isEmpty()) {
cursorItem = null;
}
return true;
}
}
} else if (cursorItem != null) {
// slot is not empty with not empty cursor
if (cursorItem.equalsIgnoreSize(clicked)) {
// only stack materials that are the same
if (clicked.getMaxStackSize() > clicked.getAmount()) {
debug("[Window] Stacking");
// add one if can fit
clicked.setAmount(clicked.getAmount() + 1);
if (canSet(inventory, slot, clicked)) {
inventory.set(slot, clicked);
cursorItem.setAmount(cursorItem.getAmount() - 1);
if (cursorItem.isEmpty()) {
cursorItem = null;
}
return true;
} else {
//Crafting result slot?
//Reset state
clicked.setAmount(clicked.getAmount() - 1);
cursorItem.stack(clicked);
if (clicked.isEmpty()) {
clicked = null;
inventory.set(slot, null, true); //will trigger crafting table to create new result if possible
} else {
inventory.set(slot, clicked, false);//will not trigger crafting table to create new result (some result still left in slot)
}
}
}
} else {
// Can it be set?
if (canSet(inventory, slot, cursorItem)) {
debug("[Window] Materials don't match. Swapping stacks.");
// materials don't match
// swap stacks
ItemStack newCursor = clicked.clone();
inventory.set(slot, cursorItem);
cursorItem = newCursor;
return true;
}
}
} else {
// slot is not empty with an empty cursor
// split the stack
int x = clicked.getAmount();
int y = x / 2;
int z = x % 2;
clicked.setAmount(y);
inventory.set(slot, clicked);
// cursor gets any remainder
cursorItem = clicked.clone();
cursorItem.setAmount(y + z);
}
return true;
case LEFT_CLICK:
debug("[Window - " + title + "] Left-Clicked slot " + slot + " using Cursor: " + cursorItem);
debug("[Window] Item at clicked slot: " + (clicked == null ? "Empty" : clicked.getMaterial().getName()));
if (clicked == null) {
if (cursorItem != null) {
debug("[Window] Put whole stack in slot");
// slot is empty; cursor is not empty.
// put whole stack down
clicked = cursorItem.clone();
// Can it be set?
if (canSet(inventory, slot, clicked)) {
inventory.set(slot, clicked);
cursorItem = null;
return true;
}
}
} else if (cursorItem != null) {
// slot is not empty; cursor is not empty.
// stack
if (cursorItem.equalsIgnoreSize(clicked)) {
debug("[Window] Stacking");
//Try to set items
if (canSet(inventory, slot, clicked)) {
clicked.stack(cursorItem);
inventory.set(slot, clicked);
if (cursorItem.isEmpty()) {
cursorItem = null;
}
//Else try to pick them up (crafting)
} else {
cursorItem.stack(clicked);
if (clicked.isEmpty()) {
clicked = null;
inventory.set(slot, null, true);//will trigger crafting table to create new result if possible
} else {
inventory.set(slot, clicked, false);//will not trigger crafting table to create new result (some result still left in slot)
}
}
return true;
} else {
// Can it be set?
if (canSet(inventory, slot, clicked)) {
debug("[Window] Materials don't match. Swapping stacks.");
// materials don't match
// swap stacks
ItemStack newCursor = clicked.clone();
inventory.set(slot, cursorItem);
cursorItem = newCursor;
}
}
} else {
// slot is not empty; cursor is empty.
// pick up stack
cursorItem = clicked.clone();
inventory.set(slot, null);
}
return true;
case DOUBLE_CLICK:
if (cursorItem == null || cursorItem.getAmount() >= cursorItem.getMaxStackSize()) {
return true;
}
debug("[Window] Combining similar materials.");
for (int i = 0; i < getSize(); i++) {
Slot spoutSlot = getSlot(i);
ItemStack get = spoutSlot.get();
if (get == null || get.getAmount() >= get.getMaxStackSize()) {
continue;
}
if (cursorItem.stack(get)) {
if (get.isEmpty()) {
spoutSlot.set(null);
if (cursorItem.getAmount() >= cursorItem.getMaxStackSize()) {// Done
return true;
}
}
}
}
break;
case DROP:
ItemStack get = args.getSlot().get();
if (get == null) {
return true;
}
if (get.getAmount() == 1) {
getHuman().dropItem(get);
args.getSlot().set(null);
} else {
getHuman().dropItem(get.clone().setAmount(1));
args.getSlot().addAmount(-1);
}
return true;
case CTRL_DROP:
if (args.getSlot().get() == null) {