类 ItemEnchantableComponent实验性

When present on an item, this item can have enchantments applied to it.

层级 (查看层级一览)

属性

isValid: boolean

返回组件是否有效。若组件的拥有者有效,并且组件需要的任何 额外验证也通过,则该组件被认为是有效的。

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.

This property can throw when used.

typeId: string

组件的标识符。 Identifier of the component.

componentId: "minecraft:enchantable" = 'minecraft:enchantable'

方法

  • 实验性

    参数

    • enchantment: Enchantment

      The enchantment interface to be added.

    返回 void

    Adds an enchantment to the item stack.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    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

    EnchantmentTypeUnknownIdError

    Error

  • 实验性

    参数

    • enchantments: Enchantment[]

      The list of enchantments to be added.

    返回 void

    Adds a list of enchantments to the item stack.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    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

    EnchantmentTypeUnknownIdError

    Error

  • 实验性

    参数

    • enchantment: Enchantment

      The enchantment interface to be added.

    返回 boolean

    Returns true if the enchantment can be added to the item stack.

    Checks whether an enchantment can be added to the item stack.

    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

    EnchantmentTypeUnknownIdError

  • 实验性

    参数

    返回 Enchantment

    Returns the enchantment if it exists on the item stack.

    Gets the enchantment of a given type from the item stack.

    ScriptItemEnchantmentUnknownIdError: Exception thrown if the enchantment type does not exist.

    EnchantmentTypeUnknownIdError

  • 实验性

    返回 Enchantment[]

    Returns a list of enchantments on the item stack.

    Gets all enchantments on the item stack.

    This function can throw errors.

  • 实验性

    参数

    • enchantmentType: string | EnchantmentType

      The enchantment type to check for.

    返回 boolean

    Returns true if the item stack has the enchantment type.

    Checks whether an item stack has a given enchantment type.

    ScriptItemEnchantmentUnknownIdError: Exception thrown if the enchantment type does not exist.

    EnchantmentTypeUnknownIdError

  • 实验性

    返回 void

    Removes all enchantments applied to this item stack.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    This function can throw errors.

  • 实验性

    参数

    返回 void

    Removes an enchantment of the given type.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    ScriptItemEnchantmentUnknownIdError: Exception thrown if the enchantment type does not exist.

    EnchantmentTypeUnknownIdError

    Error