Skip to content
David edited this page Dec 17, 2022 · 7 revisions

Item Palette

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:
fcWdMvh

Code

ItemPaletteGUI: https://pastebin.com/NzMSaLtb
InventoryUtils: https://pastebin.com/M7DFLAJc

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));
	});
}

XML

Coming Soon...

Clone this wiki locally