Class: ItemEnchantableComponent
componentBeta
当此组件存在于物品上时,表示该物品可以被附魔。
When present on an item, this item can have enchantments applied to it.
Extends
Properties
isValid
readonlyisValid:boolean
Beta
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[]
Beta
Throws
This property can throw when used.
typeId
readonlytypeId:string
Beta
Remarks
组件的标识符。
Identifier of the component.
Inherited from
componentId
readonlystaticcomponentId:"minecraft:enchantable"='minecraft:enchantable'
Beta
Methods
addEnchantment()
addEnchantment(
enchantment):void
World Mutation Beta
Parameters
enchantment
要添加的附魔接口。
The enchantment interface to be added.
Returns
void
Remarks
向物品堆添加一个附魔。
Adds an enchantment 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.
ScriptItemEnchantmentTypeNotCompatibleError: Exception thrown if the enchantment is not compatible with the item stack.
EnchantmentLevelOutOfBoundsError
EnchantmentTypeNotCompatibleError
Error
addEnchantments()
addEnchantments(
enchantments):void
World Mutation Beta
Parameters
enchantments
要添加的附魔列表。
The list of enchantments to be added.
Returns
void
Remarks
向物品堆添加一组附魔。
Adds a list of enchantments to the item stack.
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
Beta
Parameters
enchantment
要添加的附魔接口。
The enchantment interface to be added.
Returns
boolean
若该附魔可以添加到物品堆,则返回 true。
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
Beta
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[]
Beta
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
Beta
Parameters
enchantmentType
string | EnchantmentType
要检查的附魔类型。
The enchantment type to check for.
Returns
boolean
若物品堆具有该附魔类型,则返回 true。
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
World Mutation Beta
Returns
void
Remarks
移除应用于此物品堆的所有附魔。
Removes all enchantments applied to this item stack.
Throws
This function can throw errors.
removeEnchantment()
removeEnchantment(
enchantmentType):void
World Mutation Beta
Parameters
enchantmentType
string | EnchantmentType
要移除的附魔类型。
The enchantment type to remove.
Returns
void
Remarks
移除指定类型的附魔。
Removes an enchantment of the given type.
Throws
ScriptItemEnchantmentUnknownIdError: Exception thrown if the enchantment type does not exist.
Error
