-
Notifications
You must be signed in to change notification settings - Fork 30
Layouts
Layouts is a InventoryFramework feature that let you organize items in a view by “drawing” where each item should go.
Each slot in your layout corresponds to a character.
You can map items to those characters using layoutSlot.
In the example below, both “A” and “#” represent items that will be defined later in the onFirstRender trigger.
@Override
public void onInit(@NotNull ViewConfigBuilder config) {
config.layout("### A ###");
}
@Override
public void onFirstRender(@NotNull RenderContext render) {
render.layoutSlot('A', new ItemStack(Material.DIAMOND));
render.layoutSlot('#')
.withItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
}Tip
Other Inventory Framework features integrate with layouts out of the box. For instance, when using Pagination, the paginated items automatically adjust to the layout without any additional configuration.
You may have noticed that even if there are multiple “#” symbols in the layout, a single layoutSlot('#', ...) call is enough to fill all of them. Each matching character automatically gets assigned the same item or behavior.
If you want to change which item is displayed based on the slot iteration index, you can extend the layoutSlot call by providing a lambda that receives the slot’s iteration index and item builder.
@Override
public void onInit(@NotNull ViewConfigBuilder config) {
config.layout("### A ###");
}
@Override
public void onFirstRender(@NotNull RenderContext render) {
render.layoutSlot('A', new ItemStack(Material.DIAMOND));
render.layoutSlot('#', (index, item) -> item.withItem(
new ItemStack(Material.BLACK_STAINED_GLASS_PANE, index + 1))
);
}In your view configuration, you can define which layout will be applied to the view. Before doing so, keep in mind the following:
- A layout is represented as a
String[], where each string corresponds to a row. - The number of rows in the array must match the number of rows in the inventory.
- Each string in the array must have the same length as the number of inventory columns.
- If you define a layout but don’t specify a fixed inventory size, the inventory will automatically use the dimensions of the layout.
Example: In the example below, we use layout to create a black glass pane pattern around the inventory.
@Override
public void onInit(@NotNull ViewConfigBuilder config) {
config.layout(
"#########",
"# #",
"# #",
"# #",
"# #",
"#########"
);
}
@Override
public void onFirstRender(@NotNull RenderContext render) {
render.layoutSlot('#')
.withItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
}Welcome to the Inventory Framework documentation.
- Pagination — Display large collections of items across multiple pages.
- Layouts (a.k.a. Masks or Patterns) — Define visual patterns for item placement.
- Scheduled Updates
- Anvil Input — Capture text input from players using an anvil GUI.
- Dynamic Title Update — Update the inventory’s title in real time.
You can find practical examples in the examples directory.