类 EntityEquippableComponent实验性

提供对生物装备槽的访问。此组件存在于所有生物实体上。

Provides access to a mob's equipment slots. This component exists for all mob entities.

// Gives the player Elytra
import { EquipmentSlot, ItemStack, Player, EntityComponentTypes } from '@minecraft/server';
import { MinecraftItemTypes } from '@minecraft/vanilla-data';

function giveEquipment(player: Player) {
const equipmentCompPlayer = player.getComponent(EntityComponentTypes.Equippable);
if (equipmentCompPlayer) {
equipmentCompPlayer.setEquipment(EquipmentSlot.Chest, new ItemStack(MinecraftItemTypes.Elytra));
}
}

层级 (查看层级一览)

属性

entity: Entity

拥有此组件的实体。若该实体已被移除,则为 undefined。

The entity that owns this component. The entity will be undefined if it has been removed.

使用时可能会抛出异常。

This property can throw when used.

InvalidEntityError

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.

typeId: string

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

componentId: "minecraft:equippable" = 'minecraft:equippable'

方法

  • 实验性

    参数

    • equipmentSlot: EquipmentSlot

      装备槽位,例如 "head"(头部)、"chest"(胸部)、"offhand"(副手)。

      The equipment slot. e.g. "head", "chest", "offhand"

    返回 ItemStack

    返回装备在指定装备槽位中的物品。若为空,则返回 undefined。

    Returns the item equipped to the given EquipmentSlot. If empty, returns undefined.

    获取指定装备槽位中的装备物品。

    Gets the equipped item for the given EquipmentSlot.

    此函数可能会抛出错误。

    This function can throw errors.

  • 实验性

    参数

    • equipmentSlot: EquipmentSlot

      装备槽位,例如 "head"(头部)、"chest"(胸部)、"offhand"(副手)。 The equipment slot. e.g. "head", "chest", "offhand".

    返回 ContainerSlot

    返回与指定装备槽位对应的 ContainerSlot(容器槽位)。

    Returns the ContainerSlot corresponding to the given EquipmentSlot.

    获取与指定装备槽位对应的 ContainerSlot(容器槽位)。

    Gets the ContainerSlot corresponding to the given EquipmentSlot.

    此函数可能会抛出错误。

    This function can throw errors.

  • 实验性

    参数

    • equipmentSlot: EquipmentSlot

      装备槽位,例如 "head"(头部)、"chest"(胸部)、"offhand"(副手)。

      The equipment slot. e.g. "head", "chest", "offhand".

    • 可选itemStack: ItemStack

      要装备的物品。若为 undefined,则清空该槽位。

      The item to equip. If undefined, clears the slot.

    返回 boolean

    替换指定装备槽位中的物品。

    Replaces the item in the given EquipmentSlot.

    此函数无法在只读模式下调用。

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

    此函数可能会抛出错误。

    This function can throw errors.