A class that represents a particular dimension (e.g., The End) within a world.

Properties

heightRange: NumberRange

Height range of the dimension.

This property can throw when used.

id: string

Identifier of the dimension.

Methods

  • Beta

    Parameters

    • location: Vector3

      The location of the explosion.

    • radius: number

      Radius, in blocks, of the explosion to create.

    • OptionalexplosionOptions: ExplosionOptions

      Additional configurable options for the explosion.

    Returns boolean

    Creates an explosion at the specified location.

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

    const overworld = mc.world.getDimension("overworld");

    log("Creating an explosion of radius 10.");
    overworld.createExplosion(targetLocation, 10);
    const overworld = mc.world.getDimension("overworld");

    const explosionLoc = { x: targetLocation.x + 0.5, y: targetLocation.y + 0.5, z: targetLocation.z + 0.5};

    log("Creating an explosion of radius 15 that causes fire.");
    overworld.createExplosion(explosionLoc, 15, { causesFire: true });

    const belowWaterLoc = { x: targetLocation.x + 3, y: targetLocation.y + 1,z: targetLocation.z + 3};

    log("Creating an explosion of radius 10 that can go underwater.");
    overworld.createExplosion(belowWaterLoc, 10, { allowUnderwater: true });
    const overworld = mc.world.getDimension("overworld");

    const explodeNoBlocksLoc = {
    x: Math.floor(targetLocation.x + 1),
    y: Math.floor(targetLocation.y + 2),
    z: Math.floor(targetLocation.z + 1)
    };

    log("Creating an explosion of radius 15 that does not break blocks.");
    overworld.createExplosion(explodeNoBlocksLoc, 15, { breaksBlocks: false });
  • Beta

    Parameters

    • begin: Vector3

      The lower northwest starting corner of the area.

    • end: Vector3

      The upper southeast ending corner of the area.

    • block: string | BlockPermutation | BlockType

      Type of block to fill the volume with.

    • Optionaloptions: BlockFillOptions

      A set of additional options, such as a matching block to potentially replace this fill block with.

    Returns number

    Returns number of blocks placed.

    Fills an area between begin and end with block of type block.

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

    This function can throw errors.

  • Parameters

    • location: Vector3

      The location at which to return a block.

    Returns Block

    Block at the specified location, or 'undefined' if asking for a block at an unloaded chunk.

    Returns a block instance at the given location.

    PositionInUnloadedChunkError: Exception thrown when trying to interact with a Block object that isn't in a loaded and ticking chunk anymore

    PositionOutOfWorldBoundariesError: Exception thrown when trying to interact with a position outside of dimension height range

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • Parameters

    • Optionaloptions: EntityQueryOptions

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

    Returns Entity[]

    An entity array.

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

    This function can throw errors.

    let mobs = ["creeper", "skeleton", "sheep"];

    // create some sample mob data
    for (let i = 0; i < 10; i++) {
    overworld.spawnEntity(mobs[i % mobs.length], targetLocation);
    }

    let eqo: mc.EntityQueryOptions = {
    type: "skeleton",
    };

    for (let entity of overworld.getEntities(eqo)) {
    entity.applyKnockback(0, 0, 0, 1);
    }
    let mobs = ["creeper", "skeleton", "sheep"];

    // create some sample mob data
    for (let i = 0; i < 10; i++) {
    let mobTypeId = mobs[i % mobs.length];
    let entity = overworld.spawnEntity(mobTypeId, targetLocation);
    entity.addTag("mobparty." + mobTypeId);
    }

    let eqo: mc.EntityQueryOptions = {
    tags: ["mobparty.skeleton"],
    };

    for (let entity of overworld.getEntities(eqo)) {
    entity.kill();
    }
    const overworld = mc.world.getDimension("overworld");

    const items = overworld.getEntities({
    location: targetLocation,
    maxDistance: 20,
    });

    for (const item of items) {
    const itemComp = item.getComponent("item") as mc.EntityItemComponent;

    if (itemComp) {
    if (itemComp.itemStack.typeId.endsWith("feather")) {
    log("Success! Found a feather", 1);
    }
    }
    }
    import { GameMode } 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

    • location: Vector3

      The location at which to return entities.

    Returns Entity[]

    Zero or more entities at the specified location.

    Returns a set of entities at a particular location.

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

    This function can throw errors.

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

    Returns WeatherType

    Returns a WeatherType that explains the broad category of weather that is currently going on.

    Returns the current weather.

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

  • Parameters

    • commandString: string

      Command to run. Note that command strings should not start with slash.

    Returns CommandResult

    Returns a command result with a count of successful values from the command.

    Runs a command synchronously using the context of the broader dimenion.

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

    Throws an exception if the command fails due to incorrect parameters or command syntax, or in erroneous cases for the command. Note that in many cases, if the command does not operate (e.g., a target selector found no matches), this method will not throw an exception.

    CommandError

  • Parameters

    • commandString: string

      Command to run. Note that command strings should not start with slash.

    Returns Promise<CommandResult>

    For commands that return data, returns a CommandResult with an indicator of command results.

    Runs a particular command asynchronously from the context of the broader dimension. Note that there is a maximum queue of 128 asynchronous commands that can be run in a given tick.

    Throws an exception if the command fails due to incorrect parameters or command syntax, or in erroneous cases for the command. Note that in many cases, if the command does not operate (e.g., a target selector found no matches), this method will not throw an exception.

  • Parameters

    • weatherType: WeatherType

      Set the type of weather to apply.

    • Optionalduration: number

      Sets the duration of the weather (in ticks). If no duration is provided, the duration will be set to a random duration between 300 and 900 seconds.

    Returns void

    Sets the current weather within the dimension

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

    This function can throw errors.

  • Parameters

    • identifier: string

      Identifier of the type of entity to spawn. If no namespace is specified, 'minecraft:' is assumed.

    • location: Vector3

      The location at which to create the entity.

    Returns Entity

    Newly created entity at the specified location.

    Creates a new entity (e.g., a mob) at the specified location.

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

    const overworld = mc.world.getDimension("overworld");

    log("Create a horse and triggering the 'ageable_grow_up' event, ensuring the horse is created as an adult");
    overworld.spawnEntity("minecraft:horse<minecraft:ageable_grow_up>", targetLocation);
    const overworld = mc.world.getDimension("overworld");

    const fox = overworld.spawnEntity("minecraft:fox", {
    x: targetLocation.x + 1,
    y: targetLocation.y + 2,
    z: targetLocation.z + 3,
    });

    fox.addEffect("speed", 10, {
    amplifier: 2,
    });
    log("Created a fox.");

    const wolf = overworld.spawnEntity("minecraft:wolf", {
    x: targetLocation.x + 4,
    y: targetLocation.y + 2,
    z: targetLocation.z + 3,
    });
    wolf.addEffect("slowness", 10, {
    amplifier: 2,
    });
    wolf.isSneaking = true;
    log("Created a sneaking wolf.", 1);
    const creeper = overworld.spawnEntity("minecraft:creeper", targetLocation);

    creeper.triggerEvent("minecraft:start_exploding_forced");
  • Parameters

    • itemStack: ItemStack
    • location: Vector3

      The location at which to create the item stack.

    Returns Entity

    Newly created item stack entity at the specified location.

    Creates a new item stack as an entity at the specified location.

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

    const overworld = mc.world.getDimension('overworld');

    const oneItemLoc = { x: targetLocation.x + targetLocation.y + 3, y: 2, z: targetLocation.z + 1 };
    const fiveItemsLoc = { x: targetLocation.x + 1, y: targetLocation.y + 2, z: targetLocation.z + 1 };
    const diamondPickaxeLoc = { x: targetLocation.x + 2, y: targetLocation.y + 2, z: targetLocation.z + 4 };

    const oneEmerald = new mc.ItemStack(mc.MinecraftItemTypes.Emerald, 1);
    const onePickaxe = new mc.ItemStack(mc.MinecraftItemTypes.DiamondPickaxe, 1);
    const fiveEmeralds = new mc.ItemStack(mc.MinecraftItemTypes.Emerald, 5);

    log(`Spawning an emerald at (${oneItemLoc.x}, ${oneItemLoc.y}, ${oneItemLoc.z})`);
    overworld.spawnItem(oneEmerald, oneItemLoc);

    log(`Spawning five emeralds at (${fiveItemsLoc.x}, ${fiveItemsLoc.y}, ${fiveItemsLoc.z})`);
    overworld.spawnItem(fiveEmeralds, fiveItemsLoc);

    log(`Spawning a diamond pickaxe at (${diamondPickaxeLoc.x}, ${diamondPickaxeLoc.y}, ${diamondPickaxeLoc.z})`);
    overworld.spawnItem(onePickaxe, diamondPickaxeLoc);
    const featherItem = new mc.ItemStack(mc.MinecraftItemTypes.Feather, 1);

    overworld.spawnItem(featherItem, targetLocation);
    log(`New feather created at ${targetLocation.x}, ${targetLocation.y}, ${targetLocation.z}!`);
  • Parameters

    • effectName: string

      Identifier of the particle to create.

    • location: Vector3

      The location at which to create the particle emitter.

    • OptionalmolangVariables: MolangVariableMap

      A set of optional, customizable variables that can be adjusted for this particle.

    Returns void

    Creates a new particle emitter at a specified location in the world.

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

    for (let i = 0; i < 100; i++) {
    const molang = new mc.MolangVariableMap();

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

    let newLocation = {
    x: targetLocation.x + Math.floor(Math.random() * 8) - 4,
    y: targetLocation.y + Math.floor(Math.random() * 8) - 4,
    z: targetLocation.z + Math.floor(Math.random() * 8) - 4,
    };
    overworld.spawnParticle("minecraft:colored_flame_particle", newLocation, molang);
    }