Readonly
afterReadonly
beforeContains 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.
Readonly
scoreboardThe 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.
The name of the dimension. For example, "overworld", "nether" or "the_end".
The requested dimension
The property identifier.
Returns the value for the property, or undefined if the property has not been set.
let number = mc.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;
}
mc.world.setDynamicProperty("samplelibrary:number", number + 1);
let paintStr = mc.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
mc.world.setDynamicProperty("samplelibrary:longerjson", paintStr);
Optional
options: EntityQueryOptionsAdditional options that can be used to filter the set of players returned.
A player array.
Optional
musicOptions: MusicOptionsPlays a particular music track for all players.
This function can't be called in read-only mode.
let players = mc.world.getPlayers();
const musicOptions: mc.MusicOptions = {
fade: 0.5,
loop: true,
volume: 1.0,
};
mc.world.playMusic("music.menu", musicOptions);
const worldSoundOptions: mc.WorldSoundOptions = {
pitch: 0.5,
volume: 4.0,
};
mc.world.playSound("ambient.weather.thunder", targetLocation, worldSoundOptions);
const playerSoundOptions: mc.PlayerSoundOptions = {
pitch: 1.0,
volume: 1.0,
};
players[0].playSound("bucket.fill_water", playerSoundOptions);
Optional
soundOptions: WorldSoundOptionsAn error will be thrown if volume is less than 0.0. An error will be thrown if fade is less than 0.0. An error will be thrown if pitch is less than 0.01. An error will be thrown if volume is less than 0.0.
let players = mc.world.getPlayers();
const musicOptions: mc.MusicOptions = {
fade: 0.5,
loop: true,
volume: 1.0,
};
mc.world.playMusic("music.menu", musicOptions);
const worldSoundOptions: mc.WorldSoundOptions = {
pitch: 0.5,
volume: 4.0,
};
mc.world.playSound("ambient.weather.thunder", targetLocation, worldSoundOptions);
const playerSoundOptions: mc.PlayerSoundOptions = {
pitch: 1.0,
volume: 1.0,
};
players[0].playSound("bucket.fill_water", playerSoundOptions);
Identifier of the music track to play.
Optional
musicOptions: MusicOptionsAdditional options for the music track.
The 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
.
// Displays "Apple or Coal"
let rawMessage = {
translate: "accessibility.list.or.two",
with: { rawtext: [{ translate: "item.apple.name" }, { translate: "item.coal.name" }] },
};
world.sendMessage(rawMessage);
Location of the spawn point. Note that this is assumed to be within the overworld dimension.
The property identifier.
Optional
value: string | number | boolean | Vector3Data value of the property to set.
let number = mc.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;
}
mc.world.setDynamicProperty("samplelibrary:number", number + 1);
let paintStr = mc.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
mc.world.setDynamicProperty("samplelibrary:longerjson", paintStr);
A class that wraps the state of a world - a set of dimensions and the environment of Minecraft.