Script API - v1.20.10
    Preparing search index...

    Contains a set of events that are available across the scope of the World.

    Index

    Properties

    This event fires for a block that is broken by a player.

    import { world } from "@minecraft/server";

    world.afterEvents.blockBreak.subscribe((event) => {
    const { brokenBlockPermutation, player } = event;

    if (brokenBlockPermutation.type.id === "minecraft:grass") {
    player.sendMessage("You broke a grass block!");
    }

    if (brokenBlockPermutation.type.id === "minecraft:stone") {
    player.sendMessage("You broke a stone block!");
    }
    });

    This event fires for each BlockLocation destroyed by an explosion. It is fired after the blocks have already been destroyed.

    This event fires for a block that is placed by a player.

    This event fires when a button is pushed.

    import { world } from "@minecraft/server";

    world.afterEvents.buttonPush.subscribe((event) => {
    console.log("Button: ", event.block.typeId);
    console.log("Dimension: ", event.dimension.id);
    console.log("Source: ", event.source.typeId);
    });

    This event is triggered after a chat message has been broadcast or sent to players.

    import { WeatherType, system, world } from "@minecraft/server";

    const chatObjective =
    world.scoreboard.getObjective("chat") ??
    world.scoreboard.addObjective("chat", "chat");

    world.afterEvents.chatSend.subscribe((event) => {
    const { sender } = event;

    const score = chatObjective.hasParticipant(sender)
    ? chatObjective.getScore(sender.scoreboardIdentity)
    : 0;
    chatObjective.setScore(sender, score + 1);
    });
    dataDrivenEntityTriggerEvent: DataDrivenEntityTriggerAfterEventSignal

    This event is fired when an entity event has been triggered that will update the component definition state of an entity.

    import { world, system, Entity } from "@minecraft/server";

    const eventId = "minecraft:entity_spawned";

    system.runInterval(() => {
    for (let player of world.getAllPlayers()) {
    let [entityRaycaseHit] = player.getEntitiesFromViewDirection({
    maxDistance: 150,
    });
    if (!entityRaycaseHit) continue;
    let entity = entityRaycaseHit.entity;

    if (entity?.typeId === "minecraft:sheep") {
    listenTo(entity);
    entity.triggerEvent(eventId);
    }
    }
    });

    function listenTo(entity: Entity) {
    const callback = world.afterEvents.dataDrivenEntityTriggerEvent.subscribe(
    (data) => {
    world.afterEvents.dataDrivenEntityTriggerEvent.unsubscribe(
    callback
    );

    data.getModifiers().forEach((modifier) => {
    console.log(
    "ComponentGroupsToAdd:",
    modifier.getComponentGroupsToAdd()
    );
    console.log(
    "ComponentGroupsToRemove:",
    modifier.getComponentGroupsToRemove()
    );
    console.log("Triggers:", modifier.getTriggers());
    });
    },
    { entities: [entity], eventTypes: [eventId] }
    );
    }

    This event fires when an effect, like poisoning, is added to an entity.

    This event fires when an entity dies.

    import { world } from "@minecraft/server";

    world.afterEvents.entityDie.subscribe((event) => {
    world.sendMessage(
    `${event.deadEntity.typeId} died from ${event.damageSource}!`
    );
    });
    import { world } from "@minecraft/server";
    world.afterEvents.entityHitEntity.subscribe((event) => {
    const location1 = event.damagingEntity.location;
    const location2 = event.hitEntity.location;

    const distance = Math.pow(
    Math.pow(location2.x - location1.x, 2) +
    Math.pow(location2.y - location1.y, 2) +
    Math.pow(location2.z - location1.z, 2),
    0.5
    );

    console.log("Distance: " + distance + " blocks");
    });
    import { world } from "@minecraft/server";
    world.afterEvents.entityHitBlock.subscribe((event) => {
    const location1 = event.damagingEntity.location;
    const location2 = event.hitBlock.location;

    const distance = Math.pow(
    Math.pow(location2.x - location1.x, 2) +
    Math.pow(location2.y - location1.y, 2) +
    Math.pow(location2.z - location1.z, 2),
    0.5
    );

    console.log("Distance: " + distance + " blocks");
    });

    This event fires when an entity is hurt (takes damage).

    This event fires when an entity is spawned.

    This event is fired after an explosion occurs.

    itemDefinitionEvent: ItemDefinitionAfterEventSignal

    For custom items, this event is triggered when the fundamental set of defined components for the item change. Note that this event is only fired for custom data-driven items.

    This event fires when a player successfully uses an item or places a block by pressing the Use Item / Place Block button. If multiple blocks are placed, this event will only occur once at the beginning of the block placement. Note: This event cannot be used with Hoe or Axe items.

    This event fires when a player releases the Use Item / Place Block button after successfully using an item. Note: This event cannot be used with Hoe or Axe items.

    This event fires when an item is successfully used by a player.

    This event fires when an item is used on a block by a player.

    This event is an internal implementation detail, and is otherwise not currently functional.

    This event fires when a piston expands or retracts.

    This event fires when a player joins a world. See also playerSpawn for another related event you can trap for when a player is spawned the first time within a world.

    import { world } from "@minecraft/server";
    world.afterEvents.playerJoin.subscribe(({ playerId, playerName }) => {
    world.sendMessage(
    `Player ${playerName} (${playerId}) has just joined the world.`
    );
    });

    This event fires when a player leaves a world.

    import { world } from "@minecraft/server";
    world.afterEvents.playerLeave.subscribe(({ playerId, playerName }) => {
    world.sendMessage(
    `Player ${playerName} (${playerId}) has just left the world.`
    );
    });

    This event fires when a player spawns or respawns. Note that an additional flag within this event will tell you whether the player is spawning right after join vs. a respawn.

    import { world } from "@minecraft/server";

    world.afterEvents.playerSpawn.subscribe((eventData) => {
    let { player, initialSpawn } = eventData;
    if (!initialSpawn) return;

    // This runs when the player joins the game for the first time!
    });

    This event will be triggered when the weather changes within Minecraft.

    This event fires when the script environment is initialized on a World. In addition, you can register dynamic properties within the scope of a world Initialize event.