For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server/classes/EntityEquippableComponent.md.

Class: EntityEquippableComponent

entity component

Beta

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

Provides access to a mob's equipment slots. This component exists on player entities.

Example

givePlayerElytra.ts

// 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));
  }
}

Extends

Properties

entity

readonly entity: Entity

Beta

Remarks

拥有此组件的实体。如果实体已被移除,则实体将为 undefined

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

Throws

This property can throw when used.

InvalidEntityError

Inherited from

EntityComponent.entity


isValid

readonly isValid: 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

EntityComponent.isValid


totalArmor

readonly totalArmor: number

Beta

Remarks

返回拥有者的总护甲等级。

Returns the total Armor level of the owner.

Throws

This property can throw when used.

InvalidEntityError


totalToughness

readonly totalToughness: number

Beta

Remarks

返回拥有者的总韧性等级。

Returns the total Toughness level of the owner.

Throws

This property can throw when used.

InvalidEntityError


typeId

readonly typeId: string

Beta

Remarks

组件的标识符。

Identifier of the component.

Inherited from

EntityComponent.typeId


componentId

readonly static componentId: "minecraft:equippable" = 'minecraft:equippable'

Beta

Methods

getEquipment()

getEquipment(equipmentSlot): ItemStack | undefined

Beta

Parameters

equipmentSlot

EquipmentSlot

装备槽位,例如 "head""chest""offhand"

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

Returns

ItemStack | undefined

返回装备到给定 EquipmentSlot 的物品。如果为空,则返回 undefined

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

Remarks

获取给定 EquipmentSlot 的已装备物品。

Gets the equipped item for the given EquipmentSlot.

Throws

This function can throw errors.


getEquipmentSlot()

getEquipmentSlot(equipmentSlot): ContainerSlot

Beta

Parameters

equipmentSlot

EquipmentSlot

装备槽位,例如 "head""chest""offhand"

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

Returns

ContainerSlot

返回对应于给定 EquipmentSlot 的 ContainerSlot。

Returns the ContainerSlot corresponding to the given EquipmentSlot.

Remarks

获取对应于给定 EquipmentSlot 的 ContainerSlot。

Gets the ContainerSlot corresponding to the given EquipmentSlot.

Throws

This function can throw errors.


setEquipment()

setEquipment(equipmentSlot, itemStack?): boolean

World Mutation Beta

Parameters

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.

Returns

boolean

Remarks

替换给定 EquipmentSlot 中的物品。

Replaces the item in the given EquipmentSlot.

Throws

This function can throw errors.

同领域相关