Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Extends
When present on an item, this item can have enchantments applied to it.
Properties
slots
read-only slots: EnchantmentSlot[];
Type: EnchantmentSlot[]
Notes:
- This property can throw errors when used.
Methods
- addEnchantment
- addEnchantments
- canAddEnchantment
- getEnchantment
- getEnchantments
- hasEnchantment
- removeAllEnchantments
- removeEnchantment
addEnchantment
addEnchantment(enchantment: Enchantment): void
Adds an enchantment to the item stack.
Parameters
enchantment: Enchantment
The enchantment interface to be added.
Notes:
- This function can't be called in read-only mode.
- This function can throw errors.
addEnchantments
addEnchantments(enchantments: Enchantment[]): void
Adds a list of enchantments to the item stack.
Parameters
enchantments: Enchantment[]
The list of enchantments to be added.
Notes:
- This function can't be called in read-only mode.
- This function can throw errors.
canAddEnchantment
canAddEnchantment(enchantment: Enchantment): boolean
Checks whether an enchantment can be added to the item stack.
Parameters
enchantment: Enchantment
The enchantment interface to be added.
Returns boolean - Returns true if the enchantment can be added to the item stack.
Notes:
- This function can throw errors.
getEnchantment
getEnchantment(enchantmentType: EnchantmentType | string): Enchantment | undefined
Gets the enchantment of a given type from the item stack.
Parameters
enchantmentType: EnchantmentType | string
The enchantment type to get.
Returns Enchantment | undefined - Returns the enchantment if it exists on the item stack.
Notes:
- This function can throw errors.
getEnchantments
getEnchantments(): Enchantment[]
Gets all enchantments on the item stack.
Returns Enchantment[] - Returns a list of enchantments on the item stack.
Notes:
- This function can throw errors.
hasEnchantment
hasEnchantment(enchantmentType: EnchantmentType | string): boolean
Checks whether an item stack has a given enchantment type.
Parameters
enchantmentType: EnchantmentType | string
The enchantment type to check for.
Returns boolean - Returns true if the item stack has the enchantment type.
Notes:
- This function can throw errors.
removeAllEnchantments
removeAllEnchantments(): void
Removes all enchantments applied to this item stack.
Notes:
- This function can't be called in read-only mode.
- This function can throw errors.
removeEnchantment
removeEnchantment(enchantmentType: EnchantmentType | string): void
Removes an enchantment of the given type.
Parameters
enchantmentType: EnchantmentType | string
The enchantment type to remove.
Notes:
- This function can't be called in read-only mode.
- This function can throw errors.
- Throws EnchantmentTypeUnknownIdError, Error
Constants
componentId
static read-only componentId = "minecraft:enchantable";
Type: string