mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 01:17:47 +01:00
Fix for inventory window id generation (#1292)
This commit is contained in:
parent
edbef66f8e
commit
89a09f326e
@ -58,7 +58,11 @@ public non-sealed class Inventory extends AbstractInventory implements Viewable
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static byte generateId() {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,4 +75,12 @@ public class InventoryTest {
|
|||||||
assertTrue(inventory.addItemStack(ItemStack.of(Material.ANDESITE, 32), TransactionOption.ALL_OR_NOTHING));
|
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));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user