The EntitySpawnAfterEvent interface in @minecraft/server.
Interface in @minecraft/server
import type { EntitySpawnAfterEvent } from '@minecraft/server';Subscribe to it with world.afterEvents.entitySpawn.
Example
Section titled “Example”import { world, type EntitySpawnAfterEvent } from '@minecraft/server';
world.afterEvents.entitySpawn.subscribe((event: EntitySpawnAfterEvent) => { console.log('entitySpawn', event.entity.typeId, event.cause, event.natural);});import { world } from '@minecraft/server';
world.afterEvents.entitySpawn.subscribe((event) => { console.log('entitySpawn', event.entity.typeId, event.cause, event.natural);});Properties
Section titled “Properties”entity
Section titled “entity”read-only
readonly entity: Entity;Types
read-only
readonly cause: string;Always Spawned in Basalt.
natural
Section titled “natural”read-only
readonly natural: boolean;Whether it spawned on its own, as mobs do at night.
Used by
Section titled “Used by”WorldAfterEvents.entitySpawn, EntitySpawnAfterEventSignal.subscribe, EntitySpawnAfterEventSignal.unsubscribe