Class in @minecraft/server
Extends ItemComponent
How worn an item with durability is.
import { ItemDurabilityComponent } from '@minecraft/server';Example
Section titled “Example”import { ItemStack, type ItemDurabilityComponent } from '@minecraft/server';
const item = new ItemStack('minecraft:diamond_sword');const component: ItemDurabilityComponent | undefined = item.getComponent('minecraft:durability');if (component) { console.log(item.typeId, component.damage);}import { ItemStack } from '@minecraft/server';
const item = new ItemStack('minecraft:diamond_sword');const component = item.getComponent('minecraft:durability');if (component) { console.log(item.typeId, component.damage);}Properties
Section titled “Properties”componentId
Section titled “componentId”static read-only
static readonly componentId = "minecraft:durability";damage
Section titled “damage”damage: number;How much it’s worn, from 0 to maxDurability. Setting it changes the stack.
Throws
- Error outside that range.
maxDurability
Section titled “maxDurability”read-only
readonly maxDurability: number;Methods
Section titled “Methods”getDamageChance
Section titled “getDamageChance”getDamageChance(unbreakingEnchantmentLevel?: number): number;The chance in a hundred that a use wears the item, at a level of unbreaking.
Parameters
unbreakingEnchantmentLeveloptionalnumber
Returns
numbergetDamageChanceRange
Section titled “getDamageChanceRange”getDamageChanceRange(): { min: number; max: number };Returns
{ min: number; max: number }Used by
Section titled “Used by”ItemComponentTypeMap.durability, ItemComponentTypeMap.minecraft:durability
Inherited
Section titled “Inherited”From ItemComponent: typeId, isValid