A class that provides system-level events and functions.

Properties

afterEvents: SystemAfterEvents

Returns a collection of after-events for system-level operations.

currentTick: number

Represents the current world tick of the server.

Methods

  • Parameters

    • runId: number

    Returns void

    Cancels the execution of a function run that was previously scheduled via System.run.

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

    const runId = system.run(() => {
    console.log("Running callback function...");
    });

    // Clear the run, so it will not run again.
    system.clearRun(runId);
  • Parameters

    • callback: () => void

      Function callback to run when the tickDelay time criteria is met.

    Returns number

    An opaque identifier that can be used with the clearRun function to cancel the execution of this run.

    Runs a specified function at a future time. This is frequently used to implement delayed behaviors and game loops.

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

    function printEveryMinute() {
    try {
    // Minecraft runs at 20 ticks per second.
    if (system.currentTick % 1200 === 0) {
    world.sendMessage('Another minute passes...');
    }
    } catch (e) {
    console.warn('Error: ' + e);
    }

    system.run(printEveryMinute);
    }

    printEveryMinute();
    import { system } from "@minecraft/server";

    const runId = system.run(() => {
    console.log("Running callback function...");
    });
  • Parameters

    • callback: () => void

      Functional code that will run when this interval occurs.

    • OptionaltickInterval: number

      An interval of every N ticks that the callback will be called upon.

    Returns number

    An opaque handle that can be used with the clearRun method to stop the run of this function on an interval.

    Runs a set of code on an interval.

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

    const intervalRunIdentifier = Math.floor(Math.random() * 10000);

    system.runInterval(() => {
    world.sendMessage('This is an interval run ' + intervalRunIdentifier + ' sending a message every 30 seconds.');
    }, 600);
  • Parameters

    • callback: () => void

      Functional code that will run when this timeout occurs.

    • OptionaltickDelay: number

      Amount of time, in ticks, before the interval will be called.

    Returns number

    An opaque handle that can be used with the clearRun method to stop the run of this function on an interval.

    Runs a set of code at a future time specified by tickDelay.

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

    system.runTimeout(() => {
    console.log("Running callback function after delay...");
    }, TicksPerSecond * 5); // Tick delay of 5 seconds