类 Dimension实验性

表示世界中的特定维度(例如,末地)的类。

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

属性

heightRange: NumberRange

维度的高度范围。

Height range of the dimension.

This property can throw when used.

id: string

维度的标识符。

Identifier of the dimension.

方法

  • 实验性

    参数

    • volume: BlockVolumeBase

      要检查的方块区域。

      Volume of blocks that will be checked.

    • filter: BlockFilter

      将会检查方块体积中的每一个方块的方块过滤器。

      Block filter that will be checked against each block in the volume.

    • 可选allowUnloadedChunks: boolean

      若设置为 true 并且部分或全部方块体积在未加载的区块(Chunk)外,则会抑制 UnloadedChunksError。 将只检查方块体积中加载的区块的位置。

      If set to true will suppress the UnloadedChunksError if some or all of the block volume is outside of the loaded chunks. Will only check the block locations that are within the loaded chunks in the volume.

    返回 boolean

    若方块体积中至少有一个方块满足过滤器,将返回 true,否则返回 false。

    Returns true if at least one block in the volume satisfies the filter, false otherwise.

    在方块区域中查找满足方块过滤器的方块。

    Searches the block volume for a block that satisfies the block filter.

    This function can throw errors.

    Error

    UnloadedChunksError

  • 实验性

    参数

    • location: Vector3

      爆炸的位置。

      The location of the explosion.

    • radius: number

      要创建的爆炸半径,单位为方块。

      Radius, in blocks, of the explosion to create.

    • 可选explosionOptions: ExplosionOptions

      爆炸的附加配置选项。

      Additional configurable options for the explosion.

    返回 boolean

    在指定位置创建一个爆炸。

    Creates an explosion at the specified location.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

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

    function createExplosion(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
    log("Creating an explosion of radius 10.");
    targetLocation.dimension.createExplosion(targetLocation, 10);
    }
    import { DimensionLocation } from "@minecraft/server";
    import { Vector3Utils } from "@minecraft/math";

    function createNoBlockExplosion(
    log: (message: string, status?: number) => void,
    targetLocation: DimensionLocation
    ) {
    const explodeNoBlocksLoc = Vector3Utils.floor(Vector3Utils.add(targetLocation, { x: 1, y: 2, z: 1 }));

    log("Creating an explosion of radius 15 that does not break blocks.");
    targetLocation.dimension.createExplosion(explodeNoBlocksLoc, 15, { breaksBlocks: false });
    }
    import { DimensionLocation } from "@minecraft/server";
    import { Vector3Utils } from "@minecraft/math";

    function createExplosions(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
    const explosionLoc = Vector3Utils.add(targetLocation, { x: 0.5, y: 0.5, z: 0.5 });

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

    const belowWaterLoc = Vector3Utils.add(targetLocation, { x: 3, y: 1, z: 3 });

    log("Creating an explosion of radius 10 that can go underwater.");
    targetLocation.dimension.createExplosion(belowWaterLoc, 10, { allowUnderwater: true });
    }
  • 实验性

    参数

    • pos: Vector3

      起始位置,以开始查找生物群系。

      Starting location to look for a biome to find.

    • biomeToFind: string | BiomeType

      要查找的生物群系标识符。

      Identifier of the biome to look for.

    • 可选options: BiomeSearchOptions

      查找生物群系的附加筛选条件。

      Additional selection criteria for a biome search.

    返回 Vector3

    返回生物群系的位置,若未找到生物群系则返回 undefined。

    Returns a location of the biome, or undefined if a biome could not be found.

    查找离特定类型最近的生物群系的位置。 请注意,findClosestBiome 操作可能需要一些时间才能完成, 因此避免在特定 tick 内使用大量此类调用。

    Finds the location of the closest biome of a particular type. Note that the findClosestBiome operation can take some time to complete, so avoid using many of these calls within a particular tick.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

  • 实验性

    参数

    • location: Vector3

      用于返回方块的位置。

      The location at which to return a block.

    返回 Block

    指定位置的方块,若请求的方块在未加载的区块中,则返回 'undefined'。

    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: 尝试与不再位于加载和 ticking 区块内的方块对象交互时引发的异常。

    PositionInUnloadedChunkError: Exception thrown when trying

    • to interact with a Block object that isn't in a loaded and
    • ticking chunk anymore PositionOutOfWorldBoundariesError: 尝试与超出维度高度范围的位置交互时引发的异常。

    PositionOutOfWorldBoundariesError: Exception thrown when

    • trying to interact with a position outside of dimension
    • height range

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    参数

    • location: Vector3

      开始射线检测的位置。

      Location from where to initiate the ray check.

    • direction: Vector3

      进行射线检测的向量方向。

      Vector direction to cast the ray.

    • 可选options: BlockRaycastOptions

      处理此射线查询的其他选项。

      Additional options for processing this raycast query.

    返回 BlockRaycastHit

    获取从一个位置发出向量射线相交的第一个方块。

    Gets the first block that intersects with a vector emanating from a location.

  • 实验性

    参数

    • volume: BlockVolumeBase

      要检查的方块数量。

      Volume of blocks that will be checked.

    • filter: BlockFilter

      将会检查方块体积中的每一个方块的方块过滤器。

      Block filter that will be checked against each block in the volume.

    • 可选allowUnloadedChunks: boolean

      若设置为 true 并且部分或全部方块体积在未加载的区块(Chunk)外,则会抑制 UnloadedChunksError。 将只检查方块体积中加载的区块的位置。

      If set to true will suppress the UnloadedChunksError if some or all of the block volume is outside of the loaded chunks. Will only check the block locations that are within the loaded chunks in the volume.

    返回 ListBlockVolume

    返回包含所有满足方块过滤器的方块位置的 ListBlockVolume。

    Returns the ListBlockVolume that contains all the block locations that satisfied the block filter.

    获取区域内满足过滤器的所有方块。

    Gets all the blocks in a volume that satisfy the filter.

  • 实验性

    参数

    • 可选options: EntityQueryOptions

      过滤返回的实体的一组附加选项。

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

    返回 Entity[]

    一个实体数组。

    An entity array. *

    根据 EntityQueryOptions 里定义的条件,返回一组实体。

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

    This function can throw errors. *

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

    function bounceSkeletons(targetLocation: DimensionLocation) {
    const mobs = ["creeper", "skeleton", "sheep"];

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

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

    for (const entity of targetLocation.dimension.getEntities(eqo)) {
    entity.applyKnockback(0, 0, 0, 1);
    }
    }
    import { EntityQueryOptions, DimensionLocation } from "@minecraft/server";

    function tagsQuery(targetLocation: DimensionLocation) {
    const mobs = ["creeper", "skeleton", "sheep"];

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

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

    for (const entity of targetLocation.dimension.getEntities(eqo)) {
    entity.kill();
    }
    }
    import { EntityItemComponent, EntityComponentTypes, DimensionLocation } from "@minecraft/server";

    function testThatEntityIsFeatherItem(
    log: (message: string, status?: number) => void,
    targetLocation: DimensionLocation
    ) {
    const items = targetLocation.dimension.getEntities({
    location: targetLocation,
    maxDistance: 20,
    });

    for (const item of items) {
    const itemComp = item.getComponent(EntityComponentTypes.Item) as EntityItemComponent;

    if (itemComp) {
    if (itemComp.itemStack.typeId.endsWith("feather")) {
    log("Success! Found a feather", 1);
    }
    }
    }
    }
  • 实验性

    参数

    • location: Vector3

      用于返回实体的位置。

      The location at which to return entities.

    返回 Entity[]

    指定位置的零个或多个实体。

    Zero or more entities at the specified location.

    返回特定位置的一组实体。

    Returns a set of entities at a particular location.

  • 实验性

    参数

    返回 EntityRaycastHit[]

    获取从一个位置发出向量射线相交的实体。

    Gets entities that intersect with a specified vector emanating from a location.

  • 实验性

    参数

    • 可选options: EntityQueryOptions

      过滤返回的玩家的一组附加选项。

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

    返回 Player[]

    一个玩家数组。

    A player array.

    根据 EntityQueryOptions 里定义的条件,返回一组玩家。

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

  • 实验性

    参数

    • locationXZ: VectorXZ

      要检索最高方块的位置。

      Location to retrieve the topmost block for.

    • 可选minHeight: number

      开始搜索的 Y 坐标。默认为最大维度高度。

      The Y height to begin the search from. Defaults to the

      • maximum dimension height.

    返回 Block

    返回给定 XZ 位置的最高方块。

    Returns the highest block at the given XZ location.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    This function can throw errors.

  • 实验性

    返回 WeatherType

    返回一个 WeatherType,说明当前的天气。

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

    返回当前的天气。

    Returns the current weather.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

  • 实验性

    参数

    • featureName: string

      地形特征的字符串标识符。

      The string identifier for the feature.

    • location: Vector3

      放置地形特征的位置。

      Location to place the feature.

    • 可选shouldThrow: boolean

      指定如果无法放置地形特征时是否抛出错误。 注意:如果使用未知的地形特征名称或尝试在未加载的区块中放置, 函数调用将始终抛出错误。

      Specifies if the function call will throw an error if the feature could not be placed. Note: The function call will always throw an error if using an unknown feature name or trying to place in a unloaded chunk.

    返回 boolean

    将指定的地形特征放置在维度中的指定位置。

    Places the given feature into the dimension at the specified location.

    此函数无法在只读模式下调用。

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    如果地形特征名称无效,将抛出错误。 如果位置在未加载的区块中,将抛出错误。

    An error will be thrown if the feature name is invalid. An error will be thrown if the location is in an unloaded chunk.

    Error

    minecraftcommon.InvalidArgumentError

    LocationInUnloadedChunkError

  • 实验性

    参数

    • featureRuleName: string

      地形特征规则的字符串标识符。

      The string identifier for the feature rule.

    • location: Vector3

      放置地形特征规则的位置。

      Location to place the feature rule.

    返回 boolean

    将指定的地形特征规则放置在维度中的指定位置。

    Places the given feature rule into the dimension at the specified location.

    此函数无法在只读模式下调用。

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    如果地形特征规则名称无效,将抛出错误。 如果位置在未加载的区块中,将抛出错误。

    An error will be thrown if the feature rule name is invalid. An error will be thrown if the location is in an unloaded chunk.

    minecraftcommon.InvalidArgumentError

    LocationInUnloadedChunkError

  • 实验性

    参数

    • soundId: string

      声音的标识符。

      Identifier of the sound.

    • location: Vector3

      声音的位置。

      Location of the sound.

    • 可选soundOptions: WorldSoundOptions

      额外的音效配置选项。

      Additional options for configuring additional effects for

      • the sound.

    返回 void

    为所有玩家播放声音。

    Plays a sound for all players.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    若音量小于 0.0,将抛出错误。 若音频淡入淡出值小于 0.0,则抛出错误。 若音高小于 0.01,则抛出错误。 若音量小于 0.0,将抛出错误。

    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.
  • 实验性

    参数

    • commandString: string

      要运行的命令。请注意,命令字符串不应以斜杠开头。

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

    返回 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.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    若命令由于参数或命令语法不正确或命令错误情况而失败,则抛出异常。 请注意,在许多情况下,若命令不执行(例如,一个目标选择器没有找到匹配),这个方法不会抛出异常。

    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

  • 实验性

    参数

    • commandString: string

      要运行的命令。请注意,命令字符串不应以斜杠开头。

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

    返回 Promise<CommandResult>

    对于返回数据的命令,返回一个 CommandResult,指示命令结果。

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

    注:此方法在最新版已被删除,这里为了兼容性保留

    从更广泛的维度上下文运行一个特定的命令异步。 请注意,在给定的 tick 内最大可运行 128 个异步命令。

    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.

  • 实验性

    参数

    • location: Vector3

      要设置方块的维度位置。

      The location within the dimension to set the block.

    • permutation: BlockPermutation

      要设置的方块排列。

      The block permutation to set.

    返回 void

    使用 BlockPermutation(带有特定状态的方块)在世界中设置一个方块。

    Sets a block in the world using a BlockPermutation. BlockPermutations are blocks with a particular state.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    若位置在未加载的块内或超出世界边界,将抛出错误。

    Throws if the location is within an unloaded chunk or outside of the world bounds.

    LocationInUnloadedChunkError

  • 实验性

    参数

    • location: Vector3

      维度内设置方块的位置。

      The location within the dimension to set the block.

    • blockType: string | BlockType

      要设置的方块类型。这可以是一个字符串标识符或 BlockType。默认使用方块排列。

      The type of block to set. This can be either a string identifier or a BlockType. The default block permutation is used.

    返回 void

    在维度内的指定位置设置一个方块。

    Sets a block at a given location within the dimension.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    Cannot be called in read-only mode, see WorldBeforeEvents.

    若位置在未加载的区块内或在世界边界之外,则抛出错误。

    Throws if the location is within an unloaded chunk or outside of the world bounds.

    Error

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

  • 实验性

    参数

    • weatherType: WeatherType

      设置要应用的天气类型。

      Set the type of weather to apply.

    • 可选duration: number

      设置天气的持续时间(以刻为单位)。若未提供持续时间,则持续时间将设置为 300 到 900 秒之间的随机值。

      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.

    返回 void

    设置维度内的当前天气。

    Sets the current weather within the dimension.

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    Cannot be called in read-only mode, see WorldBeforeEvents.

    此函数可能会抛出错误。

    This function can throw errors.

  • 实验性

    参数

    • identifier: string

      要生成的实体类型的标识符。若未指定命名空间,则假定为 'minecraft:'。

      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.

    • 可选options: SpawnEntityOptions

    返回 Entity

    在指定位置新创建的实体。

    Newly created entity at the specified location.

    在指定位置创建一个新的实体(例如,一个生物)。

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

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    Cannot be called in read-only mode, see WorldBeforeEvents.

    此函数可能会抛出错误。

    This function can throw errors.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    import { DimensionLocation } from "@minecraft/server";
    import { Vector3Utils } from "@minecraft/math";

    function spawnAdultHorse(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
    log("Create a horse and triggering the ageable_grow_up event, ensuring the horse is created as an adult");
    targetLocation.dimension.spawnEntity(
    "minecraft:horse<minecraft:ageable_grow_up>",
    Vector3Utils.add(targetLocation, { x: 0, y: 1, z: 0 })
    );
    }
    import { DimensionLocation } from "@minecraft/server";
    import { MinecraftEntityTypes, MinecraftEffectTypes } from "@minecraft/vanilla-data";

    function quickFoxLazyDog(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
    const fox = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Fox, {
    x: targetLocation.x + 1,
    y: targetLocation.y + 2,
    z: targetLocation.z + 3,
    });

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

    const wolf = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Wolf, {
    x: targetLocation.x + 4,
    y: targetLocation.y + 2,
    z: targetLocation.z + 3,
    });
    wolf.addEffect(MinecraftEffectTypes.Slowness, 10, {
    amplifier: 2,
    });
    wolf.isSneaking = true;
    log("Created a sneaking wolf.", 1);
    }
    import { DimensionLocation } from "@minecraft/server";
    import { MinecraftEntityTypes } from "@minecraft/vanilla-data";

    function triggerEvent(targetLocation: DimensionLocation) {
    const creeper = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Creeper, targetLocation);

    creeper.triggerEvent("minecraft:start_exploding_forced");
    }
  • 实验性

    参数

    • itemStack: ItemStack
    • location: Vector3

      创建物品堆的位置。

      The location at which to create the item stack.

    返回 Entity

    在指定位置新创建的物品堆实体。

    Newly created item stack entity at the specified location.

    在指定位置创建一个新的物品堆作为实体。

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

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    Cannot be called in read-only mode, see WorldBeforeEvents.

    此函数可能会抛出错误。

    This function can throw errors.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    import { ItemStack, DimensionLocation } from "@minecraft/server";
    import { MinecraftItemTypes } from "@minecraft/vanilla-data";

    function itemStacks(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
    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 ItemStack(MinecraftItemTypes.Emerald, 1);
    const onePickaxe = new ItemStack(MinecraftItemTypes.DiamondPickaxe, 1);
    const fiveEmeralds = new ItemStack(MinecraftItemTypes.Emerald, 5);

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

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

    log(`Spawning a diamond pickaxe at (${diamondPickaxeLoc.x}, ${diamondPickaxeLoc.y}, ${diamondPickaxeLoc.z})`);
    targetLocation.dimension.spawnItem(onePickaxe, diamondPickaxeLoc);
    }
    import { ItemStack, DimensionLocation } from "@minecraft/server";
    import { MinecraftItemTypes } from "@minecraft/vanilla-data";

    function spawnFeatherItem(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
    const featherItem = new ItemStack(MinecraftItemTypes.Feather, 1);

    targetLocation.dimension.spawnItem(featherItem, targetLocation);
    log(`New feather created at ${targetLocation.x}, ${targetLocation.y}, ${targetLocation.z}!`);
    }
  • 实验性

    参数

    • effectName: string

      要创建的粒子的标识符。

      Identifier of the particle to create.

    • location: Vector3

      创建粒子发射器的位置。

      The location at which to create the particle emitter.

    • 可选molangVariables: MolangVariableMap

      一组可选的、可定制的变量,可为此粒子调整。

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

    返回 void

    在世界的指定位置创建一个新的粒子发射器。

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

    无法在只读模式下调用此函数,详见 WorldBeforeEvents

    Cannot be called in read-only mode, see WorldBeforeEvents.

    此函数可能会抛出错误。

    This function can throw errors.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

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

    function spawnParticle(targetLocation: 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 = {
    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,
    };
    targetLocation.dimension.spawnParticle("minecraft:colored_flame_particle", newLocation, molang);
    }
    }