Skip to content

Item Object

The item object represents an ItemStack (Bukkit-like). It is obtained from inventories (getItem, getItems) or created with item.create().

js
var it = item.create("minecraft:diamond_sword", 1);

Create an item

MethodDescription
item.create(name, count)Create an item with the given count
js
var it = item.create("minecraft:diamond", 64);

Methods

MethodReturnsDescription
getName()stringItem name (e.g. minecraft:diamond)
getCount()numberCount
setCount(n)itemChange count and return new item
getDisplayName()stringCustom display name
setDisplayName(name)itemSet custom display name
getLore()string[]Lore lines
setLore(lines)itemSet lore
getDurability()numberCurrent durability
setDurability(n)itemSet durability
getMaxDurability()numberMax durability
isEnchanted()booleanHas enchantments
getEnchantments(){name, level}[]Enchantments list
addEnchantment(name, level)itemAdd enchantment
removeEnchantment(name)itemRemove enchantment
clone()itemClone item

Supported enchantments

Name
sharpness
efficiency
unbreaking
silk_touch
power
punch
flame
infinity
protection
fire_protection
blast_protection
projectile_protection
feather_falling
thorns
respiration
aqua_affinity
depth_strider
mending
vanishing
fire_aspect
knockback

Examples

Create and customize an item

js
var sword = item.create("minecraft:diamond_sword", 1)
    .setDisplayName("§bEpic Sword")
    .setLore(["§7Forged in dragons", "§7Level 10"])
    .addEnchantment("sharpness", 5)
    .addEnchantment("unbreaking", 3);

Use an item in an inventory

js
var inv = player.getInventory();
inv.addItemStack(sword);

Dragonfly Script API