实验性
预览版
实验性
Volume of blocks that will be checked.
Block filter that will be checked against each block in the volume.
可选
allowUnloadedChunks: booleanIf 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.
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: ExplosionOptionsAdditional 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: BlockFillOptionsA set of additional options, such as a block filter which can be used to include / exclude specific blocks in the fill.
Returns a ListBlockVolume which contains all the blocks that were placed.
实验性
Starting location to look for a biome to find.
Identifier of the biome to look for.
可选
options: BiomeSearchOptionsAdditional selection criteria for a biome search.
Returns a location of the biome, or undefined if a biome could not be found.
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。
实验性
可选
options: BlockRaycastOptions无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
可选
options: BlockRaycastOptions无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Location from where to initiate the ray check.
Vector direction to cast the ray.
可选
options: BlockRaycastOptionsAdditional 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: booleanIf 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.
Returns the ListBlockVolume that contains all the block locations that satisfied the block filter.
实验性
可选
options: EntityQueryOptionsAdditional options that can be used to filter the set of entities returned.
An entity array.
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 { 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: EntityRaycastOptionsAdditional options for processing this raycast query.
实验性
可选
options: EntityQueryOptionsAdditional options that can be used to filter the set of players returned.
A player array.
实验性
Returns a WeatherType that explains the broad category of weather that is currently going on.
实验性
Identifier of the sound.
Location of the sound.
可选
soundOptions: WorldSoundOptionsAdditional options for configuring additional effects for the sound.
实验性
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。
实验性
Command to run. Note that command strings should not start with slash.
For commands that return data, returns a CommandResult with an indicator of command results.
实验性
The location within the dimension to set the block.
The block permutation to set.
Sets a block in the world using a BlockPermutation. BlockPermutations are blocks with a particular state.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Set the type of weather to apply.
可选
duration: numberSets 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.
实验性
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: SpawnEntityOptionsNewly created entity at the specified location.
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。
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: MolangVariableMapA 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。
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.