diff --git a/src/main/java/net/minestom/server/inventory/Inventory.java b/src/main/java/net/minestom/server/inventory/Inventory.java index 1a0df8c04..9bfa8617d 100644 --- a/src/main/java/net/minestom/server/inventory/Inventory.java +++ b/src/main/java/net/minestom/server/inventory/Inventory.java @@ -58,7 +58,11 @@ public non-sealed class Inventory extends AbstractInventory implements Viewable } private static byte generateId() { - return (byte) Math.abs((byte) ID_COUNTER.incrementAndGet()); + final byte id = (byte) Math.abs((byte) ID_COUNTER.incrementAndGet()); + if (id == 0) { // zero is player's inventory id + return generateId(); + } + return id; } /** diff --git a/src/test/java/net/minestom/server/inventory/InventoryTest.java b/src/test/java/net/minestom/server/inventory/InventoryTest.java index fa3f976bc..f8cb90317 100644 --- a/src/test/java/net/minestom/server/inventory/InventoryTest.java +++ b/src/test/java/net/minestom/server/inventory/InventoryTest.java @@ -75,4 +75,12 @@ public class InventoryTest { assertTrue(inventory.addItemStack(ItemStack.of(Material.ANDESITE, 32), TransactionOption.ALL_OR_NOTHING)); assertFalse(inventory.addItemStack(ItemStack.of(Material.BLUE_CONCRETE, 32), TransactionOption.ALL_OR_NOTHING)); } + + @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); + } + } }