To be able to build custom-sized InvMenu
instances, you must install the tedo0627/InventoryUIResourcePack resource pack on your server.
A custom-sized InvMenu provides several advantages over traditional ways of displaying menus (InvMenu::TYPE_CHEST
, InvMenu::TYPE_DOUBLE_CHEST
):
- Dynamic: To create a menu that can hold
n
items, you need not know the size of a chest or a double chest inventory. Instead, simply create a menu of the preferred size:CustomSizedInvMenu::create(n)
. - Block-less: Backed by an invisible entity, this menu does not require rendering a chest block strategically placed behind a player. Besides, rendering a chest block opens the server to an exploit where players can 'levitate' in the air by standing onto a fake chest block.
- More Portable: Backed by an invisible entity, this menu can be sent to players anywhere, regardless of their Y-axis position. Block-backed menus can only be sent when the player's Y value falls within the world's minimum and maximum block height (because blocks cannot be set outside world bounds).
- Low Latency: CustomSizedInvMenu renders right away, no delay necessary. On the other hand,
InvMenu::TYPE_DOUBLE_CHEST
is notoriously slow due to a 'delay' that is necessary to let the game render 'two individual chests transforming into a double chest'.
To build a 5-slot InvMenu, use CustomSizedInvMenu::create(5)
:
/** @var Player $player */
$menu = CustomSizedInvMenu::create(5);
$menu->setName("This is a 5-slot Inventory");
$menu->send($player);
Run /cinvmenu <numSlots> [title]
to open an InvMenu of numSlots
number of slots: