-
Notifications
You must be signed in to change notification settings - Fork 88
Item Palette
David edited this page Jul 6, 2023
·
7 revisions
This GUI allows players to select 1 item from 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/BU0i5Zms
InventoryUtils: https://pastebin.com/M7DFLAJc
Coming Soon...