mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 16:41:35 +01:00
Allow for cancelling at start and end of drag
This commit is contained in:
parent
ddbd621535
commit
99855a3ea7
@ -240,14 +240,16 @@ public class InventoryClickProcessor {
|
|||||||
// Start or end left/right drag
|
// Start or end left/right drag
|
||||||
if (button == 0) {
|
if (button == 0) {
|
||||||
// Start left
|
// Start left
|
||||||
this.leftDraggingMap.put(player, new IntOpenHashSet());
|
|
||||||
|
|
||||||
clickResult = startCondition(inventory, player, slot, ClickType.START_LEFT_DRAGGING, clicked, cursor);
|
clickResult = startCondition(inventory, player, slot, ClickType.START_LEFT_DRAGGING, clicked, cursor);
|
||||||
|
|
||||||
|
if (!clickResult.isCancel())
|
||||||
|
this.leftDraggingMap.put(player, new IntOpenHashSet());
|
||||||
} else if (button == 4) {
|
} else if (button == 4) {
|
||||||
// Start right
|
// Start right
|
||||||
this.rightDraggingMap.put(player, new IntOpenHashSet());
|
|
||||||
|
|
||||||
clickResult = startCondition(inventory, player, slot, ClickType.START_RIGHT_DRAGGING, clicked, cursor);
|
clickResult = startCondition(inventory, player, slot, ClickType.START_RIGHT_DRAGGING, clicked, cursor);
|
||||||
|
|
||||||
|
if (!clickResult.isCancel())
|
||||||
|
this.rightDraggingMap.put(player, new IntOpenHashSet());
|
||||||
} else if (button == 2) {
|
} else if (button == 2) {
|
||||||
// End left
|
// End left
|
||||||
if (!leftDraggingMap.containsKey(player))
|
if (!leftDraggingMap.containsKey(player))
|
||||||
@ -257,16 +259,30 @@ public class InventoryClickProcessor {
|
|||||||
final int cursorAmount = stackingRule.getAmount(cursor);
|
final int cursorAmount = stackingRule.getAmount(cursor);
|
||||||
if (slotCount > cursorAmount)
|
if (slotCount > cursorAmount)
|
||||||
return null;
|
return null;
|
||||||
// Should be size of each defined slot (if not full)
|
|
||||||
final int slotSize = (int) ((float) cursorAmount / (float) slotCount);
|
boolean cancel = false;
|
||||||
int finalCursorAmount = cursorAmount;
|
|
||||||
|
|
||||||
for (int s : slots) {
|
for (int s : slots) {
|
||||||
ItemStack slotItem = itemGetter.apply(s);
|
ItemStack slotItem = itemGetter.apply(s);
|
||||||
|
|
||||||
clickResult = startCondition(inventory, player, s, ClickType.LEFT_DRAGGING, slotItem, cursor);
|
clickResult = startCondition(inventory, player, s, ClickType.LEFT_DRAGGING, slotItem, cursor);
|
||||||
if (clickResult.isCancel())
|
|
||||||
|
if (clickResult.isCancel()) {
|
||||||
|
cancel = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel |= startCondition(inventory, player, slot, ClickType.END_LEFT_DRAGGING, clicked, cursor).isCancel();
|
||||||
|
|
||||||
|
// Should be size of each defined slot (if not full)
|
||||||
|
final int slotSize = (int) ((float) cursorAmount / (float) slotCount);
|
||||||
|
int finalCursorAmount = cursorAmount;
|
||||||
|
|
||||||
|
if (!cancel) {
|
||||||
|
for (int s : slots) {
|
||||||
|
ItemStack slotItem = itemGetter.apply(s);
|
||||||
StackingRule slotItemRule = slotItem.getStackingRule();
|
StackingRule slotItemRule = slotItem.getStackingRule();
|
||||||
|
|
||||||
final int maxSize = stackingRule.getMaxSize(cursor);
|
final int maxSize = stackingRule.getMaxSize(cursor);
|
||||||
@ -294,8 +310,7 @@ public class InventoryClickProcessor {
|
|||||||
cursor = stackingRule.apply(cursor, finalCursorAmount);
|
cursor = stackingRule.apply(cursor, finalCursorAmount);
|
||||||
clickResult.setCursor(cursor);
|
clickResult.setCursor(cursor);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
clickResult = startCondition(inventory, player, slot, ClickType.END_LEFT_DRAGGING, clicked, cursor);
|
|
||||||
|
|
||||||
leftDraggingMap.remove(player);
|
leftDraggingMap.remove(player);
|
||||||
} else if (button == 6) {
|
} else if (button == 6) {
|
||||||
@ -308,13 +323,26 @@ public class InventoryClickProcessor {
|
|||||||
if (size > cursorAmount)
|
if (size > cursorAmount)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
boolean cancel = false;
|
||||||
|
|
||||||
for (int s : slots) {
|
for (int s : slots) {
|
||||||
ItemStack draggedItem = cursor;
|
|
||||||
ItemStack slotItem = itemGetter.apply(s);
|
ItemStack slotItem = itemGetter.apply(s);
|
||||||
|
|
||||||
clickResult = startCondition(inventory, player, s, ClickType.RIGHT_DRAGGING, slotItem, cursor);
|
clickResult = startCondition(inventory, player, s, ClickType.RIGHT_DRAGGING, slotItem, cursor);
|
||||||
if (clickResult.isCancel())
|
|
||||||
|
if (clickResult.isCancel()) {
|
||||||
|
cancel = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel |= startCondition(inventory, player, slot, ClickType.END_RIGHT_DRAGGING, clicked, cursor).isCancel();
|
||||||
|
|
||||||
|
if (!cancel) {
|
||||||
|
for (int s : slots) {
|
||||||
|
ItemStack draggedItem = cursor;
|
||||||
|
ItemStack slotItem = itemGetter.apply(s);
|
||||||
|
|
||||||
StackingRule slotItemRule = slotItem.getStackingRule();
|
StackingRule slotItemRule = slotItem.getStackingRule();
|
||||||
if (stackingRule.canBeStacked(draggedItem, slotItem)) {
|
if (stackingRule.canBeStacked(draggedItem, slotItem)) {
|
||||||
@ -338,8 +366,7 @@ public class InventoryClickProcessor {
|
|||||||
cursor = stackingRule.apply(cursor, cursorAmount);
|
cursor = stackingRule.apply(cursor, cursorAmount);
|
||||||
clickResult.setCursor(cursor);
|
clickResult.setCursor(cursor);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
clickResult = startCondition(inventory, player, slot, ClickType.END_RIGHT_DRAGGING, clicked, cursor);
|
|
||||||
|
|
||||||
rightDraggingMap.remove(player);
|
rightDraggingMap.remove(player);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user