Split dragging into separate left and right drags

This commit is contained in:
stefvanschie 2021-05-23 21:42:16 +02:00
parent a749f07a3f
commit 2122685d5f
No known key found for this signature in database
GPG Key ID: 25B5C700152649BD
2 changed files with 29 additions and 5 deletions

View File

@ -9,9 +9,18 @@ public enum ClickType {
START_SHIFT_CLICK, START_SHIFT_CLICK,
SHIFT_CLICK, SHIFT_CLICK,
@Deprecated
START_DRAGGING, START_DRAGGING,
START_LEFT_DRAGGING,
START_RIGHT_DRAGGING,
@Deprecated
DRAGGING, DRAGGING,
LEFT_DRAGGING,
RIGHT_DRAGGING,
START_DOUBLE_CLICK, START_DOUBLE_CLICK,
DOUBLE_CLICK, DOUBLE_CLICK,

View File

@ -232,7 +232,7 @@ public class InventoryClickProcessor {
@NotNull ItemStack clicked, @NotNull ItemStack cursor, @NotNull ItemStack clicked, @NotNull ItemStack cursor,
@NotNull Int2ObjectFunction<ItemStack> itemGetter, @NotNull Int2ObjectFunction<ItemStack> itemGetter,
@NotNull BiConsumer<Integer, ItemStack> itemSetter) { @NotNull BiConsumer<Integer, ItemStack> itemSetter) {
InventoryClickResult clickResult = startCondition(inventory, player, slot, ClickType.START_DRAGGING, clicked, cursor); InventoryClickResult clickResult = null;
final StackingRule stackingRule = cursor.getStackingRule(); final StackingRule stackingRule = cursor.getStackingRule();
@ -241,9 +241,13 @@ public class InventoryClickProcessor {
if (button == 0) { if (button == 0) {
// Start left // Start left
this.leftDraggingMap.put(player, new IntOpenHashSet()); this.leftDraggingMap.put(player, new IntOpenHashSet());
clickResult = startCondition(inventory, player, slot, ClickType.START_LEFT_DRAGGING, clicked, cursor);
} else if (button == 4) { } else if (button == 4) {
// Start right // Start right
this.rightDraggingMap.put(player, new IntOpenHashSet()); this.rightDraggingMap.put(player, new IntOpenHashSet());
clickResult = startCondition(inventory, player, slot, ClickType.START_RIGHT_DRAGGING, clicked, cursor);
} else if (button == 2) { } else if (button == 2) {
// End left // End left
if (!leftDraggingMap.containsKey(player)) if (!leftDraggingMap.containsKey(player))
@ -257,10 +261,13 @@ public class InventoryClickProcessor {
final int slotSize = (int) ((float) cursorAmount / (float) slotCount); final int slotSize = (int) ((float) cursorAmount / (float) slotCount);
int finalCursorAmount = cursorAmount; int finalCursorAmount = cursorAmount;
// Set to a value in case there are no slots
clickResult = startCondition(inventory, player, slot, ClickType.START_LEFT_DRAGGING, clicked, cursor);
for (int s : slots) { for (int s : slots) {
ItemStack slotItem = itemGetter.apply(s); ItemStack slotItem = itemGetter.apply(s);
clickResult = startCondition(inventory, player, s, ClickType.DRAGGING, slotItem, cursor); clickResult = startCondition(inventory, player, s, ClickType.LEFT_DRAGGING, slotItem, cursor);
if (clickResult.isCancel()) if (clickResult.isCancel())
break; break;
StackingRule slotItemRule = slotItem.getStackingRule(); StackingRule slotItemRule = slotItem.getStackingRule();
@ -282,7 +289,7 @@ public class InventoryClickProcessor {
} }
itemSetter.accept(s, slotItem); itemSetter.accept(s, slotItem);
callClickEvent(player, inventory, s, ClickType.DRAGGING, slotItem, cursor); callClickEvent(player, inventory, s, ClickType.LEFT_DRAGGING, slotItem, cursor);
} }
cursor = stackingRule.apply(cursor, finalCursorAmount); cursor = stackingRule.apply(cursor, finalCursorAmount);
clickResult.setCursor(cursor); clickResult.setCursor(cursor);
@ -297,11 +304,15 @@ public class InventoryClickProcessor {
int cursorAmount = stackingRule.getAmount(cursor); int cursorAmount = stackingRule.getAmount(cursor);
if (size > cursorAmount) if (size > cursorAmount)
return null; return null;
// Set to a value in case there are no slots
clickResult = startCondition(inventory, player, slot, ClickType.START_RIGHT_DRAGGING, clicked, cursor);
for (int s : slots) { for (int s : slots) {
ItemStack draggedItem = cursor; ItemStack draggedItem = cursor;
ItemStack slotItem = itemGetter.apply(s); ItemStack slotItem = itemGetter.apply(s);
clickResult = startCondition(inventory, player, s, ClickType.DRAGGING, slotItem, cursor); clickResult = startCondition(inventory, player, s, ClickType.RIGHT_DRAGGING, slotItem, cursor);
if (clickResult.isCancel()) if (clickResult.isCancel())
break; break;
@ -319,7 +330,7 @@ public class InventoryClickProcessor {
cursorAmount -= 1; cursorAmount -= 1;
} }
callClickEvent(player, inventory, s, ClickType.DRAGGING, draggedItem, cursor); callClickEvent(player, inventory, s, ClickType.RIGHT_DRAGGING, draggedItem, cursor);
} }
cursor = stackingRule.apply(cursor, cursorAmount); cursor = stackingRule.apply(cursor, cursorAmount);
clickResult.setCursor(cursor); clickResult.setCursor(cursor);
@ -335,11 +346,15 @@ public class InventoryClickProcessor {
return null; return null;
leftDraggingMap.get(player).add(slot); leftDraggingMap.get(player).add(slot);
clickResult = startCondition(inventory, player, slot, ClickType.START_LEFT_DRAGGING, clicked, cursor);
} else if (button == 5) { } else if (button == 5) {
// Add right slot // Add right slot
if (!rightDraggingMap.containsKey(player)) if (!rightDraggingMap.containsKey(player))
return null; return null;
rightDraggingMap.get(player).add(slot); rightDraggingMap.get(player).add(slot);
clickResult = startCondition(inventory, player, slot, ClickType.START_RIGHT_DRAGGING, clicked, cursor);
} }
} }