BetaOptionalallowUnloadedChunks: booleanThe location of the explosion.
Radius, in blocks, of the explosion to create.
OptionalexplosionOptions: ExplosionOptionsAdditional configurable options for the explosion.
Creates an explosion at the specified location.
This function can't be called in read-only mode.
// Creates an explosion of radius 15 that does not break blocks
import { DimensionLocation } from '@minecraft/server';
function createExplosions(location: DimensionLocation) {
// Creates an explosion of radius 15 that does not break blocks
location.dimension.createExplosion(location, 15, { breaksBlocks: false });
// Creates an explosion of radius 15 that does not cause fire
location.dimension.createExplosion(location, 15, { causesFire: true });
// Creates an explosion of radius 10 that can go underwater
location.dimension.createExplosion(location, 10, { allowUnderwater: true });
}
BetaType of block to fill the volume with.
Optionaloptions: BlockFillOptionsA set of additional options, such as a matching block to potentially replace this fill block with.
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.
BetaStarting location to look for a biome to find.
Identifier of the biome to look for.
Optionaloptions: 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.
This function can't be called in read-only mode.
BetaOptionaloptions: BlockRaycastOptionsThis function can't be called in read-only mode.
BetaOptionaloptions: BlockRaycastOptionsThis function can't be called in read-only mode.
Location from where to initiate the ray check.
Vector direction to cast the ray.
Optionaloptions: BlockRaycastOptionsAdditional options for processing this raycast query.
BetaOptionalallowUnloadedChunks: booleanimport {
BlockPermutation,
BlockVolume,
system,
world,
} from "@minecraft/server";
// Get every non-air block location at chunk (0, 0)
const overworld = world.getDimension("overworld");
const volume = new BlockVolume(
{ x: 0, y: overworld.heightRange.min, z: 0 },
{ x: 15, y: overworld.heightRange.max, z: 15 }
);
const locations = overworld.getBlocks(
volume,
{ excludeTypes: ["minecraft:air"] },
false
);
// A simple generator that replace non-air blocks to cobblestone at chunk (0, 0),
// yielding after each block placement.
function* blockPlacingGenerator() {
for (const location of locations.getBlockLocationIterator()) {
const block = overworld.getBlock(location);
block.setPermutation(BlockPermutation.resolve("minecraft:cobblestone"));
yield;
}
}
system.runJob(blockPlacingGenerator());
Optionaloptions: 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 { DimensionLocation, EntityComponentTypes } from "@minecraft/server";
// Returns true if a feather item entity is within 'distance' blocks of 'location'.
function isFeatherNear(location: DimensionLocation, distance: number): boolean {
const items = location.dimension.getEntities({
location: location,
maxDistance: 20,
});
for (const item of items) {
const itemComp = item.getComponent(EntityComponentTypes.Item);
if (itemComp) {
if (itemComp.itemStack.typeId.endsWith('feather')) {
return true;
}
}
}
return false;
}
import { EntityQueryOptions, DimensionLocation } from '@minecraft/server';
function mobParty(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 { EntityQueryOptions, GameMode, world } 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)
);
Optionaloptions: EntityRaycastOptionsAdditional options for processing this raycast query.
Optionaloptions: EntityQueryOptionsAdditional options that can be used to filter the set of players returned.
A player array.
Returns a set of players based on a set of conditions defined via the EntityQueryOptions set of filter criteria.
import { EntityQueryOptions, world } from "@minecraft/server";
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)
);
BetaOptionalminHeight: numberThis function can't be called in read-only mode.
BetaReturns a WeatherType that explains the broad category of weather that is currently going on.
OptionalsoundOptions: WorldSoundOptionsThis function can't be called in read-only mode.
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.
This function can't be called in read-only mode.
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.
BetaThis function can't be called in read-only mode.
BetaThis function can't be called in read-only mode.
Set the type of weather to apply.
Optionalduration: 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.
Sets the current weather within the dimension
This function can't be called in read-only mode.
Identifier of the type of entity to spawn. If no namespace is specified, 'minecraft:' is assumed.
The location at which to create the entity.
Optionaloptions: SpawnEntityOptionsNewly 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.
// Spawns an adult horse
import { DimensionLocation } from '@minecraft/server';
function spawnAdultHorse(location: DimensionLocation) {
// Create a horse and triggering the 'ageable_grow_up' event, ensuring the horse is created as an adult
location.dimension.spawnEntity('minecraft:horse<minecraft:ageable_grow_up>', location);
}
// Spawns a fox over a dog
import { DimensionLocation } from '@minecraft/server';
import { MinecraftEntityTypes } from '@minecraft/vanilla-data';
function spawnAdultHorse(location: DimensionLocation) {
// Create fox (our quick brown fox)
const fox = location.dimension.spawnEntity(MinecraftEntityTypes.Fox, {
x: location.x,
y: location.y + 2,
z: location.z,
});
fox.addEffect('speed', 10, {
amplifier: 2,
});
// Create wolf (our lazy dog)
const wolf = location.dimension.spawnEntity(MinecraftEntityTypes.Wolf, location);
wolf.addEffect('slowness', 10, {
amplifier: 2,
});
wolf.isSneaking = true;
}
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.
// Spawns a feather at a location
import { ItemStack, DimensionLocation } from '@minecraft/server';
import { MinecraftItemTypes } from '@minecraft/vanilla-data';
function spawnFeather(location: DimensionLocation) {
const featherItem = new ItemStack(MinecraftItemTypes.Feather, 1);
location.dimension.spawnItem(featherItem, location);
}
Identifier of the particle to create.
The location at which to create the particle emitter.
OptionalmolangVariables: 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.
This function can't be called in read-only mode.
// A function that spawns a particle at a random location near the target location for all players in the server
import { world, MolangVariableMap, DimensionLocation, Vector3 } 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);
}
}
A class that represents a particular dimension (e.g., The End) within a world.