@minecraft/server
    Preparing search index...

    Class WorldBeta

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

    Index

    Properties

    afterEvents: WorldAfterEvents

    Contains a set of events that are applicable to the entirety of the world. Event callbacks are called in a deferred manner. Event callbacks are executed in read-write mode.

    This property can be read in early-execution mode.

    beforeEvents: WorldBeforeEvents

    Contains 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;
    }
    }
    }
    });
    }
    gameRules: GameRules

    The game rules that apply to the world.

    isHardcore: boolean
    scoreboard: Scoreboard

    Returns the general global scoreboard that applies to the world.

    structureManager: StructureManager

    Returns the manager for Structure related APIs.

    Methods

    • Beta

      Parameters

      • id: string

        The message identifier.

      • value: string

        The message.

      Returns void

      A method that is internal-only, used for broadcasting specific messages between client and server.

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

    • Beta

      Returns void

      Clears the set of dynamic properties declared for this behavior pack within the world.

    • Beta

      Returns number

      Returns the absolute time since the start of the world.

    • Beta

      Returns AimAssistRegistry

      The aim-assist presets and categories that can be used in the world.

    • Beta

      Returns Player[]

      Returns an array of all active players within the world.

      This function can throw errors.

      CommandError

      minecraftcommon.InvalidArgumentError

    • Beta

      Returns number

      The current day, determined by the world time divided by the number of ticks per day. New worlds start at day 0.

      Returns the current day.

    • Beta

      Returns Vector3

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

      Returns the default Overworld spawn location.

    • Beta

      Returns Difficulty

      Returns the world difficulty.

      Gets the difficulty from the world.

    • Beta

      Parameters

      • dimensionId: string

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

      Returns Dimension

      The requested dimension

      Returns a dimension object.

      Throws if the given dimension name is invalid

    • Beta

      Parameters

      • identifier: string

        The property identifier.

      Returns undefined | string | number | boolean | Vector3

      Returns the value for the property, or undefined if the property has not been set.

      Returns a property value.

      Throws if the given dynamic property identifier is not defined.

      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);
      }
    • Beta

      Returns string[]

      A string array of active dynamic property identifiers.

      Gets a set of dynamic property identifiers that have been set in this world.

    • Beta

      Returns number

      Gets the total byte count of dynamic properties. This could potentially be used for your own analytics to ensure you're not storing gigantic sets of dynamic properties.

    • Beta

      Parameters

      • id: string

        The id of the entity.

      Returns undefined | Entity

      The requested entity object.

      Returns an entity based on the provided id.

      Throws if the given entity id is invalid.

    • Beta

      Returns LootTableManager

      A loot table manager with a variety of loot generation methods.

      Returns a manager capable of generating loot from an assortment of sources.

    • Beta

      Returns MoonPhase

      Returns the MoonPhase for the current time.

    • Beta

      Returns Record<string, string | number | boolean>

      Returns a map of pack setting name and value pairs.

      This function can be called in early-execution mode.

    • Beta

      Parameters

      • Optionaloptions: EntityQueryOptions

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

      Returns Player[]

      A player array.

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

      Throws if the provided EntityQueryOptions are invalid.

      CommandError

      minecraftcommon.InvalidArgumentError

    • Beta

      Returns number

      The time of day, in ticks, between 0 and 24000.

      Returns the time of day.

    • Beta

      Parameters

      Returns void

      Plays a particular music track for all players.

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

      This function can throw errors.

      minecraftcommon.PropertyOutOfBoundsError

      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);
      }
    • Beta

      Parameters

      • trackId: string

        Identifier of the music track to play.

      • OptionalmusicOptions: MusicOptions

        Additional options for the music track.

      Returns void

      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.

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

      minecraftcommon.PropertyOutOfBoundsError

    • Beta

      Parameters

      Returns void

      Sends a message to all players.

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

    • Beta

      Parameters

      • absoluteTime: number

        The world time, in ticks.

      Returns void

      Sets the world time.

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

    • Beta

      Parameters

      • spawnLocation: Vector3

        Location of the spawn point. Note that this is assumed to be within the overworld dimension.

      Returns void

      Sets a default spawn location for all players.

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

      Throws if the provided spawn location is out of bounds.

      Error

      LocationOutOfWorldBoundariesError

    • Beta

      Parameters

      • difficulty: Difficulty

        The difficulty we want to set the world to.

      Returns void

      Sets the worlds difficulty.

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

    • Beta

      Parameters

      • values: Record<string, undefined | string | number | boolean | Vector3>

        A Record of key value pairs of the dynamic properties to set. If the data value is null, it will remove that property instead.

      Returns void

      Sets multiple dynamic properties with specific values.

      This function can throw errors.

      minecraftcommon.ArgumentOutOfBoundsError

    • Beta

      Parameters

      • identifier: string

        The property identifier.

      • Optionalvalue: string | number | boolean | Vector3

        Data value of the property to set. If the value is null, it will remove the property instead.

      Returns void

      Sets a specified property to a value.

      Throws if the given dynamic property identifier is not defined.

      minecraftcommon.ArgumentOutOfBoundsError

      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);
      }
    • Beta

      Parameters

      • timeOfDay: number

        The time of day, in ticks, between 0 and 24000.

      Returns void

      Sets the time of day.

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

      Throws if the provided time of day is not within the valid range.

    • Beta

      Returns void

      Stops any music tracks from playing.

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