Script API - v1.26.10.23
    Preparing search index...
    Index

    Constructors

    Properties

    heightRange: NumberRange

    This property can throw errors.

    This property can't be read in early-execution mode.

    import { Player, system, world } from "@minecraft/server";

    // Get all dimensions
    const overworld = world.getDimension("overworld");
    const nether = world.getDimension("nether");
    const end = world.getDimension("the end");

    // If user sends a scriptevent command with id test:height_range, it prints the height of each dimension in a world.
    system.afterEvents.scriptEventReceive.subscribe((event) => {
    if (event.id === "test:height_range") {
    // Gets the height range of every dimension
    const overworldHeight = overworld.heightRange;
    const netherHeight = nether.heightRange;
    const endHeight = end.heightRange;

    // Sends the message to player who sent the command
    if (event.sourceEntity instanceof Player) {
    event.sourceEntity.sendMessage(
    `Overworld height: ${overworldHeight.min} to ${overworldHeight.max} (Height: ${
    overworldHeight.max - overworldHeight.min
    } blocks)`
    );
    event.sourceEntity.sendMessage(
    `Nether height: ${netherHeight.min} to ${netherHeight.max} (Height: ${
    netherHeight.max - netherHeight.min
    } blocks)`
    );
    event.sourceEntity.sendMessage(
    `End height: ${endHeight.min} to ${endHeight.max} (Height: ${endHeight.max - endHeight.min} blocks)`
    );
    }
    }
    });
    id: string
    localizationKey: string

    Methods

    • Parameters

      Returns ListBlockVolume

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

      This function can throw errors.

      minecraftcommon.EngineError

      Error

      UnloadedChunksError

      This function can't be called in early-execution mode.

      import { BlockPermutation, BlockVolume, world } from "@minecraft/server";

      // Command: /fill 0 10 0 20 30 40 underwater_tnt replace air
      const overworld = world.getDimension("overworld");
      const volume = new BlockVolume({ x: 0, y: 10, z: 0 }, { x: 20, y: 30, z: 40 });
      const tnt = BlockPermutation.resolve("minecraft:underwater_tnt");
      overworld.fillBlocks(volume, tnt, { blockFilter: { excludeTypes: ["minecraft:air"] } });
      import { BlockPermutation, BlockVolume, Dimension, Vector3, world } from "@minecraft/server";

      function fillBlockType(dimension: Dimension, from: Vector3, to: Vector3, block: string): void {
      const volume = new BlockVolume(from, to);
      dimension.fillBlocks(volume, block);
      }

      // Command: /fill 0 10 0 20 30 40 diamond_block
      const overworld = world.getDimension("overworld");
      fillBlockType(overworld, { x: 0, y: 10, z: 0 }, { x: 20, y: 30, z: 40 }, "minecraft:diamond_block");
    • Parameters

      Returns ListBlockVolume

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

      This function can throw errors.

      Error

      UnloadedChunksError

      This function can't be called in early-execution mode.

      import { BlockPermutation, BlockVolume, system, world } from "@minecraft/server";

      // Get every non-air block location at chunk (0, 0)
      const overworld = world.getDimension("overworld");
      const volume = new BlockVolume(
      { x: 0, y: overworld.heightRange.min, z: 0 },
      { x: 15, y: overworld.heightRange.max, z: 15 }
      );
      const locations = overworld.getBlocks(volume, { excludeTypes: ["minecraft:air"] }, false);

      /**
      A simple generator that replace non-air blocks to cobblestone at chunk (0, 0),
      yielding after each block placement.
      @returns {Generator<void, void, void>} A generator that yields after each block placement.
      /
      function* blockPlacingGenerator() {
      for (const location of locations.getBlockLocationIterator()) {
      const block = overworld.getBlock(location);
      block.setPermutation(BlockPermutation.resolve("minecraft:cobblestone"));
      yield;
      }
      }

      system.runJob(blockPlacingGenerator());
    • Parameters

      Returns Entity[]

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

      This function can throw errors.

      CommandError

      minecraftcommon.InvalidArgumentError

      This function can't be called in early-execution mode.

      import { EntityQueryOptions, GameMode, world } from "@minecraft/server";

      const options: EntityQueryOptions = {
      families: ["mob", "animal"],
      excludeTypes: ["cow"],
      maxDistance: 50,
      excludeGameModes: [GameMode.Creative, GameMode.Spectator],
      };

      const filteredEntities = world.getDimension("overworld").getEntities(options);
      console.log(
      "Filtered Entities:",
      filteredEntities.map((entity) => entity.typeId)
      );
    • Parameters

      Returns Player[]

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

      This function can throw errors.

      CommandError

      minecraftcommon.InvalidArgumentError

      This function can't be called in early-execution mode.

      import { EntityQueryOptions, world } from "@minecraft/server";

      const entityQueryOptions: EntityQueryOptions = {
      maxDistance: 100,
      scoreOptions: [
      { objective: "kills", minScore: 10 },
      { objective: "deaths", maxScore: 5 },
      ],
      };

      const filteredPlayers = world.getDimension("overworld").getPlayers(entityQueryOptions);
      console.log(
      "Filtered Players in Overworld:",
      filteredPlayers.map((player) => player.name)
      );
    • Parameters

      • locationXZ: VectorXZ
      • OptionalminHeight: number

      Returns Block

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

      This function can throw errors.

      This function can't be called in early-execution mode.

    • Parameters

      Returns void

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

      This function can throw errors.

      This function can't be called in early-execution mode.