ItemStackBuilder

class ItemStackBuilder(item: ItemStack)

A DSL builder for creating and modifying ItemStacks in a declarative way.

This builder provides a type-safe way to configure ItemStack properties including:

  • Display name and lore

  • Enchantments

  • Item flags

  • Attributes

  • Custom model data

Example usage:

val sword = itemStack(Material.DIAMOND_SWORD) {
displayName = Component.text("Legendary Sword")
lore(
Component.text("A powerful weapon"),
Component.text("Forged in ancient times")
)
enchant(Enchantment.SHARPNESS, 5)
hideAll()
}

Throws

if the ItemStack's ItemMeta is null

Constructors

Link copied to clipboard
constructor(item: ItemStack)

Creates a builder from an existing ItemStack

constructor(material: Material, amount: Int = 1)

Creates a builder for a new ItemStack with the specified material and amount.

Properties

Link copied to clipboard
var amount: Int

The stack size of the ItemStack.

Link copied to clipboard

The custom model data value for resource pack model overrides. Returns null if no custom model data is set.

Link copied to clipboard
var displayName: Component?

The display name of the ItemStack as an Adventure Component. Set to null to remove the display name.

Link copied to clipboard
var lore: List<Component>?

The lore lines of the ItemStack as a list of Adventure Components. Set to null to remove all lore.

Link copied to clipboard
var material: Material

The material type of the ItemStack.

Functions

Link copied to clipboard
fun attribute(attribute: Attribute, modifier: AttributeModifier)

Adds an attribute modifier to the ItemStack.

Link copied to clipboard
fun build(): ItemStack

Builds and returns the configured ItemStack.

Link copied to clipboard
fun enchant(enchantment: Enchantment, level: Int = 1, ignoreLevelRestriction: Boolean = true)

Adds an enchantment to the ItemStack.

Link copied to clipboard
fun enchants(vararg enchants: Pair<Enchantment, Int>)

Adds multiple enchantments from pairs of Enchantment to level.

Link copied to clipboard
fun flags(vararg flags: ItemFlag)

Adds item flags to hide specific attributes or information.

Link copied to clipboard
fun hideAll()

Hides all possible item information by adding all ItemFlags.

Link copied to clipboard
fun lore(lines: Iterable<Component>)

Sets the lore from an iterable collection of Components.

fun lore(vararg lines: Component)

Sets the lore from vararg Component parameters.