Editar

Compartilhar via


EntityItemComponent Class

Extends

If added onto the entity, this indicates that the entity represents a free-floating item in the world. Lets you retrieve the actual item stack contents via the itemStack property.

Properties

itemStack

read-only itemStack: ItemStack;

Item stack represented by this entity in the world.

Type: ItemStack

Notes:

  • This property can throw errors when used.

Constants

componentId

static read-only componentId = "minecraft:item";

Type: string

Examples

testThatEntityIsFeatherItem.ts
import { EntityItemComponent, EntityComponentTypes, DimensionLocation } from '@minecraft/server';

function testThatEntityIsFeatherItem(
  log: (message: string, status?: number) => void,
  targetLocation: DimensionLocation
) {
  const items = targetLocation.dimension.getEntities({
    location: targetLocation,
    maxDistance: 20,
  });

  for (const item of items) {
    const itemComp = item.getComponent(EntityComponentTypes.Item) as EntityItemComponent;

    if (itemComp) {
      if (itemComp.itemStack.typeId.endsWith('feather')) {
        log('Success! Found a feather', 1);
      }
    }
  }
}

(preview) Work with this sample on the MCTools.dev code sandbox.