Script API - v1.26.10.23
    Preparing search index...
    import { world } from "@minecraft/server";

    for (const player of world.getAllPlayers()) {
    player.sendMessage(`Hello, ${player.name}!`);
    }

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    camera: Camera

    This property can throw errors.

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

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

    function runCutscene() {
    for (const player of world.getPlayers()) {
    const location = player.location;
    player.camera.setCamera("minecraft:free", {
    location: { x: location.x, y: location.y + 10, z: location.z },
    rotation: { x: 90, y: 0 },
    });
    system.run(() => {
    player.camera.setCamera("minecraft:free", {
    location: player.getHeadLocation(),
    rotation: player.getRotation(),
    easeOptions: {
    easeTime: 1.0,
    easeType: EasingType.InCubic,
    },
    });
    system.runTimeout(() => {
    player.camera.clear();
    player.runCommand("/inputpermission @s camera enabled");
    player.runCommand("/inputpermission @s movement enabled");
    }, 20);
    });
    player.runCommand("/inputpermission @s camera disabled");
    player.runCommand("/inputpermission @s movement disabled");
    }
    }

    runCutscene();
    clientSystemInfo: ClientSystemInfo

    This property can throw errors.

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

    commandPermissionLevel: CommandPermissionLevel

    This property can't be edited in read-only mode.

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

    This is related to Operator Permission Levels (The op-permission-level setting in server.properties file in Minecraft Bedrock Dedicated Server).

    This property determines the default permission level assigned to players when using the /op command. This affects which commands they can use unless explicitly set in permissions.json.


    Allows only non-destructive, informational, and communication-related commands. Ideal for minimal permissions.

    Example level 0 commands: /help, /tell


    Adds access to gameplay-related commands such as gamemode changes, teleporting, and giving items. Suitable for creative players or minor helpers.

    Example level 1 commands: /aimassist, /camera


    Example level 2 commands: /op, /deop

    Grants access to moderation tools like kicking and banning players. Useful for server moderators or staff.


    Provides some access to server and management commands. This is the command permission level for the host when launching a Minecraft world from the client.

    Example level 3 command: /setmaxplayers


    Provides full access to all server and management commands. Intended only for server owners or trusted administrators.

    Example level 4 commands: /changesetting, /stop

    Additional info by Visual1mpact

    dimension: Dimension

    This property can throw errors.

    minecraftcommon.EngineError

    InvalidEntityError

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

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

    for (const entity of world.getDimension("overworld").getEntities()) {
    entity.dimension.spawnItem(new ItemStack("minecraft:diamond_sword"), entity.location);
    }
    graphicsMode: GraphicsMode

    This property can throw errors.

    InvalidEntityError

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

    id: string
    import { Entity, world } from "@minecraft/server";

    /**
    Gets entity id
    @param {Entity} entity
    /
    function showId(entity) {
    entity.runCommand("say My entity ID: " + entity.id);
    }

    for (const entity of world.getDimension("overworld").getEntities()) {
    showId(entity);
    }
    inputInfo: InputInfo
    inputPermissions: PlayerInputPermissions
    isClimbing: boolean

    This property can throw errors.

    InvalidEntityError

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

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

    system.runInterval(() => {
    // Get all overworld entities
    for (const entity of world.getDimension("overworld").getEntities()) {
    if (entity.isClimbing) {
    entity.runCommand("say I'm climbing!");
    }
    }
    });
    isEmoting: boolean

    This property can throw errors.

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

    isFalling: boolean

    This property can throw errors.

    InvalidEntityError

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

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

    system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
    player.sendMessage(`isFalling - ${player.isFalling}`);
    }
    });
    isFlying: boolean

    This property can throw errors.

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

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

    system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
    player.sendMessage(`player is flying: ${player.isFlying}`);
    }
    });
    isGliding: boolean

    This property can throw errors.

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

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

    system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
    player.sendMessage(`player is gliding with Elytra: ${player.isGliding}`);
    }
    });
    isInWater: boolean

    This property can throw errors.

    InvalidEntityError

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

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

    system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
    player.sendMessage(`player in water: ${player.isInWater}`);
    }
    });
    isJumping: boolean

    This property can throw errors.

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

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

    system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
    player.sendMessage(`player is jumping: ${player.isJumping}`);
    }
    });
    isOnGround: boolean

    This property can throw errors.

    InvalidEntityError

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

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

    system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
    player.sendMessage(`player on ground: ${player.isOnGround}`);
    }
    });
    isSleeping: boolean

    This property can throw errors.

    InvalidEntityError

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

    isSneaking: boolean

    This property can't be edited in read-only mode.

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

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

    system.runInterval(() => {
    for (const entity of world.getDimension("overworld").getEntities()) {
    // Force entity to not sneak
    entity.isSneaking = false;
    }
    });
    import { DimensionLocation, MolangVariableMap, Vector3, system, world } from "@minecraft/server";

    function spawnConfetti(location: DimensionLocation) {
    for (let i = 0; i < 100; i++) {
    const molang = new MolangVariableMap();

    molang.setColorRGB("variable.color", {
    red: Math.random(),
    green: Math.random(),
    blue: Math.random(),
    });

    const newLocation: Vector3 = {
    x: location.x + Math.floor(Math.random() * 8) - 4,
    y: location.y + Math.floor(Math.random() * 8) - 4,
    z: location.z + Math.floor(Math.random() * 8) - 4,
    };
    location.dimension.spawnParticle("minecraft:colored_flame_particle", newLocation, molang);
    }
    }

    system.runInterval(() => {
    for (const player of world.getPlayers()) {
    if (player.isSneaking) {
    spawnConfetti({
    dimension: player.dimension,
    x: player.location.x,
    y: player.location.y,
    z: player.location.z,
    });
    player.sendMessage("player is sneaking");
    }
    }
    });
    isSprinting: boolean

    This property can throw errors.

    InvalidEntityError

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

    isSwimming: boolean

    This property can throw errors.

    InvalidEntityError

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

    isValid: boolean
    import { system, world } from "@minecraft/server";

    const zombie = world.getDimension("overworld").spawnEntity("minecraft:zombie", world.getDefaultSpawnLocation());

    const id = system.runInterval(() => {
    if (!zombie.isValid) {
    system.clearRun(id);
    return;
    }
    const location = zombie.location;
    for (const player of world.getPlayers()) {
    player.sendMessage(
    `Zombie location: (${location.x.toFixed(2)}, ${location.y.toFixed(2)}, ${location.z.toFixed(2)})`
    );
    }
    });
    level: number

    This property can throw errors.

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

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

    for (const player of world.getAllPlayers()) {
    player.onScreenDisplay.setActionBar(
    `Level: ${player.level}, xp at current level: ${player.xpEarnedAtCurrentLevel} / ${player.totalXpNeededForNextLevel}`
    );
    }
    localizationKey: string

    This property can throw errors.

    InvalidEntityError

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

    location: Vector3

    This property can throw errors.

    InvalidEntityError

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

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

    world.afterEvents.buttonPush.subscribe((event) => {
    if (event.source instanceof Player) {
    const { x, y, z } = event.source.location;
    event.source.sendMessage(`Your location: ${x}, ${y}, ${z}`);
    }
    });
    name: string

    This property can throw errors.

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

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

    world.afterEvents.playerSpawn.subscribe((event) => {
    world.sendMessage("Welcome to the server, " + event.player.name + "!");
    });
    nameTag: string

    This property can't be edited in read-only mode.

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

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

    system.afterEvents.scriptEventReceive.subscribe(({ message }) => {
    if (message === "dinnerbone:true") {
    for (const entity of world.getDimension("overworld").getEntities()) {
    entity.nameTag = "Dinnerbone";
    }
    }
    });
    onScreenDisplay: ScreenDisplay

    This property can throw errors.

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

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

    for (const player of world.getAllPlayers()) {
    player.onScreenDisplay.setActionBar("Hello World");
    }
    import { HudElement, world } from "@minecraft/server";

    for (const player of world.getAllPlayers()) {
    player.onScreenDisplay.hideAllExcept([HudElement.Hotbar]);
    }
    import { world } from "@minecraft/server";

    for (const player of world.getAllPlayers()) {
    player.onScreenDisplay.setTitle(" "); // spaces needed
    player.onScreenDisplay.updateSubtitle("Insert Subtitle");
    }
    import { world } from "@minecraft/server";

    for (const player of world.getAllPlayers()) {
    player.onScreenDisplay.setTitle("Hello World");
    player.onScreenDisplay.updateSubtitle("Welcome to the server!");
    }
    playerPermissionLevel: PlayerPermissionLevel

    This property can throw errors.

    InvalidEntityError

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

    scoreboardIdentity?: ScoreboardIdentity
    selectedSlotIndex: number

    This property can't be edited in read-only mode.

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

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

    for (const player of world.getPlayers()) {
    const inventory = player.getComponent("inventory");
    const selectedItem = inventory.container.getItem(player.selectedSlotIndex);
    player.sendMessage("Selected Item: " + selectedItem.typeId);
    }
    totalXpNeededForNextLevel: number

    This property can throw errors.

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

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

    function countdownFromTen(player: Player) {
    player.addLevels(-10000);
    player.addLevels(11);
    const id = system.runInterval(() => {
    player.addExperience(Math.round(-player.totalXpNeededForNextLevel / 10));
    if (player.getTotalXp() === 0) {
    system.clearRun(id);
    }
    if (player.xpEarnedAtCurrentLevel == 0) {
    player.addLevels(-1);
    player.addExperience(player.totalXpNeededForNextLevel - 1);
    }
    }, 2);
    }
    for (const player of world.getPlayers()) {
    countdownFromTen(player);
    }
    typeId: string
    import { system, world } from "@minecraft/server";

    // This event triggers when world is loaded
    system.runInterval(() => {
    const entity = world.getDimension("overworld").getEntities()[0];
    // Finally, show that location as title
    entity.runCommand(
    `title @a actionbar X: ${Math.floor(entity.location.x)} | Y: ${Math.floor(entity.location.y)} | Z: ${Math.floor(
    entity.location.z
    )}`
    );
    });
    xpEarnedAtCurrentLevel: number

    This property can throw errors.

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

    Methods

    • Parameters

      • amount: number

      Returns number

      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.

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

      // Command equivalent to /xp player 100
      function addExperience(player: Player) {
      const xpAdded = player.addExperience(100);
      console.log(`Player ${player.name} now has ${xpAdded} experience points.`);
      }

      for (const player of world.getPlayers()) {
      addExperience(player);
      }
    • Parameters

      • amount: number

      Returns number

      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.

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

      // Command equivalent to /xp player 5L
      function addLevels(player: Player) {
      const levels = player.addLevels(5);
      console.log(`Player ${player.name} now has ${levels} levels.`);
      }
    • Parameters

      • horizontalForce: VectorXZ
      • verticalStrength: number

      Returns void

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

      This function can throw errors.

      InvalidEntityError

      minecraftcommon.UnsupportedFunctionalityError

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

      The following example (updated of the above - bounceSkeleton.ts) spawns several mobs, then applies a knockback to all skeletons.

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

      function bounceSkeletons(targetLocation: DimensionLocation) {
      const mobs = ["creeper", "skeleton", "sheep"];
      const horizontalForce = { x: 5, z: 4 }; // horizontal knockback strength - xz vector
      const verticalStrength = 0.3; // upward knockback strength

      // Spawn 10 mobs in a pattern
      for (let i = 0; i < 10; i++) {
      targetLocation.dimension.spawnEntity(
      mobs[i % mobs.length],
      targetLocation
      );
      }

      const eqo: EntityQueryOptions = { type: "skeleton" };

      // Apply knockback to all skeletons in the area
      for (const entity of targetLocation.dimension.getEntities(eqo)) {
      entity.applyKnockback(horizontalForce, verticalStrength);
      }
      }
    • Returns void

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

      This function can throw errors.

      InvalidEntityError

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

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

      for (const entity of world.getDimension("overworld").getEntities()) {
      entity.clearDynamicProperties();
      }
    • 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.

    • Parameters

      Returns BlockRaycastHit

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

      This function can throw errors.

      InvalidEntityError

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

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

      for (const entity of world.getDimension("overworld").getEntities()) {
      const blockHit = entity.getBlockFromViewDirection();

      if (blockHit) {
      console.log("Block Hit:");
      console.log("Block:", blockHit.block);
      console.log("Face:", blockHit.face);
      console.log("Face Location:", JSON.stringify(blockHit.faceLocation));
      } else {
      console.log("No block in view direction.");
      }
      }
      import { BlockPermutation, world } from "@minecraft/server";

      const entity = world.getDimension("overworld").spawnEntity("minecraft:fox", { x: 0, y: 0, z: 0 });
      const blockHit = entity.getBlockFromViewDirection();

      if (blockHit) {
      blockHit.block.setPermutation(BlockPermutation.resolve("minecraft:bedrock"));
      } else {
      console.log("No block in view direction.");
      }
    • Type Parameters

      • T extends string

      Parameters

      • componentId: T

      Returns EntityComponentReturnType<T>

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

      This function can throw errors.

      InvalidEntityError

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

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

      for (const player of world.getPlayers()) {
      const health = player.getComponent("health");
      player.sendMessage("Your health is " + health.currentValue + "/" + health.effectiveMax);
      health.setCurrentValue(15); // set player to 15 hp
      health.resetToMaxValue(); // reset player to max hp
      }
      import { ItemStack, world } from "@minecraft/server";

      world.afterEvents.buttonPush.subscribe((event) => {
      const entity = event.source;
      entity.getComponent("inventory").container.addItem(new ItemStack("minecraft:dirt", 1));
      });
      import { world } from "@minecraft/server";

      const itemEntities = world.getDimension("overworld").getEntities({ type: "minecraft:item" });
      for (const itemEntity of itemEntities) {
      const item = itemEntity.getComponent("item");
      item.itemStack.keepOnDeath = true;
      }
    • Returns EntityComponent[]

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

      This function can throw errors.

      InvalidEntityError

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

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

      for (const entity of world.getDimension("overworld").getEntities()) {
      const components = entity.getComponents();
      console.log(`Number of components: ${components.length}: ${components.map((component) => component.typeId)}`);
      }
    • Parameters

      • identifier: string

      Returns string | number | boolean | Vector3

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

      This function can throw errors.

      InvalidEntityError

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

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

      world.afterEvents.entitySpawn.subscribe((event) => {
      event.entity.setDynamicProperty("spawn_location", event.entity.location); // set location spawn
      });

      world.beforeEvents.entityRemove.subscribe((event) => {
      const location = event.removedEntity.getDynamicProperty("spawn_location") as Vector3; // get location spawn
      const dimension = event.removedEntity.dimension;
      system.run(() => {
      dimension.spawnEntity<string>(event.removedEntity.typeId, location);
      });
      });
    • Returns string[]

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

      This function can throw errors.

      InvalidEntityError

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

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

      system.afterEvents.scriptEventReceive.subscribe((event) => {
      // Type /scriptevent bp:entries to see this message
      if (event.id === "bp:entries" && event.sourceEntity instanceof Player) {
      event.sourceEntity.sendMessage("Here's your dynamic properties entries:");

      // Display all dynamic properties
      for (const id of event.sourceEntity.getDynamicPropertyIds()) {
      event.sourceEntity.sendMessage(`- ${id}: ${event.sourceEntity.getDynamicProperty(id)}`);
      }
      }
      });
    • Returns number

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

      This function can throw errors.

      InvalidEntityError

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

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

      system.afterEvents.scriptEventReceive.subscribe((event) => {
      // Type /scriptevent dp:size to see this message
      if (event.id === "dp:size" && event.sourceEntity instanceof Player) {
      // Returns the total size, in bytes, of all the dynamic properties that are currently stored for this entity.
      const byteCount = event.sourceEntity.getDynamicPropertyTotalByteCount();

      // Send the byte count to the player
      event.sourceEntity.sendMessage(`Dynamic Properties Byte Count: ${byteCount}`);
      }
      });
    • Parameters

      Returns Effect

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

      This function can throw errors.

      minecraftcommon.InvalidArgumentError

      InvalidEntityError

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

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

      /**
      @param {Player} player
      /
      function hasNightVision(player) {
      const nightVision = player.getEffect("night_vision");
      if (nightVision) {
      return true;
      } else return false;
      }

      for (const player of world.getAllPlayers()) {
      if (hasNightVision(player)) {
      player.sendMessage("You have night vision.");
      } else {
      player.sendMessage("You don't have night vision.");
      }
      }
    • Returns Effect[]

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

      This function can throw errors.

      InvalidEntityError

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

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

      for (const player of world.getAllPlayers()) {
      for (const effect of player.getEffects()) {
      player.sendMessage(
      `Effect: ${effect.displayName} | Duration: ${effect.duration} | Amplifier: ${effect.amplifier}`
      );
      }
      }
    • Parameters

      Returns EntityRaycastHit[]

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

      This function can throw errors.

      minecraftcommon.EngineError

      minecraftcommon.InvalidArgumentError

      InvalidEntityError

      minecraftcommon.UnsupportedFunctionalityError

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

      import type { EntityRaycastOptions } from "@minecraft/server";
      import { world } from "@minecraft/server";

      // Optional: Configure ray cast options
      const raycastOptions: EntityRaycastOptions = {
      maxDistance: 10, // Set your desired maximum distance
      };

      // Perform the ray cast

      for (const entity of world.getDimension("overworld").getEntities()) {
      const entitiesInView = entity.getEntitiesFromViewDirection(raycastOptions);

      // Log the results
      entitiesInView.forEach((hit) => {
      console.log(`Entity hit at distance ${hit.distance} blocks.`);
      console.log("Entity details:", hit.entity); // You can access properties/methods of the hit entity
      });
      }
    • Returns GameMode

      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.

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

      for (const player of world.getAllPlayers()) {
      const gameMode = player.getGameMode();
      player.sendMessage(`Your game mode is ${gameMode}`);
      }
    • Returns Vector3

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

      This function can throw errors.

      InvalidEntityError

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

      import { Player } from "@minecraft/server";

      function freezePlayerCamera(player: Player) {
      player.camera.setCamera("minecraft:free", {
      location: player.getHeadLocation(),
      rotation: player.getRotation(),
      });
      }
    • Parameters

      • cooldownCategory: string

      Returns number

      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.

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

      const player = world.getAllPlayers()[0];
      const cooldown = player.getItemCooldown("equipment");
      // console.log removed for example clarity
    • Parameters

      • identifier: string

      Returns string | number | boolean

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

      This function can throw errors.

      InvalidEntityError

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

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

      const entity = world.getDimension("overworld").getEntities({ type: "create:dummy" })[0];
      entity.setProperty("create:rotation_offset", 1);
      console.warn(entity.getProperty("create:rotation_offset"));
    • Returns Vector2

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

      This function can throw errors.

      InvalidEntityError

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

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

      world.beforeEvents.chatSend.subscribe((event) => {
      const message = event.message;
      const player = event.sender;
      if (message === "rotation get") {
      event.cancel = true;
      const rotation = player.getRotation();
      player.sendMessage(`Spawn point location: ${rotation.x} ${rotation.y}`);
      }
      });
    • Returns DimensionLocation

      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.

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

      world.beforeEvents.chatSend.subscribe((event) => {
      const message = event.message;
      const player = event.sender;
      if (message === "spawnpoint get") {
      event.cancel = true;
      const spawnPoint = player.getSpawnPoint();
      if (spawnPoint) {
      player.sendMessage(
      `Spawn point location: ${spawnPoint.x} ${spawnPoint.y} ${spawnPoint.z} at ${spawnPoint.dimension.id}`
      );
      } else {
      player.sendMessage(`No spawn point set.`);
      }
      }
      });
    • Returns string[]

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

      This function can throw errors.

      InvalidEntityError

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

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

      for (const entity of world.getDimension("overworld").getEntities()) {
      const tags = entity.getTags();
      const jaylyTag = tags.find((tag) => tag.startsWith("jayly:"));
      if (jaylyTag) {
      world.sendMessage(`${entity.id}: ${jaylyTag}`);
      }
      }
    • Returns number

      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

      • componentId: string

      Returns boolean

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

      This function can throw errors.

      InvalidEntityError

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

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

      const entity = world.getDimension("overworld").getEntities({ type: "minecraft:villager" })[0];
      entity.hasComponent("tameable");
      entity.hasComponent("inventory");
      entity.hasComponent("addrider");
      entity.hasComponent("is_tamed");
    • Parameters

      Returns boolean

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

      This function can throw errors.

      minecraftcommon.InvalidArgumentError

      InvalidEntityError

      minecraftcommon.UnsupportedFunctionalityError

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

      import { GameMode, system, world } from "@minecraft/server";
      system.runInterval(() => {
      for (const player of world.getAllPlayers()) {
      const isSpectating = player.matches({ gameMode: GameMode.Spectator });
      if (isSpectating) {
      player.onScreenDisplay.setActionBar("You are spectating");
      }
      }
      });
    • 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.

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

      import { Player } from "@minecraft/server";

      // Scripting code for `playsound
      function playCreatorMusicBoxRecord(player: Player) {
      player.playSound("record.creator_music_box", { location: player.location });
      }
    • 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.

      import { Player } from "@minecraft/server";

      // Surely someone enjoy minecraft ambient music
      const allMusic = [
      "music.overworld.bamboo_jungle",
      "music.overworld.bamboo_jungle",
      "music.game.basalt_deltas",
      "music.game_and_wild_equal_chance",
      "music.game_and_wild_equal_chance",
      "music.game_and_wild_favor_game",
      "music.overworld.cherry_grove",
      "music.game.creative",
      "music.game.credits",
      "music.game.crimson_forest",
      "music.overworld.deep_dark",
      "music.overworld.desert",
      "music.overworld.desert",
      "music.overworld.desert",
      "music.overworld.dripstone_caves",
      "music.game.end",
      "music.game.endboss",
      "music.overworld.flower_forest",
      "music.game_and_wild_equal_chance",
      "music.game.frozen_peaks",
      "music.game",
      "music.overworld.grove",
      "music.game.nether_wastes",
      "music.overworld.jagged_peaks",
      "music.overworld.jungle",
      "music.overworld.jungle_edge",
      "music.overworld.jungle",
      "music.overworld.jungle",
      "music.game_and_wild_equal_chance",
      "music.overworld.lush_caves",
      "music.game.swamp_music",
      "music.game.meadow",
      "music.game_and_wild_favor_game",
      "music.menu",
      "music.overworld.mesa",
      "music.overworld.mesa",
      "music.overworld.mesa",
      "music.game.nether",
      "music.game_and_wild_favor_game",
      "music.game_and_wild_favor_game",
      "music.game_and_wild_equal_chance",
      "music.game_and_wild_equal_chance",
      "music.overworld.snowy_slopes",
      "music.game.soulsand_valley",
      "music.overworld.stony_peaks",
      "music.game.swamp_music",
      "music.game.swamp_music",
      "music.game.water",
      ];

      function queueAllMusic(player: Player) {
      for (const musicTrackId of allMusic) {
      player.queueMusic(musicTrackId, { fade: 1.0 });
      }
      }
    • Returns void

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

      This function can throw errors.

      InvalidEntityError

      minecraftcommon.UnsupportedFunctionalityError

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

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

      // Note: You cannot despawn players via entity.remove()
      const entities = world.getDimension("overworld").getEntities({ excludeTypes: ["minecraft:player"] });

      for (const entity of entities) {
      entity.remove();
      }
    • Parameters

      • targetEntity: Entity
      • identifier: string

      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.

    • Parameters

      • tag: string

      Returns boolean

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

      This function can throw errors.

      InvalidEntityError

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

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

      for (const player of world.getAllPlayers()) {
      player.removeTag("admin");
      }
    • 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.

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

      for (const player of world.getAllPlayers()) {
      player.resetLevel();
      }
    • Parameters

      • identifier: string
      • Optionalvalue: string | number | boolean | Vector3

      Returns void

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

      This function can throw errors.

      minecraftcommon.ArgumentOutOfBoundsError

      InvalidEntityError

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

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

      world.afterEvents.entitySpawn.subscribe((event) => {
      event.entity.setDynamicProperty("spawn_location", event.entity.location); // set location spawn
      });

      world.beforeEvents.entityRemove.subscribe((event) => {
      const location = event.removedEntity.getDynamicProperty("spawn_location") as Vector3; // get location spawn
      const dimension = event.removedEntity.dimension;
      system.run(() => {
      dimension.spawnEntity<string>(event.removedEntity.typeId, location);
      });
      });
    • 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.

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

      for (const player of world.getAllPlayers()) {
      player.setGameMode(GameMode.Creative);
      }
    • Parameters

      • seconds: number
      • OptionaluseEffects: boolean

        Defaults to: true

      Returns boolean

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

      This function can throw errors.

      InvalidEntityError

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

    • Parameters

      • identifier: string
      • value: string | number | boolean

      Returns void

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

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

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

      const tileEntity = world.getDimension("overworld").getEntities({ type: "create:dummy" })[0];
      tileEntity.setProperty("create:rotation_offset", 1);
      console.warn(tileEntity.getProperty("create:rotation_offset"));
    • Parameters

      • targetEntity: Entity
      • identifier: string
      • value: string | number | boolean

      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.

    • Parameters

      • cooldownCategory: string
      • tickDuration: number

      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.

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

    • Parameters

      Returns void

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

      This function can throw errors.

      InvalidEntityError

      minecraftcommon.UnsupportedFunctionalityError

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

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

      system.afterEvents.scriptEventReceive.subscribe(({ sourceEntity, message }) => {
      if (!sourceEntity) return;

      if (message === "tp:nether") {
      sourceEntity.teleport({ x: 0, y: 0, z: 0 }, { dimension: world.getDimension("nether") });
      }
      });
      import { system, world } from "@minecraft/server";

      system.afterEvents.scriptEventReceive.subscribe(({ sourceEntity, message }) => {
      if (!sourceEntity) return;

      if (message === "tp:nether") {
      sourceEntity.teleport(
      { x: 0, y: 0, z: 0 },
      {
      dimension: world.getDimension("nether"),
      facingLocation: { x: 100, y: 100, z: 100 },
      }
      );
      }
      });