A class that wraps the state of a world - a set of dimensions and the environment of Minecraft.

Hierarchy

  • World

Constructors

  • Returns World

Methods

  • Returns Player[]

    Remarks

    Returns an array of all active players within the world.

    Throws

    This function can throw errors.

  • Parameters

    • dimensionId: string

      The name of the dimension. For example, "overworld", "nether" or "the_end".

    Returns Dimension

    The requested dimension

    Remarks

    Returns a dimension object.

    Throws

    Throws if the given dimension name is invalid

  • Parameters

    • Optional options: EntityQueryOptions

      Additional options that can be used to filter the set of players returned.

    Returns Player[]

    A player array.

    Remarks

    Returns a set of players based on a set of conditions defined via the EntityQueryOptions set of filter criteria.

    Throws

    Throws if the provided EntityQueryOptions are invalid.

  • Parameters

    Returns void

    Remarks

    Plays a particular music track for all players.

    This function can't be called in read-only mode.

    Throws

    This function can throw errors.

    Example

    playMusicAndSound.ts

      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);
  • Parameters

    Returns void

    Remarks

    Plays a sound for all players.

    This function can't be called in read-only mode.

    Throws

    An 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.

    Example

    playMusicAndSound.ts

      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);
  • Parameters

    Returns void

    Remarks

    Queues an additional music track for players. If a track is not playing, a music track will play.

    This function can't be called in read-only mode.

    Throws

    An error will be thrown if volume is less than 0.0. An error will be thrown if fade is less than 0.0.

  • Parameters

    Returns void

    Remarks

    Sends a message to all players.

    Throws

    This method can throw if the provided RawMessage is in an invalid format. For example, if an empty name string is provided to score.

    Example

    nestedTranslation.ts

    // Displays "Apple or Coal"
    let rawMessage = {
    translate: "accessibility.list.or.two",
    with: { rawtext: [{ translate: "item.apple.name" }, { translate: "item.coal.name" }] },
    };
    world.sendMessage(rawMessage);

    Example

    scoreWildcard.ts

    // Displays the player's score for objective "obj". Each player will see their own score.
    const rawMessage = { score: { name: "*", objective: "obj" } };
    world.sendMessage(rawMessage);

    Example

    simpleString.ts

    // Displays "Hello, world!"
    world.sendMessage("Hello, world!");

    Example

    translation.ts

    // Displays "First or Second"
    const rawMessage = { translate: "accessibility.list.or.two", with: ["First", "Second"] };
    world.sendMessage(rawMessage);
  • Returns void

    Remarks

    Stops any music tracks from playing.

    This function can't be called in read-only mode.