A class that provides system-level events and functions.

Hierarchy

  • System

Constructors

Properties

afterEvents: SystemAfterEvents

Remarks

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

beforeEvents: SystemBeforeEvents

Remarks

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

currentTick: number

Remarks

Represents the current world tick of the server.

Methods

  • Beta

    Parameters

    • jobId: number

    Returns void

  • Parameters

    • runId: number

    Returns void

    Remarks

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

    Example

    clearRun.js

    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.

        • (): void
        • Returns void

    Returns number

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

    Remarks

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

    Example

    trapTick.ts

      const overworld = mc.world.getDimension("overworld");

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

    mc.system.run(trapTick);

    Example

    run.js

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

    • callback: (() => void)

      Functional code that will run when this interval occurs.

        • (): void
        • Returns void

    • Optional tickInterval: number

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

      Optional

    Returns number

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

    Remarks

    Runs a set of code on an interval.

    Example

    every30Seconds.ts

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

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

    Parameters

    • generator: Generator<void, void, void>

    Returns number

  • Parameters

    • callback: (() => void)

      Functional code that will run when this timeout occurs.

        • (): void
        • Returns void

    • Optional tickDelay: number

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

      Optional

    Returns number

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

    Remarks

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

    Example

    runTimeout.js

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

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

Generated using TypeDoc