Skip to content

@minecraft/server


@minecraft/server / EntityQueryOptions

Interface: EntityQueryOptions ​

Defined in: @minecraft/server/index.d.ts:23678

Contains options for selecting entities within an area.

Examples ​

blockConditional.ts

typescript
import { DimensionLocation } from '@minecraft/server';

function blockConditional(targetLocation: DimensionLocation) {
  targetLocation.dimension
    .getEntities({
      type: 'fox',
    })
    .filter(entity => {
      const block = targetLocation.dimension.getBlock({
        x: entity.location.x,
        y: entity.location.y - 1,
        z: entity.location.z,
      });

      return block !== undefined && block.matches('minecraft:stone');
    })
    .forEach(entity => {
      targetLocation.dimension.spawnEntity('salmon', entity.location);
    });
}

findEntitiesHavingPropertyEqualsTo.ts

typescript
import { EntityQueryOptions, DimensionLocation } from '@minecraft/server';

function findEntitiesHavingPropertyEqualsTo(targetLocation: DimensionLocation) {
  // Minecraft bees have a has_nectar boolean property
  const queryOption: EntityQueryOptions = {
    propertyOptions: [{ propertyId: 'minecraft:has_nectar', value: { equals: true } }],
  };

  const entities = targetLocation.dimension.getEntities(queryOption);
}

playSoundChained.ts

typescript
import { DimensionLocation } from '@minecraft/server';

function playSoundChained(targetLocation: DimensionLocation) {
  const targetPlayers = targetLocation.dimension.getPlayers();
  const originEntities = targetLocation.dimension.getEntities({
    type: 'armor_stand',
    name: 'myArmorStand',
    tags: ['dummyTag1'],
    excludeTags: ['dummyTag2'],
  });

  originEntities.forEach(entity => {
    targetPlayers.forEach(player => {
      player.playSound('raid.horn');
    });
  });
}

setScoreboardChained.ts

typescript
import { world, DimensionLocation } from '@minecraft/server';

function setScoreboardChained(targetLocation: DimensionLocation) {
  const objective = world.scoreboard.addObjective('scoreObjective1', 'dummy');
  targetLocation.dimension
    .getEntities({
      type: 'armor_stand',
      name: 'myArmorStand',
    })
    .forEach(entity => {
      if (entity.scoreboardIdentity !== undefined) {
        objective.setScore(entity.scoreboardIdentity, -1);
      }
    });
}

summonMobChained.ts

typescript
import { DimensionLocation } from '@minecraft/server';

function summonMobChained(targetLocation: DimensionLocation) {
  const armorStandArray = targetLocation.dimension.getEntities({
    type: 'armor_stand',
  });
  const playerArray = targetLocation.dimension.getPlayers({
    location: { x: 0, y: -60, z: 0 },
    closest: 4,
    maxDistance: 15,
  });
  armorStandArray.forEach(entity => {
    playerArray.forEach(player => {
      targetLocation.dimension.spawnEntity('pig', {
        x: player.location.x + 1,
        y: player.location.y,
        z: player.location.z,
      });
    });
  });
}

bounceSkeletons.ts

typescript
import { EntityQueryOptions, DimensionLocation } from '@minecraft/server';

function bounceSkeletons(targetLocation: DimensionLocation) {
  const mobs = ['creeper', 'skeleton', 'sheep'];

  // create some sample mob data
  for (let i = 0; i < 10; i++) {
    targetLocation.dimension.spawnEntity(mobs[i % mobs.length], targetLocation);
  }

  const eqo: EntityQueryOptions = {
    type: 'skeleton',
  };

  for (const entity of targetLocation.dimension.getEntities(eqo)) {
    entity.applyKnockback(0, 0, 0, 1);
  }
}

tagsQuery.ts

typescript
import { EntityQueryOptions, DimensionLocation } from '@minecraft/server';

function tagsQuery(targetLocation: DimensionLocation) {
  const mobs = ['creeper', 'skeleton', 'sheep'];

  // create some sample mob data
  for (let i = 0; i < 10; i++) {
    const mobTypeId = mobs[i % mobs.length];
    const entity = targetLocation.dimension.spawnEntity(mobTypeId, targetLocation);
    entity.addTag('mobparty.' + mobTypeId);
  }

  const eqo: EntityQueryOptions = {
    tags: ['mobparty.skeleton'],
  };

  for (const entity of targetLocation.dimension.getEntities(eqo)) {
    entity.kill();
  }
}

testThatEntityIsFeatherItem.ts

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

Extends ​

Properties ​

closest? ​

optional closest?: number

Defined in: @minecraft/server/index.d.ts:23687

Remarks ​

Limits the number of entities to return, opting for the closest N entities as specified by this property. The location value must also be specified on the query options object.


excludeFamilies? ​

optional excludeFamilies?: string[]

Defined in: @minecraft/server/index.d.ts:23261

Remarks ​

Excludes entities that match one or more of the specified families.

Inherited from ​

EntityFilter.excludeFamilies


excludeGameModes? ​

optional excludeGameModes?: GameMode[]

Defined in: @minecraft/server/index.d.ts:23268

Remarks ​

Excludes entities if have a specific gamemode that matches the specified gamemode.

Inherited from ​

EntityFilter.excludeGameModes


excludeNames? ​

optional excludeNames?: string[]

Defined in: @minecraft/server/index.d.ts:23275

Remarks ​

Excludes entities that have a name that match one of the specified values.

Inherited from ​

EntityFilter.excludeNames


excludeTags? ​

optional excludeTags?: string[]

Defined in: @minecraft/server/index.d.ts:23282

Remarks ​

Excludes entities with a tag that matches one of the specified values.

Inherited from ​

EntityFilter.excludeTags


excludeTypes? ​

optional excludeTypes?: string[]

Defined in: @minecraft/server/index.d.ts:23288

Remarks ​

Excludes entities if they are one of the specified types.

Inherited from ​

EntityFilter.excludeTypes


families? ​

optional families?: string[]

Defined in: @minecraft/server/index.d.ts:23295

Remarks ​

If specified, includes entities that match all of the specified families.

Inherited from ​

EntityFilter.families


farthest? ​

optional farthest?: number

Defined in: @minecraft/server/index.d.ts:23696

Remarks ​

Limits the number of entities to return, opting for the farthest N entities as specified by this property. The location value must also be specified on the query options object.


gameMode? ​

optional gameMode?: GameMode

Defined in: @minecraft/server/index.d.ts:23302

Remarks ​

If specified, includes entities with a gamemode that matches the specified gamemode.

Inherited from ​

EntityFilter.gameMode


location? ​

optional location?: Vector3

Defined in: @minecraft/server/index.d.ts:23704

Remarks ​

Adds a seed location to the query that is used in conjunction with closest, farthest, limit, volume, and distance properties.


maxDistance? ​

optional maxDistance?: number

Defined in: @minecraft/server/index.d.ts:23712

Remarks ​

If specified, includes entities that are less than this distance away from the location specified in the location property.


maxHorizontalRotation? ​

optional maxHorizontalRotation?: number

Defined in: @minecraft/server/index.d.ts:23309

Remarks ​

If specified, will only include entities that have at most this horizontal rotation.

Inherited from ​

EntityFilter.maxHorizontalRotation


maxLevel? ​

optional maxLevel?: number

Defined in: @minecraft/server/index.d.ts:23316

Remarks ​

If defined, only players that have at most this level are returned.

Inherited from ​

EntityFilter.maxLevel


maxVerticalRotation? ​

optional maxVerticalRotation?: number

Defined in: @minecraft/server/index.d.ts:23323

Remarks ​

If specified, only entities that have at most this vertical rotation are returned.

Inherited from ​

EntityFilter.maxVerticalRotation


minDistance? ​

optional minDistance?: number

Defined in: @minecraft/server/index.d.ts:23719

Remarks ​

If specified, includes entities that are least this distance away from the location specified in the location property.


minHorizontalRotation? ​

optional minHorizontalRotation?: number

Defined in: @minecraft/server/index.d.ts:23330

Remarks ​

If specified, will only include entities that have at a minimum this horizontal rotation.

Inherited from ​

EntityFilter.minHorizontalRotation


minLevel? ​

optional minLevel?: number

Defined in: @minecraft/server/index.d.ts:23337

Remarks ​

If defined, only players that have at least this level are returned.

Inherited from ​

EntityFilter.minLevel


minVerticalRotation? ​

optional minVerticalRotation?: number

Defined in: @minecraft/server/index.d.ts:23344

Remarks ​

If specified, will only include entities that have at least this vertical rotation.

Inherited from ​

EntityFilter.minVerticalRotation


name? ​

optional name?: string

Defined in: @minecraft/server/index.d.ts:23350

Remarks ​

Includes entities with the specified name.

Inherited from ​

EntityFilter.name


propertyOptions? ​

optional propertyOptions?: EntityQueryPropertyOptions[]

Defined in: @minecraft/server/index.d.ts:23351

Inherited from ​

EntityFilter.propertyOptions


scoreOptions? ​

optional scoreOptions?: EntityQueryScoreOptions[]

Defined in: @minecraft/server/index.d.ts:23358

Remarks ​

Gets/sets a collection of EntityQueryScoreOptions objects with filters for specific scoreboard objectives.

Inherited from ​

EntityFilter.scoreOptions


tags? ​

optional tags?: string[]

Defined in: @minecraft/server/index.d.ts:23364

Remarks ​

Includes entities that match all of the specified tags.

Inherited from ​

EntityFilter.tags


type? ​

optional type?: string

Defined in: @minecraft/server/index.d.ts:23370

Remarks ​

If defined, entities that match this type are included.

Inherited from ​

EntityFilter.type


volume? ​

optional volume?: Vector3

Defined in: @minecraft/server/index.d.ts:23726

Remarks ​

In conjunction with location, specified a cuboid volume of entities to include.