diff --git a/src/main/java/net/minestom/server/inventory/Inventory.java b/src/main/java/net/minestom/server/inventory/Inventory.java index 9bfa8617d..be9c688fa 100644 --- a/src/main/java/net/minestom/server/inventory/Inventory.java +++ b/src/main/java/net/minestom/server/inventory/Inventory.java @@ -58,11 +58,7 @@ public non-sealed class Inventory extends AbstractInventory implements Viewable } private static byte generateId() { - final byte id = (byte) Math.abs((byte) ID_COUNTER.incrementAndGet()); - if (id == 0) { // zero is player's inventory id - return generateId(); - } - return id; + return (byte) ID_COUNTER.updateAndGet(i -> i + 1 >= 128 ? 1 : i + 1); } /** diff --git a/src/test/java/net/minestom/server/inventory/InventoryTest.java b/src/test/java/net/minestom/server/inventory/InventoryTest.java index f8cb90317..612e3b162 100644 --- a/src/test/java/net/minestom/server/inventory/InventoryTest.java +++ b/src/test/java/net/minestom/server/inventory/InventoryTest.java @@ -78,9 +78,9 @@ public class InventoryTest { @Test public void testIds() { - for (int i = 0; i <= 256; ++i) { - final Inventory inventory = new Inventory(InventoryType.CHEST_1_ROW, "title"); - assertTrue(inventory.getWindowId() != 0); + for (int i = 0; i <= 1000; ++i) { + final byte windowId = new Inventory(InventoryType.CHEST_1_ROW, "title").getWindowId(); + assertTrue(windowId > 0); } } }