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/EntitySpawnAfterEvent.md.

Class: EntitySpawnAfterEvent

event entity

Beta

Contains data related to an entity spawning within the world.

Example

logEntitySpawnEvent.ts

import { world, system, EntitySpawnAfterEvent, DimensionLocation } from '@minecraft/server';
import { Vector3Utils } from '@minecraft/math';

function logEntitySpawnEvent(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
  // register a new function that is called when a new entity is created.
  world.afterEvents.entitySpawn.subscribe((entityEvent: EntitySpawnAfterEvent) => {
    if (entityEvent && entityEvent.entity) {
      log(`New entity of type ${entityEvent.entity.typeId} created!`, 1);
    } else {
      log(`The entity event did not work as expected.`, -1);
    }
  });

  system.runTimeout(() => {
    targetLocation.dimension.spawnEntity(
      'minecraft:horse<minecraft:ageable_grow_up>',
      Vector3Utils.add(targetLocation, { x: 0, y: 1, z: 0 })
    );
  }, 20);
}

Properties

cause

readonly cause: EntityInitializationCause

Beta

Remarks

Initialization cause (Spawned, Born ...).


entity

entity: Entity

World Mutation Beta

Remarks

Entity that was spawned.

同领域相关