类 System实验性

A class that provides system-level events and functions.

属性

afterEvents: SystemAfterEvents

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

beforeEvents: SystemBeforeEvents

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

currentTick: number

Represents the current world tick of the server.

serverSystemInfo: SystemInfo

Contains the device information for the server.

方法

  • 实验性

    参数

    • runId: number

    返回 void

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

    This function can be called in early-execution mode.

  • 实验性

    参数

    • callback: (() => void)

      Function callback to run at the next game tick.

        • (): void
        • 返回 void

    返回 number

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

    Runs a specified function at the next available future time. This is frequently used to implement delayed behaviors and game loops. When run within the context of an event handler, this will generally run the code at the end of the same tick where the event occurred. When run in other code (a system.run callout), this will run the function in the next tick. Note, however, that depending on load on the system, running in the same or next tick is not guaranteed.

    This function can be called in early-execution mode.

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

    function trapTick() {
    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(trapTick);
    }
  • 实验性

    参数

    • callback: (() => void)

      Functional code that will run when this interval occurs.

        • (): void
        • 返回 void

    • 可选tickInterval: number

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

    返回 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.

    This function can be called in early-execution mode.

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

    function every30Seconds(targetLocation: DimensionLocation) {
    const intervalRunIdentifier = Math.floor(Math.random() * 10000);

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

    参数

    • generator: Generator<void, void, void>

      The instance of the generator to run.

    返回 number

    An opaque handle that can be used with System.clearJob to stop the run of this generator.

    Queues a generator to run until completion. The generator will be given a time slice each tick, and will be run until it yields or completes.

    This function can be called in early-execution mode.

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

    function cubeGenerator(targetLocation: DimensionLocation) {
    const blockPerm = BlockPermutation.resolve("minecraft:cobblestone");

    system.runJob(blockPlacingGenerator(blockPerm, targetLocation, 15));
    }

    function* blockPlacingGenerator(blockPerm: BlockPermutation, startingLocation: DimensionLocation, size: number) {
    for (let x = startingLocation.x; x < startingLocation.x + size; x++) {
    for (let y = startingLocation.y; y < startingLocation.y + size; y++) {
    for (let z = startingLocation.z; z < startingLocation.z + size; z++) {
    const block = startingLocation.dimension.getBlock({ x: x, y: y, z: z });
    if (block) {
    block.setPermutation(blockPerm);
    }
    yield;
    }
    }
    }
    }
  • 实验性

    参数

    • callback: (() => void)

      Functional code that will run when this timeout occurs.

        • (): void
        • 返回 void

    • 可选tickDelay: number

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

    返回 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.

    This function can be called in early-execution mode.