Skip to main content

Class: EntityEquippableComponent

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

Examples

// 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));
}
}
// Gives the player some equipment
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.Head, new ItemStack(MinecraftItemTypes.GoldenHelmet));
equipmentCompPlayer.setEquipment(EquipmentSlot.Chest, new ItemStack(MinecraftItemTypes.IronChestplate));
equipmentCompPlayer.setEquipment(EquipmentSlot.Legs, new ItemStack(MinecraftItemTypes.DiamondLeggings));
equipmentCompPlayer.setEquipment(EquipmentSlot.Feet, new ItemStack(MinecraftItemTypes.NetheriteBoots));
equipmentCompPlayer.setEquipment(EquipmentSlot.Mainhand, new ItemStack(MinecraftItemTypes.WoodenSword));
equipmentCompPlayer.setEquipment(EquipmentSlot.Offhand, new ItemStack(MinecraftItemTypes.Shield));
} else {
console.warn('No equipment component found on player');
}
}

Extends

Constructors

new EntityEquippableComponent()

private new EntityEquippableComponent(): EntityEquippableComponent

Returns

EntityEquippableComponent

Overrides

EntityComponent . constructor

Properties

entity

Beta

readonly entity: Entity

Remarks

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

Inherited from

EntityComponent . entity


typeId

readonly typeId: string

Remarks

Identifier of the component.

Inherited from

EntityComponent . typeId


componentId

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

Methods

getEquipment()

getEquipment(equipmentSlot): ItemStack

Parameters

ParameterTypeDescription
equipmentSlotEquipmentSlotThe equipment slot. e.g. "head", "chest", "offhand"

Returns

ItemStack

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

Remarks

Gets the equipped item for the given EquipmentSlot.

Throws

This function can throw errors.


getEquipmentSlot()

getEquipmentSlot(equipmentSlot): ContainerSlot

Parameters

ParameterTypeDescription
equipmentSlotEquipmentSlotThe equipment slot. e.g. "head", "chest", "offhand".

Returns

ContainerSlot

Returns the ContainerSlot corresponding to the given EquipmentSlot.

Remarks

Gets the ContainerSlot corresponding to the given EquipmentSlot.

Throws

This function can throw errors.


isValid()

isValid(): boolean

Returns

boolean

Whether the component is valid.

Inherited from

EntityComponent . isValid

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.


setEquipment()

setEquipment(equipmentSlot, itemStack?): boolean

Parameters

ParameterTypeDescription
equipmentSlotEquipmentSlotThe equipment slot. e.g. "head", "chest", "offhand".
itemStack?ItemStackThe item to equip. If undefined, clears the slot.

Returns

boolean

Remarks

Replaces the item in the given EquipmentSlot.

This function can't be called in read-only mode.

Throws

This function can throw errors.