Class in @minecraft/server
Extends ItemComponent
The enchantments on an item that takes them. Changes go on the stack at once.
import { ItemEnchantableComponent } from '@minecraft/server';Example
Section titled “Example”import { ItemStack, type ItemEnchantableComponent } from '@minecraft/server';
const item = new ItemStack('minecraft:diamond_sword');const component: ItemEnchantableComponent | undefined = item.getComponent('minecraft:enchantable');if (component) { console.log(item.typeId, component.typeId);}import { ItemStack } from '@minecraft/server';
const item = new ItemStack('minecraft:diamond_sword');const component = item.getComponent('minecraft:enchantable');if (component) { console.log(item.typeId, component.typeId);}Properties
Section titled “Properties”componentId
Section titled “componentId”static read-only
static readonly componentId = "minecraft:enchantable";read-only
readonly slots: string[];Always empty in Basalt.
Methods
Section titled “Methods”addEnchantment
Section titled “addEnchantment”addEnchantment(enchantment: Enchantment): void;Puts an enchantment on, replacing the same one at another level.
Parameters
enchantmentEnchantment
Throws
- Error if the item doesn’t take it, the level is out of range, or another enchantment on it excludes this one.
Types
addEnchantments
Section titled “addEnchantments”addEnchantments(enchantments: Enchantment[]): void;Parameters
enchantmentsEnchantment[]
Types
canAddEnchantment
Section titled “canAddEnchantment”canAddEnchantment(enchantment: Enchantment): boolean;Whether addEnchantment would succeed.
Parameters
enchantmentEnchantment
Returns
booleanTypes
getEnchantment
Section titled “getEnchantment”getEnchantment(enchantmentType: EnchantmentType | string): { type: EnchantmentType; level: number } | undefined;Parameters
enchantmentTypeEnchantmentType | string
Returns
{ type: EnchantmentType; level: number } | undefinedTypes
getEnchantments
Section titled “getEnchantments”getEnchantments(): { type: EnchantmentType; level: number }[];Returns
{ type: EnchantmentType; level: number }[]Types
hasEnchantment
Section titled “hasEnchantment”hasEnchantment(enchantmentType: EnchantmentType | string): boolean;Parameters
enchantmentTypeEnchantmentType | string
Returns
booleanTypes
removeAllEnchantments
Section titled “removeAllEnchantments”removeAllEnchantments(): void;removeEnchantment
Section titled “removeEnchantment”removeEnchantment(enchantmentType: EnchantmentType | string): void;Parameters
enchantmentTypeEnchantmentType | string
Types
Used by
Section titled “Used by”ItemComponentTypeMap.enchantable, ItemComponentTypeMap.minecraft:enchantable
Inherited
Section titled “Inherited”From ItemComponent: typeId, isValid