Skip to content

Commit 387fb13

Browse files
Increase default inventory max stack size to 99
With the max stack size component, item stacks can be stacked up to 99. This commit increases the default max stack size for slots in virtual inventories to 99 to allow such items. Additionally, the max stack size of referencing inventories now uses the max stack size of the referenced inventory.
1 parent 58acc9c commit 387fb13

6 files changed

Lines changed: 31 additions & 20 deletions

File tree

invui/src/main/java/xyz/xenondevs/invui/inventory/Inventory.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@
5454
*/
5555
public sealed abstract class Inventory implements Observable permits VirtualInventory, CompositeInventory, ObscuredInventory, ReferencingInventory {
5656

57+
/**
58+
* The default maximum stack size of slots in inventories.
59+
* Note that the actual maximum stack size of item stacks is also limited
60+
* by their max stack size component.
61+
*/
62+
public static int DEFAULT_MAX_STACK_SIZE = 99;
63+
5764
private final int size;
5865
private final List<Set<ObserverAtSlot>> observers;
5966
private @Nullable List<Consumer<? super InventoryClickEvent>> clickHandlers;
@@ -581,11 +588,12 @@ public int getMaxStackSize(int slot, int alternative) {
581588
* parameter will be used to determine a potential maximum stack size.
582589
*
583590
* @param slot The slot
584-
* @param alternativeFrom The alternative {@link ItemStack} to determine the potential maximum stack size. Uses 64 if null.
591+
* @param alternativeFrom The alternative {@link ItemStack} to determine the potential maximum stack size.
592+
* Uses {@link #DEFAULT_MAX_STACK_SIZE} if null.
585593
* @return The current maximum allowed stack size on the specific slot.
586594
*/
587595
public int getMaxStackSize(int slot, @Nullable ItemStack alternativeFrom) {
588-
int itemMaxStackSize = alternativeFrom == null ? 64 : alternativeFrom.getMaxStackSize();
596+
int itemMaxStackSize = alternativeFrom == null ? DEFAULT_MAX_STACK_SIZE : alternativeFrom.getMaxStackSize();
589597
return getMaxStackSize(slot, itemMaxStackSize);
590598
}
591599

@@ -606,11 +614,12 @@ public int getMaxSlotStackSize(int slot, int alternative) {
606614
* The returned value will be a minimum of the maximum stack size of both the slot and the alternativeFrom parameter.
607615
*
608616
* @param slot The slot
609-
* @param alternativeFrom The alternative {@link ItemStack} to determine the potential maximum stack size. Uses 64 if null.
617+
* @param alternativeFrom The alternative {@link ItemStack} to determine the potential maximum stack size.
618+
* Uses {@link #DEFAULT_MAX_STACK_SIZE} if null.
610619
* @return The maximum stack size on that slot
611620
*/
612621
public int getMaxSlotStackSize(int slot, @Nullable ItemStack alternativeFrom) {
613-
int itemMaxStackSize = alternativeFrom == null ? 64 : alternativeFrom.getMaxStackSize();
622+
int itemMaxStackSize = alternativeFrom == null ? DEFAULT_MAX_STACK_SIZE : alternativeFrom.getMaxStackSize();
614623
return getMaxSlotStackSize(slot, itemMaxStackSize);
615624
}
616625

invui/src/main/java/xyz/xenondevs/invui/inventory/InventoryAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public int getSize() {
2929

3030
@Override
3131
public int getMaxStackSize() {
32-
return Arrays.stream(inventory.getMaxStackSizes()).max().orElse(64);
32+
return Arrays.stream(inventory.getMaxStackSizes()).max().orElse(Inventory.DEFAULT_MAX_STACK_SIZE);
3333
}
3434

3535
@Override

invui/src/main/java/xyz/xenondevs/invui/inventory/ReferencingInventory.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
*/
2727
public sealed class ReferencingInventory extends xyz.xenondevs.invui.inventory.Inventory {
2828

29-
private static final int MAX_STACK_SIZE = 64;
30-
3129
protected final Inventory inventory;
3230
protected final Function<Inventory, @Nullable ItemStack[]> itemsGetter;
3331
protected final BiFunction<Inventory, Integer, @Nullable ItemStack> itemGetter;
@@ -54,7 +52,7 @@ private ReferencingInventory(
5452
this.itemGetter = itemGetter;
5553
this.itemSetter = itemSetter;
5654
this.maxStackSizes = new int[getSize()];
57-
Arrays.fill(maxStackSizes, MAX_STACK_SIZE);
55+
Arrays.fill(maxStackSizes, inventory.getMaxStackSize());
5856
}
5957

6058
/**
@@ -95,7 +93,7 @@ public int[] getMaxStackSizes() {
9593

9694
@Override
9795
public int getMaxSlotStackSize(int slot) {
98-
return MAX_STACK_SIZE;
96+
return inventory.getMaxStackSize();
9997
}
10098

10199
@Override

invui/src/main/java/xyz/xenondevs/invui/inventory/VirtualInventory.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public final class VirtualInventory extends Inventory {
3737
* @param uuid The {@link UUID} of this {@link VirtualInventory}. Can be null, only used for serialization.
3838
* @param size The amount of slots this {@link VirtualInventory} has.
3939
* @param items A predefined array of content. Can be null.
40-
* @param maxStackSizes An array of maximum allowed stack sizes for each slot in the {@link VirtualInventory}. Can be null for 64.
40+
* @param maxStackSizes An array of maximum allowed stack sizes for each slot in the {@link VirtualInventory}.
41+
* Can be null for {@link Inventory#DEFAULT_MAX_STACK_SIZE}.
4142
* @throws IllegalArgumentException If the given size does not match the length of the items array or the length of the stackSizes array.
4243
*/
4344
public VirtualInventory(@Nullable UUID uuid, int size, @Nullable ItemStack @Nullable [] items, int @Nullable [] maxStackSizes) {
@@ -51,7 +52,7 @@ public VirtualInventory(@Nullable UUID uuid, int size, @Nullable ItemStack @Null
5152
this.maxStackSizes = maxStackSizes;
5253
} else {
5354
this.maxStackSizes = new int[size];
54-
Arrays.fill(this.maxStackSizes, 64);
55+
Arrays.fill(this.maxStackSizes, Inventory.DEFAULT_MAX_STACK_SIZE);
5556
}
5657

5758
if (items != null) {
@@ -73,7 +74,8 @@ public VirtualInventory(@Nullable UUID uuid, int size, @Nullable ItemStack @Null
7374
*
7475
* @param size The amount of slots this {@link VirtualInventory} has.
7576
* @param items A predefined array of content. Can be null.
76-
* @param maxStackSizes An array of maximum allowed stack sizes for each slot in the {@link VirtualInventory}. Can be null for 64.
77+
* @param maxStackSizes An array of maximum allowed stack sizes for each slot in the {@link VirtualInventory}.
78+
* Can be null for {@link Inventory#DEFAULT_MAX_STACK_SIZE}.
7779
*/
7880
public VirtualInventory(int size, @Nullable ItemStack @Nullable [] items, int @Nullable [] maxStackSizes) {
7981
this(null, size, items, maxStackSizes);
@@ -84,7 +86,8 @@ public VirtualInventory(int size, @Nullable ItemStack @Nullable [] items, int @N
8486
*
8587
* @param uuid The {@link UUID} of this {@link VirtualInventory}. Can be null, only used for serialization.
8688
* @param items A predefined array of content.
87-
* @param maxStackSizes An array of maximum allowed stack sizes for each slot in the {@link VirtualInventory}. Can be null for 64.
89+
* @param maxStackSizes An array of maximum allowed stack sizes for each slot in the {@link VirtualInventory}.
90+
* Can be null for {@link Inventory#DEFAULT_MAX_STACK_SIZE}.
8891
*/
8992
public VirtualInventory(@Nullable UUID uuid, @Nullable ItemStack[] items, int @Nullable [] maxStackSizes) {
9093
this(uuid, items.length, items, maxStackSizes);
@@ -94,7 +97,8 @@ public VirtualInventory(@Nullable UUID uuid, @Nullable ItemStack[] items, int @N
9497
* Constructs a new {@link VirtualInventory}
9598
*
9699
* @param items A predefined array of content.
97-
* @param maxStackSizes An array of maximum allowed stack sizes for each slot in the {@link VirtualInventory}. Can be null for 64.
100+
* @param maxStackSizes An array of maximum allowed stack sizes for each slot in the {@link VirtualInventory}.
101+
* Can be null for {@link Inventory#DEFAULT_MAX_STACK_SIZE}.
98102
*/
99103
public VirtualInventory(@Nullable ItemStack[] items, int @Nullable [] maxStackSizes) {
100104
this(null, items.length, items, maxStackSizes);

invui/src/main/java/xyz/xenondevs/invui/inventory/VirtualInventoryManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public VirtualInventory createNew(UUID uuid, int size) {
6161
* @param items The items of the {@link VirtualInventory}.
6262
* Can be null for an empty inventory.
6363
* @param maxStackSizes The max stack sizes of the {@link VirtualInventory}.
64-
* Can be null for the default stack size of 64.
64+
* Can be null for the default stack size of {@link Inventory#DEFAULT_MAX_STACK_SIZE}.
6565
* @return The created {@link VirtualInventory}.
6666
* @throws IllegalArgumentException If a {@link VirtualInventory} with the given UUID already exists.
6767
*/
@@ -106,14 +106,14 @@ public VirtualInventory getOrCreate(UUID uuid, int size) {
106106
* @param items The items of the {@link VirtualInventory} to create if no such inventory exists.
107107
* Can be null for an empty inventory.
108108
* @param maxStackSizes The max stack sizes of the {@link VirtualInventory}.
109-
* Can be null for the default stack size of 64.
109+
* Can be null for the default stack size of {@link Inventory#DEFAULT_MAX_STACK_SIZE}.
110110
* @return The {@link VirtualInventory} with the given UUID or a new one with the given size, items and stack sizes if no such inventory exists.
111111
*/
112112
public VirtualInventory getOrCreate(UUID uuid, int size, @Nullable ItemStack @Nullable [] items, int @Nullable [] maxStackSizes) {
113113
VirtualInventory inventory = getByUuid(uuid);
114114
if (inventory != null) {
115115
if (maxStackSizes != null) {
116-
inventory.setMaxStackSizes(ArrayUtils.copyOf(maxStackSizes, inventory.getSize(), 64));
116+
inventory.setMaxStackSizes(ArrayUtils.copyOf(maxStackSizes, inventory.getSize(), Inventory.DEFAULT_MAX_STACK_SIZE));
117117
}
118118
return inventory;
119119
} else {

invui/src/test/java/xyz/xenondevs/invui/inventory/InventoryAdapterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ void getMaxStackSize() {
5050
var backingInv = new VirtualInventory(10);
5151
var adapter = new InventoryAdapter(backingInv);
5252

53-
// Default max stack size is 64
54-
assertEquals(64, adapter.getMaxStackSize());
53+
// Default max stack size is 99
54+
assertEquals(99, adapter.getMaxStackSize());
5555

5656
// With custom max stack sizes
5757
var backingInv2 = new VirtualInventory(3, null, new int[] {32, 16, 99});
@@ -66,7 +66,7 @@ void setMaxStackSize() {
6666
var backingInv = new VirtualInventory(10);
6767
var adapter = new InventoryAdapter(backingInv);
6868

69-
assertEquals(64, adapter.getMaxStackSize());
69+
assertEquals(99, adapter.getMaxStackSize());
7070

7171
adapter.setMaxStackSize(32);
7272

0 commit comments

Comments
 (0)