@minecraft/server / ItemEnchantableComponent
Class: ItemEnchantableComponent ​
Defined in: @minecraft/server/index.d.ts:14122
When present on an item, this item can have enchantments applied to it.
Extends ​
Properties ​
isValid ​
readonlyisValid:boolean
Defined in: @minecraft/server/index.d.ts:6234
Remarks ​
Returns whether the component is valid. A component is considered valid if its owner is valid, in addition to any addition to any additional validation required by the component.
Inherited from ​
slots ​
readonlyslots:EnchantmentSlot[]
Defined in: @minecraft/server/index.d.ts:14127
Throws ​
This property can throw when used.
typeId ​
readonlytypeId:string
Defined in: @minecraft/server/index.d.ts:6240
Remarks ​
Identifier of the component.
Inherited from ​
componentId ​
readonlystaticcomponentId:"minecraft:enchantable"='minecraft:enchantable'
Defined in: @minecraft/server/index.d.ts:14128
Methods ​
addEnchantment() ​
addEnchantment(
enchantment):void
Defined in: @minecraft/server/index.d.ts:14158
Parameters ​
enchantment ​
The enchantment interface to be added.
Returns ​
void
Remarks ​
Adds an enchantment to the item stack.
This function can't be called in restricted-execution mode.
Throws ​
ScriptItemEnchantmentUnknownIdError: Exception thrown if the enchantment type does not exist.
ScriptItemEnchantmentLevelOutOfBoundsError: Exception thrown if the enchantment level is outside the allowable range for the given enchantment type.
ScriptItemEnchantmentTypeNotCompatibleError: Exception thrown if the enchantment is not compatible with the item stack.
EnchantmentLevelOutOfBoundsError
EnchantmentTypeNotCompatibleError
Error
addEnchantments() ​
addEnchantments(
enchantments):void
Defined in: @minecraft/server/index.d.ts:14188
Parameters ​
enchantments ​
The list of enchantments to be added.
Returns ​
void
Remarks ​
Adds a list of enchantments to the item stack.
This function can't be called in restricted-execution mode.
Throws ​
ScriptItemEnchantmentUnknownIdError: Exception thrown if any enchantment type does not exist.
ScriptItemEnchantmentLevelOutOfBoundsError: Exception thrown if any enchantment level is outside the allowable range for the given enchantment type.
ScriptItemEnchantmentTypeNotCompatibleError: Exception thrown if any enchantment is not compatible with the item stack.
EnchantmentLevelOutOfBoundsError
EnchantmentTypeNotCompatibleError
Error
canAddEnchantment() ​
canAddEnchantment(
enchantment):boolean
Defined in: @minecraft/server/index.d.ts:14212
Parameters ​
enchantment ​
The enchantment interface to be added.
Returns ​
boolean
Returns true if the enchantment can be added to the item stack.
Remarks ​
Checks whether an enchantment can be added to the item stack.
Throws ​
ScriptItemEnchantmentUnknownIdError: Exception thrown if the enchantment type does not exist.
ScriptItemEnchantmentLevelOutOfBoundsError: Exception thrown if the enchantment level is outside the allowable range for the given enchantment type.
EnchantmentLevelOutOfBoundsError
getEnchantment() ​
getEnchantment(
enchantmentType):Enchantment|undefined
Defined in: @minecraft/server/index.d.ts:14228
Parameters ​
enchantmentType ​
string | EnchantmentType
The enchantment type to get.
Returns ​
Enchantment | undefined
Returns the enchantment if it exists on the item stack.
Remarks ​
Gets the enchantment of a given type from the item stack.
Throws ​
ScriptItemEnchantmentUnknownIdError: Exception thrown if the enchantment type does not exist.
getEnchantments() ​
getEnchantments():
Enchantment[]
Defined in: @minecraft/server/index.d.ts:14237
Returns ​
Returns a list of enchantments on the item stack.
Remarks ​
Gets all enchantments on the item stack.
Throws ​
This function can throw errors.
hasEnchantment() ​
hasEnchantment(
enchantmentType):boolean
Defined in: @minecraft/server/index.d.ts:14253
Parameters ​
enchantmentType ​
string | EnchantmentType
The enchantment type to check for.
Returns ​
boolean
Returns true if the item stack has the enchantment type.
Remarks ​
Checks whether an item stack has a given enchantment type.
Throws ​
ScriptItemEnchantmentUnknownIdError: Exception thrown if the enchantment type does not exist.
removeAllEnchantments() ​
removeAllEnchantments():
void
Defined in: @minecraft/server/index.d.ts:14262
Returns ​
void
Remarks ​
Removes all enchantments applied to this item stack.
This function can't be called in restricted-execution mode.
Throws ​
This function can throw errors.
removeEnchantment() ​
removeEnchantment(
enchantmentType):void
Defined in: @minecraft/server/index.d.ts:14280
Parameters ​
enchantmentType ​
string | EnchantmentType
The enchantment type to remove.
Returns ​
void
Remarks ​
Removes an enchantment of the given type.
This function can't be called in restricted-execution mode.
Throws ​
ScriptItemEnchantmentUnknownIdError: Exception thrown if the enchantment type does not exist.
Error