@@ -57,14 +57,15 @@ public sealed abstract class Inventory permits VirtualInventory, CompositeInvent
5757 private @ Nullable List <Consumer <InventoryClickEvent >> clickHandlers ;
5858 private @ Nullable List <Consumer <ItemPreUpdateEvent >> preUpdateHandlers ;
5959 private @ Nullable List <Consumer <ItemPostUpdateEvent >> postUpdateHandlers ;
60- private int guiPriority = 0 ;
61- private final Map <IterationOrderCategory , int []> iterationOrders ;
60+ private final Map < OperationCategory , int []> iterationOrders ;
61+ private final Map <OperationCategory , Integer > guiPriorities ;
6262
6363 @ SuppressWarnings ("unchecked" )
6464 public Inventory (int size ) {
6565 this .size = size ;
6666 viewers = new Set [size ];
67- iterationOrders = CollectionUtils .newEnumMap (IterationOrderCategory .class , k -> IntStream .range (0 , size ).toArray ());
67+ iterationOrders = CollectionUtils .newEnumMap (OperationCategory .class , k -> IntStream .range (0 , size ).toArray ());
68+ guiPriorities = CollectionUtils .newEnumMap (OperationCategory .class , k -> 0 );
6869 }
6970
7071 /**
@@ -81,7 +82,7 @@ public int getSize() {
8182 *
8283 * @param iterationOrder The new iteration order. Must include all slots and no duplicates.
8384 */
84- public void setIterationOrder (IterationOrderCategory category , int [] iterationOrder ) {
85+ public void setIterationOrder (OperationCategory category , int [] iterationOrder ) {
8586 if (iterationOrder .length != size )
8687 throw new IllegalArgumentException ("Iteration order size must match inventory size" );
8788
@@ -102,7 +103,7 @@ public void setIterationOrder(IterationOrderCategory category, int[] iterationOr
102103 * @param category The category of iteration operations
103104 * @return The current iteration order.
104105 */
105- public int [] getIterationOrder (IterationOrderCategory category ) {
106+ public int [] getIterationOrder (OperationCategory category ) {
106107 return iterationOrders .get (category ).clone ();
107108 }
108109
@@ -111,7 +112,7 @@ public int[] getIterationOrder(IterationOrderCategory category) {
111112 * such as {@link #addItem(UpdateReason, ItemStack)} or {@link #collectSimilar(UpdateReason, ItemStack, int)}.
112113 */
113114 public void reverseIterationOrder () {
114- for (var category : IterationOrderCategory .values ()) {
115+ for (var category : OperationCategory .values ()) {
115116 reverseIterationOrder (category );
116117 }
117118 }
@@ -121,7 +122,7 @@ public void reverseIterationOrder() {
121122 *
122123 * @param category The category of operations where the iteration order should be reversed
123124 */
124- public void reverseIterationOrder (IterationOrderCategory category ) {
125+ public void reverseIterationOrder (OperationCategory category ) {
125126 setIterationOrder (category , ArrayUtils .reversed (getIterationOrder (category )));
126127 }
127128
@@ -511,25 +512,37 @@ public void callPostUpdateEvent(@Nullable UpdateReason updateReason, int slot, @
511512 }
512513
513514 /**
514- * Gets the priority for click actions in a {@link Gui}, such as shift clicking or cursor collection
515- * with multiple {@link Inventory VirtualInventories} .
515+ * Gets the gui priority for operations of the given category.
516+ * This priority is used to determine the order in which operations are applied to gui-embedded inventories .
516517 *
517518 * @return The priority for click actions, {@link Inventory VirtualInventories} with
518519 * a higher priority get prioritized.
519520 */
520- public int getGuiPriority () {
521- return guiPriority ;
521+ public int getGuiPriority (OperationCategory category ) {
522+ return guiPriorities . get ( category ) ;
522523 }
523524
524525 /**
525- * Sets the priority for click actions in a {@link Gui}, such as shift-clicking or cursor collection
526- * with multiple {@link Inventory VirtualInventories} .
526+ * Sets the gui priority for all operation types.
527+ * This priority is used to determine the order in which operations are applied to gui-embedded inventories .
527528 *
528- * @param guiPriority The priority for click actions, {@link Inventory VirtualInventories} with
529- * a higher priority get prioritized.
529+ * @param priority The priority
530530 */
531- public void setGuiPriority (int guiPriority ) {
532- this .guiPriority = guiPriority ;
531+ public void setGuiPriority (int priority ) {
532+ for (var category : OperationCategory .values ()) {
533+ setGuiPriority (category , priority );
534+ }
535+ }
536+
537+ /**
538+ * Sets the gui priority for operations of the given category.
539+ * This priority is used to determine the order in which operations are applied to gui-embedded inventories.
540+ *
541+ * @param category The category of operations to set the priority for.
542+ * @param priority The priority
543+ */
544+ public void setGuiPriority (OperationCategory category , int priority ) {
545+ guiPriorities .put (category , priority );
533546 }
534547
535548 /**
@@ -1016,7 +1029,7 @@ private int addToPartialSlots(
10161029 int amountLeft ,
10171030 @ Nullable ItemStack [] items
10181031 ) {
1019- for (int slot : getIterationOrder (IterationOrderCategory .ADD )) {
1032+ for (int slot : getIterationOrder (OperationCategory .ADD )) {
10201033 if (amountLeft <= 0 )
10211034 break ;
10221035
@@ -1059,7 +1072,7 @@ private int addToEmptySlots(
10591072 int amountLeft ,
10601073 @ Nullable ItemStack [] items
10611074 ) {
1062- for (int slot : getIterationOrder (IterationOrderCategory .ADD )) {
1075+ for (int slot : getIterationOrder (OperationCategory .ADD )) {
10631076 if (amountLeft <= 0 )
10641077 break ;
10651078
@@ -1177,7 +1190,7 @@ public int simulateSingleAdd(@Nullable ItemStack itemStack) {
11771190 int amountLeft = itemStack .getAmount ();
11781191
11791192 // find all slots where the item partially fits
1180- for (int slot : getIterationOrder (IterationOrderCategory .ADD )) {
1193+ for (int slot : getIterationOrder (OperationCategory .ADD )) {
11811194 if (amountLeft == 0 )
11821195 break ;
11831196
@@ -1194,7 +1207,7 @@ public int simulateSingleAdd(@Nullable ItemStack itemStack) {
11941207 }
11951208
11961209 // remaining items would be added to empty slots
1197- for (int slot : getIterationOrder (IterationOrderCategory .ADD )) {
1210+ for (int slot : getIterationOrder (OperationCategory .ADD )) {
11981211 if (amountLeft == 0 )
11991212 break ;
12001213
@@ -1256,7 +1269,7 @@ public int collectSimilar(@Nullable UpdateReason updateReason, ItemStack templat
12561269 @ Nullable ItemStack [] items = getUnsafeItems ();
12571270
12581271 // find partial slots and take items from there
1259- for (int slot : getIterationOrder (IterationOrderCategory .COLLECT )) {
1272+ for (int slot : getIterationOrder (OperationCategory .COLLECT )) {
12601273 ItemStack currentStack = items [slot ];
12611274 if (currentStack == null || currentStack .getAmount () >= maxStackSize || !template .isSimilar (currentStack ))
12621275 continue ;
@@ -1267,7 +1280,7 @@ public int collectSimilar(@Nullable UpdateReason updateReason, ItemStack templat
12671280 }
12681281
12691282 // only taking from partial stacks wasn't enough, take from a full slot
1270- for (int slot : getIterationOrder (IterationOrderCategory .COLLECT )) {
1283+ for (int slot : getIterationOrder (OperationCategory .COLLECT )) {
12711284 ItemStack currentStack = items [slot ];
12721285 if (currentStack == null || currentStack .getAmount () < maxStackSize || !template .isSimilar (currentStack ))
12731286 continue ;
@@ -1292,7 +1305,7 @@ public int removeIf(@Nullable UpdateReason updateReason, Predicate<ItemStack> pr
12921305 @ Nullable ItemStack [] items = getUnsafeItems ();
12931306
12941307 int removed = 0 ;
1295- for (int slot : getIterationOrder (IterationOrderCategory .OTHER )) {
1308+ for (int slot : getIterationOrder (OperationCategory .OTHER )) {
12961309 ItemStack item = items [slot ];
12971310 if (item != null && predicate .test (item .clone ()) && setItem (updateReason , slot , null )) {
12981311 removed += item .getAmount ();
@@ -1314,7 +1327,7 @@ public int removeFirst(@Nullable UpdateReason updateReason, int amount, Predicat
13141327 @ Nullable ItemStack [] items = getUnsafeItems ();
13151328
13161329 int leftOver = amount ;
1317- for (int slot : getIterationOrder (IterationOrderCategory .OTHER )) {
1330+ for (int slot : getIterationOrder (OperationCategory .OTHER )) {
13181331 ItemStack item = items [slot ];
13191332 if (item != null && predicate .test (item .clone ())) {
13201333 leftOver -= takeFrom (updateReason , slot , leftOver );
@@ -1336,7 +1349,7 @@ public int removeSimilar(@Nullable UpdateReason updateReason, ItemStack itemStac
13361349 @ Nullable ItemStack [] items = getUnsafeItems ();
13371350
13381351 int removed = 0 ;
1339- for (int slot : getIterationOrder (IterationOrderCategory .OTHER )) {
1352+ for (int slot : getIterationOrder (OperationCategory .OTHER )) {
13401353 ItemStack item = items [slot ];
13411354 if (item != null && item .isSimilar (itemStack ) && setItem (updateReason , slot , null )) {
13421355 removed += item .getAmount ();
@@ -1358,7 +1371,7 @@ public int removeFirstSimilar(@Nullable UpdateReason updateReason, int amount, I
13581371 @ Nullable ItemStack [] items = getUnsafeItems ();
13591372
13601373 int leftOver = amount ;
1361- for (int slot : getIterationOrder (IterationOrderCategory .OTHER )) {
1374+ for (int slot : getIterationOrder (OperationCategory .OTHER )) {
13621375 ItemStack item = items [slot ];
13631376 if (item != null && item .isSimilar (itemStack )) {
13641377 leftOver -= takeFrom (updateReason , slot , leftOver );
0 commit comments