Registers a script-based event handler for handling what happens when an entity spawns.

Methods

  • Parameters

    Returns (arg: EntitySpawnAfterEvent) => void

    Method to register an event handler for what happens when an entity spawns.

    This function can't be called in read-only mode.

    // register a new function that is called when a new entity is created.
    mc.world.afterEvents.entitySpawn.subscribe((entityEvent: mc.EntitySpawnAfterEvent) => {
    if (entityEvent && entityEvent.entity) {
    log(`New entity of type '${entityEvent.entity.typeId}' created!`, 1);
    } else {
    log(`The entity event didn't work as expected.`, -1);
    }
    });

    mc.system.runTimeout(() => {
    createOldHorse(log, targetLocation);
    }, 20);
  • Parameters

    • callback: (arg: EntitySpawnAfterEvent) => void

      Original function that was passed into the subscribe event, that is to be unregistered.

    Returns void

    Unregisters a method that was previously subscribed to the subscription event.

    This function can't be called in read-only mode.

    This function can throw errors.