return false;
}
private boolean handleClick(ClickArguments args) {
Slot s = args.getSlot();
Inventory inventory = s.getInventory();
int slot = s.getIndex();
// First check if we have a situtation where s's inventory is null
switch (args.getAction()) {
case START_LEFT_PAINT:
if (paintType != NOPAINT || cursorItem == null) {
resetPaint();
return false;
}
debug("[Window] Beginning left paint");
paintType = LEFTPAINT;
painting = cursorItem.clone();
return true;
case START_RIGHT_PAINT:
if (paintType != NOPAINT || cursorItem == null) {
resetPaint();
return false;
}
debug("[Window] Beginning right paint");
paintType = RIGHTPAINT;
painting = cursorItem.clone();
return true;
case LEFT_PAINT_PROGRESS:
if (paintType != LEFTPAINT || cursorItem == null) {
resetPaint();
return false;
}
if (paintedSlotSet.size() == painting.getAmount()) {// Can't split item anymore
return false;
}
debug("[Window] Progessing left paint");
if (s.get() != null) {
if (!s.get().equalsIgnoreSize(painting)) {// Materials don't match
return false;
}
if (s.get().getAmount() >= s.get().getMaxStackSize()) {// Can't stack anymore
return true;
}
}
paintedSlotSet.add(s);
return true;
case RIGHT_PAINT_PROGRESS:
if (paintType != RIGHTPAINT || cursorItem == null) {
resetPaint();
return false;
}
if (paintedSlotSet.size() == painting.getAmount()) {// Can't split item anymore
return false;
}
debug("[Window] Progessing right paint");
if (s.get() != null) {
if (!s.get().equalsIgnoreSize(painting)) {// Materials don't match
return false;
}
if (s.get().getAmount() >= s.get().getMaxStackSize()) {// Can't stack anymore
return true;
}
}
paintedSlotSet.add(s);
return true;
case END_LEFT_PAINT:
if (paintType != LEFTPAINT || cursorItem == null) {
resetPaint();
return false;
}
debug("[Window] Ending left paint");
final int divide = painting.getAmount() / paintedSlotSet.size();
int extra = 0;
for (Slot pSlot : paintedSlotSet) {
int newSize = (pSlot.get() == null ? 0 : pSlot.get().getAmount()) + divide;
if (newSize > painting.getMaxStackSize()) {
extra += painting.getMaxStackSize() - newSize;
newSize = painting.getMaxStackSize();
}
pSlot.set(painting.clone().setAmount(newSize));
}
cursorItem.setAmount(extra + (painting.getAmount() % paintedSlotSet.size()));
resetPaint();
return true;
case END_RIGHT_PAINT:
if (paintType != RIGHTPAINT || cursorItem == null) {
resetPaint();
return false;
}
debug("[Window] Ending right paint");
for (Slot pSlot : paintedSlotSet) {
int newSize = (pSlot.get() == null ? 0 : pSlot.get().getAmount()) + 1;
pSlot.set(painting.clone().setAmount(newSize));
}
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;