Class: EntitySpawnAfterEventSignal
Registers a script-based event handler for handling what happens when an entity spawns.
Example
// Register a new function that is called when a new entity is created.
import { world, EntitySpawnAfterEvent } from '@minecraft/server';
world.afterEvents.entitySpawn.subscribe((entityEvent: EntitySpawnAfterEvent) => {
const spawnLocation = entityEvent.entity.location;
world.sendMessage(
`New entity of type '${entityEvent.entity.typeId}' spawned at ${spawnLocation.x}, ${spawnLocation.y}, ${spawnLocation.z}!`,
);
});
Constructors
new EntitySpawnAfterEventSignal()
private
new EntitySpawnAfterEventSignal():EntitySpawnAfterEventSignal
Returns
Methods
subscribe()
subscribe(
callback
): (arg
) =>void
Parameters
Parameter | Type | Description |
---|---|---|
callback | (arg ) => void | Function that handles the spawn event. |
Returns
Function
Parameters
Parameter | Type |
---|---|
arg | EntitySpawnAfterEvent |
Returns
void
Remarks
Method to register an event handler for what happens when an entity spawns.
This function can't be called in read-only mode.
unsubscribe()
unsubscribe(
callback
):void
Parameters
Parameter | Type | Description |
---|---|---|
callback | (arg ) => void | Original function that was passed into the subscribe event, that is to be unregistered. |
Returns
void
Remarks
Unregisters a method that was previously subscribed to the subscription event.
This function can't be called in read-only mode.
Throws
This function can throw errors.