Class ItemBuilder

java.lang.Object
me.agent.vgui.api.item.ItemBuilder

public final class ItemBuilder extends Object
Fluent builder for PacketEvents ItemStacks that writes both modern item components (1.20.5+) and legacy NBT tags, so items render correctly on every client version from 1.8 to the latest.
ItemStack sword = ItemBuilder.of(ItemTypes.DIAMOND_SWORD)
    .name(Component.text("Excalibur", NamedTextColor.GOLD))
    .lore(Component.text("Legendary"), Component.text("Click to buy"))
    .glow()
    .build();
  • Method Summary

    Modifier and Type
    Method
    Description
    amount(int amount)
    Sets the stack size (clamped to [1, 99]).
    Shortcut for ViewItem.of(build()).
    com.github.retrooper.packetevents.protocol.item.ItemStack
    Builds the item stack.
    customModelData(int data)
    Sets custom model data (resource-pack driven models, 1.14+).
    edit(Consumer<com.github.retrooper.packetevents.protocol.item.ItemStack.Builder> editor)
    Escape hatch: mutate the underlying PacketEvents builder directly.
    Gives the item an enchantment glint without a visible enchantment.
    glow(boolean glow)
    Sets or removes the enchantment glint override.
    legacyData(int legacyData)
    Sets legacy item data (durability or metadata) for pre-1.13 clients.
    lore(List<net.kyori.adventure.text.Component> lore)
    Sets the lore lines.
    lore(net.kyori.adventure.text.Component... lore)
    Sets the lore lines.
    name(net.kyori.adventure.text.Component name)
    Sets the display name.
    of(com.github.retrooper.packetevents.protocol.item.type.ItemType type)
    Starts building an item of the given type with amount 1.
    of(com.github.retrooper.packetevents.protocol.item.type.ItemType type, int amount)
    Starts building an item of the given type and amount (clamped to [1, 99]).
    Shortcut for ViewItem.clickable(build(), onClick).
    skullOwner(String playerName)
    Sets a player-head skin by player name.
    skullTexture(String base64Texture)
    Sets a player-head texture from a base64 texture value (the Value field of a textures property, as found on skin sites).
    Marks the item unbreakable (also hides the durability bar).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • of

      public static ItemBuilder of(com.github.retrooper.packetevents.protocol.item.type.ItemType type)
      Starts building an item of the given type with amount 1.
    • of

      public static ItemBuilder of(com.github.retrooper.packetevents.protocol.item.type.ItemType type, int amount)
      Starts building an item of the given type and amount (clamped to [1, 99]).
    • name

      public ItemBuilder name(net.kyori.adventure.text.Component name)
      Sets the display name.
    • lore

      public ItemBuilder lore(net.kyori.adventure.text.Component... lore)
      Sets the lore lines.
    • lore

      public ItemBuilder lore(List<net.kyori.adventure.text.Component> lore)
      Sets the lore lines.
    • amount

      public ItemBuilder amount(int amount)
      Sets the stack size (clamped to [1, 99]).
    • glow

      public ItemBuilder glow()
      Gives the item an enchantment glint without a visible enchantment.
    • glow

      public ItemBuilder glow(boolean glow)
      Sets or removes the enchantment glint override.
    • customModelData

      public ItemBuilder customModelData(int data)
      Sets custom model data (resource-pack driven models, 1.14+).
    • unbreakable

      public ItemBuilder unbreakable()
      Marks the item unbreakable (also hides the durability bar).
    • skullTexture

      public ItemBuilder skullTexture(String base64Texture)
      Sets a player-head texture from a base64 texture value (the Value field of a textures property, as found on skin sites). Only meaningful for PLAYER_HEAD items. See Skulls.texturedHead(String) for a shortcut.
    • skullOwner

      public ItemBuilder skullOwner(String playerName)
      Sets a player-head skin by player name. The client resolves the skin itself (works for premium account names).
    • legacyData

      public ItemBuilder legacyData(int legacyData)
      Sets legacy item data (durability or metadata) for pre-1.13 clients. For example, 14 makes a STAINED_GLASS_PANE red. Modern clients ignore it.
    • edit

      public ItemBuilder edit(Consumer<com.github.retrooper.packetevents.protocol.item.ItemStack.Builder> editor)
      Escape hatch: mutate the underlying PacketEvents builder directly.
    • build

      public com.github.retrooper.packetevents.protocol.item.ItemStack build()
      Builds the item stack. The builder can be reused afterwards.
    • asItem

      public ViewItem asItem()
      Shortcut for ViewItem.of(build()).
    • onClick

      public ViewItem onClick(Consumer<ClickContext> onClick)
      Shortcut for ViewItem.clickable(build(), onClick).