-
Notifications
You must be signed in to change notification settings - Fork 85
Item Palette
David edited this page Dec 20, 2022
·
7 revisions
The purpose of this GUI is to let players choose an item out of all(or just portion of) the items in Minecraft, without having to deal with the pain of paging logic.
Example of a palette with only flammable items:
ItemPaletteGUI itemPalette = new ItemPaletteGUI.Builder("Choose an Item:")
.show(Material::isFlammable) //decide what items are displayed(e.g. flammable only)
.as(this::getDisplayItem) //how should the displayed materials look? Pass a Function<Material, GuiItem>
.build();
itemPalette.show(player);
Helper method that attaches an action to every displayed Material:
private GuiItem getDisplayItem(Material material)
{
ItemStack item = new ItemStack(material);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.GOLD + material.name());
item.setItemMeta(meta);
return new GuiItem(item, event ->
{
Player player = (Player) event.getWhoClicked();
player.closeInventory();
player.getInventory().addItem(item);
player.sendMessage(String.format(ChatColor.GOLD + "Don't get close to %s!", material));
});
}
ItemPaletteGUI: https://pastebin.com/NzMSaLtb
InventoryUtils: https://pastebin.com/M7DFLAJc
Coming Soon...