@minecraft/server / System
Class: System ​
Defined in: @minecraft/server/index.d.ts:20358
A class that provides system-level events and functions.
Properties ​
afterEvents ​
readonlyafterEvents:SystemAfterEvents
Defined in: @minecraft/server/index.d.ts:20368
Remarks ​
Returns a collection of after-events for system-level operations.
This property can be read in early-execution mode.
beforeEvents ​
readonlybeforeEvents:SystemBeforeEvents
Defined in: @minecraft/server/index.d.ts:20377
Remarks ​
Returns a collection of before-events for system-level operations.
This property can be read in early-execution mode.
currentTick ​
readonlycurrentTick:number
Defined in: @minecraft/server/index.d.ts:20385
Remarks ​
Represents the current world tick of the server.
This property can be read in early-execution mode.
isEditorWorld ​
readonlyisEditorWorld:boolean
Defined in: @minecraft/server/index.d.ts:20394
Remarks ​
Returns true if this is a world where the editor is currently loaded, returns false otherwise.
This property can be read in early-execution mode.
serverSystemInfo ​
readonlyserverSystemInfo:SystemInfo
Defined in: @minecraft/server/index.d.ts:20402
Remarks ​
Contains the device information for the server.
This property can be read in early-execution mode.
Methods ​
clearJob() ​
clearJob(
jobId):void
Defined in: @minecraft/server/index.d.ts:20413
Parameters ​
jobId ​
number
The job ID returned from System.runJob.
Returns ​
void
Remarks ​
Cancels the execution of a job queued via System.runJob.
This function can be called in early-execution mode.
clearRun() ​
clearRun(
runId):void
Defined in: @minecraft/server/index.d.ts:20422
Parameters ​
runId ​
number
Returns ​
void
Remarks ​
Cancels the execution of a function run that was previously scheduled via System.run.
This function can be called in early-execution mode.
run() ​
run(
callback):number
Defined in: @minecraft/server/index.d.ts:20459
Parameters ​
callback ​
() => void
Function callback to run at the next game tick.
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 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.
Example ​
trapTick.ts
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);
}runInterval() ​
runInterval(
callback,tickInterval?):number
Defined in: @minecraft/server/index.d.ts:20487
Parameters ​
callback ​
() => void
Functional code that will run when this interval occurs.
tickInterval? ​
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.
Remarks ​
Runs a set of code on an interval.
This function can be called in early-execution mode.
Example ​
every30Seconds.ts
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);
}runJob() ​
runJob(
generator):number
Defined in: @minecraft/server/index.d.ts:20526
Parameters ​
generator ​
Generator<void, void, void>
The instance of the generator to run.
Returns ​
number
An opaque handle that can be used with System.clearJob to stop the run of this generator.
Remarks ​
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.
Example ​
cubeGenerator.ts
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;
}
}
}
}runTimeout() ​
runTimeout(
callback,tickDelay?):number
Defined in: @minecraft/server/index.d.ts:20542
Parameters ​
callback ​
() => void
Functional code that will run when this timeout occurs.
tickDelay? ​
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.
Remarks ​
Runs a set of code at a future time specified by tickDelay.
This function can be called in early-execution mode.
sendScriptEvent() ​
sendScriptEvent(
id,message):void
Defined in: @minecraft/server/index.d.ts:20564
Parameters ​
id ​
string
Identifier of the message to send. This is custom and dependent on the kinds of behavior packs and content you may have installed within the world.
message ​
string
Data component of the message to send. This is custom and dependent on the kinds of behavior packs and content you may have installed within the world.
Returns ​
void
Remarks ​
Causes an event to fire within script with the specified message ID and payload.
Throws ​
This function can throw errors.
minecraftcommon.EngineError
minecraftcommon.InvalidArgumentError
waitTicks() ​
waitTicks(
ticks):Promise<void>
Defined in: @minecraft/server/index.d.ts:20581
Parameters ​
ticks ​
number
The amount of ticks to wait. Minimum value is 1.
Returns ​
Promise<void>
A promise that is resolved when the specified amount of ticks have occurred.
Remarks ​
waitTicks returns a promise that resolves after the requested number of ticks.
This function can be called in early-execution mode.
Throws ​
This function can throw errors.
minecraftcommon.EngineError