类 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

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

typeId: string

Identifier of the component.

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

方法

  • 实验性

    参数

    • equipmentSlot: EquipmentSlot

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

    返回 ItemStack

    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

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

    返回 ContainerSlot

    Returns the ContainerSlot corresponding to the given EquipmentSlot.

    Gets the ContainerSlot corresponding to the given EquipmentSlot.

    This function can throw errors.

  • 实验性

    返回 boolean

    Whether the component is valid.

    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.

  • 实验性

    参数

    • equipmentSlot: EquipmentSlot

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

    • 可选itemStack: ItemStack

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

    返回 boolean

    Replaces the item in the given EquipmentSlot.

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

    This function can throw errors.