实验性
实验性
要检查的方块区域。
Volume of blocks that will be checked.
将会检查方块体积中的每一个方块的方块过滤器。
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.
若方块体积中至少有一个方块满足过滤器,将返回 true,否则返回 false。
Returns true if at least one block in the volume satisfies the filter, false otherwise.
实验性
爆炸的位置。
The location of the explosion.
要创建的爆炸半径,单位为方块。
Radius, in blocks, of the explosion to create.
可选
explosionOptions: ExplosionOptions爆炸的附加配置选项。
Additional configurable options for the explosion.
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 });
}
实验性
要填充的方块区域。
Volume of blocks to be filled.
要用来填充区域的方块类型。
Type of block to fill the volume with.
可选
options: BlockFillOptions额外的选项,例如可用于包括/排除特定方块的方块过滤器。
A set of additional options, such as a block filter which can be used to include / exclude specific blocks in the fill.
返回包含所有放置的方块的 ListBlockVolume。
Returns a ListBlockVolume which contains all the blocks that were placed.
用特定的方块类型填充一个区域。
Fills an area of blocks with a specific block type.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
起始位置,以开始查找生物群系。
Starting location to look for a biome to find.
要查找的生物群系标识符。
Identifier of the biome to look for.
可选
options: BiomeSearchOptions查找生物群系的附加筛选条件。
Additional selection criteria for a biome search.
返回生物群系的位置,若未找到生物群系则返回 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。
实验性
用于返回方块的位置。
The location at which to return a block.
指定位置的方块,若请求的方块在未加载的区块中,则返回 'undefined'。
Block at the specified location, or 'undefined' if asking for a block at an unloaded chunk.
PositionInUnloadedChunkError: 尝试与不再位于加载和 ticking 区块内的方块对象交互时引发的异常。
PositionInUnloadedChunkError: Exception thrown when trying
PositionOutOfWorldBoundariesError: Exception thrown when
实验性
可选
options: BlockRaycastOptions无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
可选
options: BlockRaycastOptions无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
开始射线检测的位置。
Location from where to initiate the ray check.
进行射线检测的向量方向。
Vector direction to cast the ray.
可选
options: BlockRaycastOptions处理此射线查询的其他选项。
Additional options for processing this raycast query.
实验性
要检查的方块数量。
Volume of blocks that will be checked.
将会检查方块体积中的每一个方块的方块过滤器。
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。
Returns the ListBlockVolume that contains all the block locations that satisfied the block filter.
实验性
可选
options: EntityQueryOptions过滤返回的实体的一组附加选项。
Additional options that can be used to filter the set of entities returned.
一个实体数组。
An entity array. *
根据 EntityQueryOptions 里定义的条件,返回一组实体。
Returns a set of entities based on a set of conditions defined via the EntityQueryOptions set of filter criteria.
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);
}
}
}
}
实验性
可选
options: EntityRaycastOptions处理此射线查询的其他选项。
Additional options for processing this raycast query.
实验性
可选
options: EntityQueryOptions过滤返回的玩家的一组附加选项。
Additional options that can be used to filter the set of players returned.
一个玩家数组。
A player array.
根据 EntityQueryOptions 里定义的条件,返回一组玩家。
Returns a set of players based on a set of conditions defined via the EntityQueryOptions set of filter criteria.
实验性
要检索最高方块的位置。
Location to retrieve the topmost block for.
可选
minHeight: number开始搜索的 Y 坐标。默认为最大维度高度。
The Y height to begin the search from. Defaults to the
返回给定 XZ 位置的最高方块。
Returns the highest block at the given XZ location.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
返回一个 WeatherType,说明当前的天气。
Returns a WeatherType that explains the broad category of weather that is currently going on.
实验性
地形特征的字符串标识符。
The string identifier for the feature.
放置地形特征的位置。
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.
将指定的地形特征放置在维度中的指定位置。
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.
实验性
地形特征规则的字符串标识符。
The string identifier for the feature rule.
放置地形特征规则的位置。
Location to place the feature rule.
将指定的地形特征规则放置在维度中的指定位置。
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.
实验性
声音的标识符。
Identifier of the sound.
声音的位置。
Location of the sound.
可选
soundOptions: WorldSoundOptions额外的音效配置选项。
Additional options for configuring additional effects for
实验性
要运行的命令。请注意,命令字符串不应以斜杠开头。
Command to run. Note that command strings should not start with slash.
返回命令结果,包含成功值。
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.
实验性
要运行的命令。请注意,命令字符串不应以斜杠开头。
Command to run. Note that command strings should not start with slash.
对于返回数据的命令,返回一个 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.
实验性
要设置方块的维度位置。
The location within the dimension to set the block.
要设置的方块排列。
The block permutation to set.
使用 BlockPermutation(带有特定状态的方块)在世界中设置一个方块。
Sets a block in the world using a BlockPermutation. BlockPermutations are blocks with a particular state.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
在维度内的指定位置设置一个方块。
Sets a block at a given location within the dimension.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
Cannot be called in read-only mode, see WorldBeforeEvents.
实验性
设置要应用的天气类型。
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.
设置维度内的当前天气。
Sets the current weather within the dimension.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
Cannot be called in read-only mode, see WorldBeforeEvents.
实验性
要生成的实体类型的标识符。若未指定命名空间,则假定为 'minecraft:'。
Identifier of the type of entity to spawn. If no namespace is specified, 'minecraft:' is assumed.
创建实体的位置。
The location at which to create the entity.
可选
options: SpawnEntityOptions在指定位置新创建的实体。
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.
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");
}
实验性
在指定位置新创建的物品堆实体。
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.
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}!`);
}
实验性
要创建的粒子的标识符。
Identifier of the particle to create.
创建粒子发射器的位置。
The location at which to create the particle emitter.
可选
molangVariables: MolangVariableMap一组可选的、可定制的变量,可为此粒子调整。
A set of optional, customizable variables that can be adjusted for this particle.
在世界的指定位置创建一个新的粒子发射器。
Creates a new particle emitter at a specified location in the world.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
Cannot be called in read-only mode, see WorldBeforeEvents.
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);
}
}
表示世界中的特定维度(例如,末地)的类。
A class that represents a particular dimension (e.g., The End) within a world.