BetaReadonly BetaafterReadonly BetabeforeContains a set of events that are applicable to the entirety of the world. Event callbacks are called immediately. Event callbacks are executed in read-only mode.
This property can be read in early-execution mode.
import { world, DimensionLocation } from "@minecraft/server";
function customCommand(targetLocation: DimensionLocation) {
const chatCallback = world.beforeEvents.chatSend.subscribe((eventData) => {
if (eventData.message.includes("cancel")) {
// Cancel event if the message contains "cancel"
eventData.cancel = true;
} else {
const args = eventData.message.split(" ");
if (args.length > 0) {
switch (args[0].toLowerCase()) {
case "echo":
// Send a modified version of chat message
world.sendMessage(`Echo '${eventData.message.substring(4).trim()}'`);
break;
case "help":
world.sendMessage(`Available commands: echo <message>`);
break;
}
}
}
});
}
Readonly BetagameReadonly BetaisReadonly BetascoreboardReadonly BetaseedReadonly BetastructureReturns the manager for Structure related APIs.
Readonly BetatickingBetaBetaThe default Overworld spawn location. By default, the Y coordinate is 32767, indicating a player's spawn height is not fixed and will be determined by surrounding blocks.
BetaThe name of the dimension. For example, "overworld", "nether" or "the_end".
The requested dimension
BetaThe property identifier.
Returns the value for the property, or undefined if the property has not been set.
import { world, DimensionLocation } from "@minecraft/server";
function incrementDynamicProperty(
log: (message: string, status?: number) => void,
targetLocation: DimensionLocation
) {
let number = world.getDynamicProperty("samplelibrary:number");
log("Current value is: " + number);
if (number === undefined) {
number = 0;
}
if (typeof number !== "number") {
log("Number is of an unexpected type.");
return -1;
}
world.setDynamicProperty("samplelibrary:number", number + 1);
}
import { world, DimensionLocation } from "@minecraft/server";
function incrementDynamicPropertyInJsonBlob(
log: (message: string, status?: number) => void,
targetLocation: DimensionLocation
) {
let paintStr = world.getDynamicProperty("samplelibrary:longerjson");
let paint: { color: string; intensity: number } | undefined = undefined;
log("Current value is: " + paintStr);
if (paintStr === undefined) {
paint = {
color: "purple",
intensity: 0,
};
} else {
if (typeof paintStr !== "string") {
log("Paint is of an unexpected type.");
return -1;
}
try {
paint = JSON.parse(paintStr);
} catch (e) {
log("Error parsing serialized struct.");
return -1;
}
}
if (!paint) {
log("Error parsing serialized struct.");
return -1;
}
paint.intensity++;
paintStr = JSON.stringify(paint); // be very careful to ensure your serialized JSON str cannot exceed limits
world.setDynamicProperty("samplelibrary:longerjson", paintStr);
}
BetaThe id of the entity.
The requested entity object.
BetaOptionaloptions: EntityQueryOptionsAdditional options that can be used to filter the set of players returned.
A player array.
BetaRetrieves a concatenated string from dynamic properties based on the provided property name.
The base name of the dynamic property to retrieve the string from.
OptionalzeroLengthPlaceholder: stringA placeholder string to return if the length of the dynamic property is zero. Defaults to an empty string.
The concatenated string from the dynamic properties, or the zeroLengthPlaceholder if the length is zero.
BetaOptionalmusicOptions: MusicOptionsPlays a particular music track for all players.
This function can't be called in restricted-execution mode.
import { world, MusicOptions, WorldSoundOptions, PlayerSoundOptions, DimensionLocation } from "@minecraft/server";
function playMusicAndSound(targetLocation: DimensionLocation) {
const players = world.getPlayers();
const musicOptions: MusicOptions = {
fade: 0.5,
loop: true,
volume: 1.0,
};
world.playMusic("music.menu", musicOptions);
const worldSoundOptions: WorldSoundOptions = {
pitch: 0.5,
volume: 4.0,
};
world.playSound("ambient.weather.thunder", targetLocation, worldSoundOptions);
const playerSoundOptions: PlayerSoundOptions = {
pitch: 1.0,
volume: 1.0,
};
players[0].playSound("bucket.fill_water", playerSoundOptions);
}
BetaIdentifier of the music track to play.
OptionalmusicOptions: MusicOptionsAdditional options for the music track.
BetaSaves a string to dynamic properties, optionally clearing old properties first and splitting the string into chunks.
The string to save to dynamic properties.
The name of the property to save the string under.
OptionalclearOldProperties: booleanWhether to clear old properties before saving the new string. Defaults to true.
OptionalchunkSize: number | bigintThe size of each chunk to split the string into. Defaults to 32760.
BetaThe message to be displayed.
This method can throw if the provided RawMessage is
in an invalid format. For example, if an empty name string
is provided to score.
BetaLocation of the spawn point. Note that this is assumed to be within the overworld dimension.
BetaA Record of key value pairs of the dynamic properties to set. If the data value is null, it will remove that property instead.
BetaThe property identifier.
Optionalvalue: string | number | boolean | Vector3Data value of the property to set. If the value is null, it will remove the property instead.
import { world, DimensionLocation } from "@minecraft/server";
function incrementDynamicProperty(
log: (message: string, status?: number) => void,
targetLocation: DimensionLocation
) {
let number = world.getDynamicProperty("samplelibrary:number");
log("Current value is: " + number);
if (number === undefined) {
number = 0;
}
if (typeof number !== "number") {
log("Number is of an unexpected type.");
return -1;
}
world.setDynamicProperty("samplelibrary:number", number + 1);
}
import { world, DimensionLocation } from "@minecraft/server";
function incrementDynamicPropertyInJsonBlob(
log: (message: string, status?: number) => void,
targetLocation: DimensionLocation
) {
let paintStr = world.getDynamicProperty("samplelibrary:longerjson");
let paint: { color: string; intensity: number } | undefined = undefined;
log("Current value is: " + paintStr);
if (paintStr === undefined) {
paint = {
color: "purple",
intensity: 0,
};
} else {
if (typeof paintStr !== "string") {
log("Paint is of an unexpected type.");
return -1;
}
try {
paint = JSON.parse(paintStr);
} catch (e) {
log("Error parsing serialized struct.");
return -1;
}
}
if (!paint) {
log("Error parsing serialized struct.");
return -1;
}
paint.intensity++;
paintStr = JSON.stringify(paint); // be very careful to ensure your serialized JSON str cannot exceed limits
world.setDynamicProperty("samplelibrary:longerjson", paintStr);
}
A class that wraps the state of a world - a set of dimensions and the environment of Minecraft.