Structure - NichtStudioCode/InvUI Wiki
Inspired by Bukkit's ShapedRecipe, a Structure will let you design the layout of the GUI in a similar way. Each ingredient is associated with a character and you "draw" the GUI in your code.
This is an example I stole from the [[Paged GUI]] section:
// create a structure Structure structure = new Structure("" + "# # # # # # # # #" + "# x x x x x x x #" + "# x x x x x x x #" + "# # # < # > # # #") .addIngredient('x', Marker.ITEM_LIST_SLOT) // where paged items should be put .addIngredient('#', new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setDisplayName("§r")) // this will just create a SimpleItem with the given ItemBuilder .addIngredient('<', new BackItem()) .addIngredient('>', new ForwardItem()); // use it in a GUI Builder new GUIBuilder(GUIType.PAGED_ITEMS, 9, 4).setStructure(structure); // or use it on an existing GUI gui.applyStructure(structure);
As you can see, there are many different types of ingredients that can be added: Items, Item Supplier, SlotElement, Marker Enum. When you're using an Item or SlotElement as ingredient, be aware that it will always be the same item on every slot which means that when one of them changes, every item changes. To circumvent this behavior, use an Item Supplier. This will create a new instance of the Item for every slot.
If you're reusing the same ingredients over and over again, consider registering them as global ingredients.
// Supplier is not needed here as the Item does not do anything Structure.addGlobalIngredient('#', new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setDisplayName("§r")); // These items need a supplier Structure.addGlobalIngredient('<', BackItem::new); Structure.addGlobalIngredient('>', ForwardItem::new); // adding the Marker.ITEM_LIST_SLOT as a global ingredient is also a good idea Structure.addGlobalIngredient('x', Marker.ITEM_LIST_SLOT);