Skip to content

@minecraft/server


@minecraft/server / Dimension

Class: Dimension ​

Defined in: @minecraft/server/index.d.ts:7222

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

Properties ​

heightRange ​

readonly heightRange: NumberRange

Defined in: @minecraft/server/index.d.ts:7230

Remarks ​

Height range of the dimension.

Throws ​

This property can throw when used.


id ​

readonly id: string

Defined in: @minecraft/server/index.d.ts:7236

Remarks ​

Identifier of the dimension.


localizationKey ​

readonly localizationKey: string

Defined in: @minecraft/server/index.d.ts:7243

Remarks ​

Key for the localization of a dimension's name used by language files.

Methods ​

containsBiomes() ​

containsBiomes(volume, biomeFilter, isSuperset): boolean

Defined in: @minecraft/server/index.d.ts:7285

Parameters ​

volume ​

BlockVolumeBase

Area to check biomes in.

biomeFilter ​

BiomeFilter

A list of biomes to include and exclude. A list of tags to include and exclude. Will return false if a biome is found in the area that is in the excluded list or contains any of the excluded tags.

isSuperset ​

boolean

Superset is used to determine the strictness of the filter. If superset is set to true then the area must contain one or more biomes in the included list or that contains all of the included tags. If superset is set to false then the area must contain only biomes in the included list and that contain all of the included tags

Returns ​

boolean

Returns true if the biomes in the area match the filter settings passed in. Otherwise, returns false.

Remarks ​

Checks if an area contains the specified biomes. If the area is partially inside world boundaries, only the area that is in bounds will be searched. This operation takes longer proportional to both the area of the volume and the number of biomes to check.

Throws ​

An error will be thrown if the area provided includes unloaded chunks. An error will be thrown if the area provided is completely outside the world boundaries. An error will be thrown if an unknown biome name is provided.

minecraftcommon.EngineError

minecraftcommon.InvalidArgumentError

LocationOutOfWorldBoundariesError

UnloadedChunksError


containsBlock() ​

containsBlock(volume, filter, allowUnloadedChunks?): boolean

Defined in: @minecraft/server/index.d.ts:7311

Parameters ​

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

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. Defaults to: false

Returns ​

boolean

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

Remarks ​

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

Throws ​

This function can throw errors.

Error

UnloadedChunksError


createExplosion() ​

createExplosion(location, radius, explosionOptions?): boolean

Defined in: @minecraft/server/index.d.ts:7369

Parameters ​

location ​

Vector3

The location of the explosion.

radius ​

number

Radius, in blocks, of the explosion to create. Bounds: [0, 1000]

explosionOptions? ​

ExplosionOptions

Additional configurable options for the explosion.

Returns ​

boolean

Remarks ​

Creates an explosion at the specified location.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

Examples ​

createExplosion.ts

typescript
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);
}

createNoBlockExplosion.ts

typescript
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 });
}

createExplosions.ts

typescript
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 });
}

fillBlocks() ​

fillBlocks(volume, block, options?): ListBlockVolume

Defined in: @minecraft/server/index.d.ts:7395

Parameters ​

volume ​

BlockVolumeBase

Volume of blocks to be filled.

block ​

string | BlockPermutation | BlockType

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.

Returns ​

ListBlockVolume

Returns a ListBlockVolume which contains all the blocks that were placed.

Remarks ​

Fills an area of blocks with a specific block type.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

minecraftcommon.EngineError

Error

UnloadedChunksError


getBiome() ​

getBiome(location): BiomeType

Defined in: @minecraft/server/index.d.ts:7416

Parameters ​

location ​

Vector3

Location at which to check the biome.

Returns ​

BiomeType

Remarks ​

Returns the biome type at the specified location.

Throws ​

An error will be thrown if the location is out of world bounds. An error will be thrown if the location is in an unloaded chunk.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


getBlock() ​

getBlock(location): Block | undefined

Defined in: @minecraft/server/index.d.ts:7440

Parameters ​

location ​

Vector3

The location at which to return a block.

Returns ​

Block | undefined

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

Remarks ​

Returns a block instance at the given location.

Throws ​

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


getBlockAbove() ​

getBlockAbove(location, options?): Block | undefined

Defined in: @minecraft/server/index.d.ts:7453

Parameters ​

location ​

Vector3

Location to retrieve the block above from.

options? ​

BlockRaycastOptions

The options to decide if a block is a valid result.

Returns ​

Block | undefined

Remarks ​

Gets the first block found above a given block location based on the given options (by default will find the first solid block above).

Throws ​

This function can throw errors.


getBlockBelow() ​

getBlockBelow(location, options?): Block | undefined

Defined in: @minecraft/server/index.d.ts:7466

Parameters ​

location ​

Vector3

Location to retrieve the block below from.

options? ​

BlockRaycastOptions

The options to decide if a block is a valid result.

Returns ​

Block | undefined

Remarks ​

Gets the first block found below a given block location based on the given options (by default will find the first solid block below).

Throws ​

This function can throw errors.


getBlockFromRay() ​

getBlockFromRay(location, direction, options?): BlockRaycastHit | undefined

Defined in: @minecraft/server/index.d.ts:7480

Parameters ​

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.

Returns ​

BlockRaycastHit | undefined

Remarks ​

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

Throws ​

This function can throw errors.


getBlocks() ​

getBlocks(volume, filter, allowUnloadedChunks?): ListBlockVolume

Defined in: @minecraft/server/index.d.ts:7505

Parameters ​

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

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. Defaults to: false

Returns ​

ListBlockVolume

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

Remarks ​

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

Throws ​

This function can throw errors.

Error

UnloadedChunksError


getEntities() ​

getEntities(options?): Entity[]

Defined in: @minecraft/server/index.d.ts:7590

Parameters ​

options? ​

EntityQueryOptions

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

Returns ​

Entity[]

An entity array.

Remarks ​

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

Throws ​

This function can throw errors.

CommandError

minecraftcommon.InvalidArgumentError

Examples ​

bounceSkeletons.ts

typescript
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);
  }
}

tagsQuery.ts

typescript
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();
  }
}

testThatEntityIsFeatherItem.ts

typescript
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);
      }
    }
  }
}

getEntitiesAtBlockLocation() ​

getEntitiesAtBlockLocation(location): Entity[]

Defined in: @minecraft/server/index.d.ts:7600

Parameters ​

location ​

Vector3

The location at which to return entities.

Returns ​

Entity[]

Zero or more entities at the specified location.

Remarks ​

Returns a set of entities at a particular location.


getEntitiesFromRay() ​

getEntitiesFromRay(location, direction, options?): EntityRaycastHit[]

Defined in: @minecraft/server/index.d.ts:7618

Parameters ​

location ​

Vector3

direction ​

Vector3

options? ​

EntityRaycastOptions

Additional options for processing this raycast query.

Returns ​

EntityRaycastHit[]

Remarks ​

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

Throws ​

This function can throw errors.

minecraftcommon.EngineError

minecraftcommon.InvalidArgumentError

InvalidEntityError

minecraftcommon.UnsupportedFunctionalityError


getLightLevel() ​

getLightLevel(location): number

Defined in: @minecraft/server/index.d.ts:7634

Parameters ​

location ​

Vector3

Location of the block we want to check the brightness of.

Returns ​

number

The brightness level on the block.

Remarks ​

Returns the total brightness level of light shining on a certain block position.

Throws ​

This function can throw errors.

minecraftcommon.InvalidArgumentError

LocationInUnloadedChunkError


getPlayers() ​

getPlayers(options?): Player[]

Defined in: @minecraft/server/index.d.ts:7651

Parameters ​

options? ​

EntityQueryOptions

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

Returns ​

Player[]

A player array.

Remarks ​

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

Throws ​

This function can throw errors.

CommandError

minecraftcommon.InvalidArgumentError


getSkyLightLevel() ​

getSkyLightLevel(location): number

Defined in: @minecraft/server/index.d.ts:7667

Parameters ​

location ​

Vector3

Position of the block we want to check the brightness of.

Returns ​

number

The brightness level on the block.

Remarks ​

Returns the brightness level of light shining from the sky on a certain block position.

Throws ​

This function can throw errors.

minecraftcommon.InvalidArgumentError

LocationInUnloadedChunkError


getTopmostBlock() ​

getTopmostBlock(locationXZ, minHeight?): Block | undefined

Defined in: @minecraft/server/index.d.ts:7679

Parameters ​

locationXZ ​

VectorXZ

Location to retrieve the topmost block for.

minHeight? ​

number

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

Returns ​

Block | undefined

Remarks ​

Returns the highest block at the given XZ location.

Throws ​

This function can throw errors.


isChunkLoaded() ​

isChunkLoaded(location): boolean

Defined in: @minecraft/server/index.d.ts:7688

Parameters ​

location ​

Vector3

Location to check if the chunk is loaded.

Returns ​

boolean

Remarks ​

Returns true if the chunk at the given location is loaded (and valid for use with scripting).


placeFeature() ​

placeFeature(featureName, location, shouldThrow?): boolean

Defined in: @minecraft/server/index.d.ts:7718

Parameters ​

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. Defaults to: false

Returns ​

boolean

Remarks ​

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

This function can't be called in restricted-execution mode.

Throws ​

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


placeFeatureRule() ​

placeFeatureRule(featureRuleName, location): boolean

Defined in: @minecraft/server/index.d.ts:7739

Parameters ​

featureRuleName ​

string

The string identifier for the feature rule.

location ​

Vector3

Location to place the feature rule.

Returns ​

boolean

Remarks ​

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

This function can't be called in restricted-execution mode.

Throws ​

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


playSound() ​

playSound(soundId, location, soundOptions?): void

Defined in: @minecraft/server/index.d.ts:7761

Parameters ​

soundId ​

string

Identifier of the sound.

location ​

Vector3

Location of the sound.

soundOptions? ​

WorldSoundOptions

Additional options for configuring additional effects for the sound.

Returns ​

void

Remarks ​

Plays a sound for all players.

This function can't be called in restricted-execution mode.

Throws ​

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.

minecraftcommon.PropertyOutOfBoundsError


runCommand() ​

runCommand(commandString): CommandResult

Defined in: @minecraft/server/index.d.ts:7784

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.

Remarks ​

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

This function can't be called in restricted-execution mode.

Throws ​

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


setBlockPermutation() ​

setBlockPermutation(location, permutation): void

Defined in: @minecraft/server/index.d.ts:7804

Parameters ​

location ​

Vector3

The location within the dimension to set the block.

permutation ​

BlockPermutation

The block permutation to set.

Returns ​

void

Remarks ​

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

This function can't be called in restricted-execution mode.

Throws ​

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

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


setBlockType() ​

setBlockType(location, blockType): void

Defined in: @minecraft/server/index.d.ts:7827

Parameters ​

location ​

Vector3

The location within the dimension to set the block.

blockType ​

string | BlockType

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

Returns ​

void

Remarks ​

Sets a block at a given location within the dimension.

This function can't be called in restricted-execution mode.

Throws ​

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

Error

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError


setWeather() ​

setWeather(weatherType, duration?): void

Defined in: @minecraft/server/index.d.ts:7843

Parameters ​

weatherType ​

WeatherType

Set the type of weather to apply.

duration? ​

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. Bounds: [1, 1000000]

Returns ​

void

Remarks ​

Sets the current weather within the dimension

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.


spawnEntity() ​

spawnEntity(identifier, location, options?): Entity

Defined in: @minecraft/server/index.d.ts:7923

Parameters ​

identifier ​

string | EntityType

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

Returns ​

Entity

Newly created entity at the specified location.

Remarks ​

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

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

EntitySpawnError

minecraftcommon.InvalidArgumentError

InvalidEntityError

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

Examples ​

spawnAdultHorse.ts

typescript
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&lt;minecraft:ageable_grow_up&gt;',
    Vector3Utils.add(targetLocation, { x: 0, y: 1, z: 0 })
  );
}

quickFoxLazyDog.ts

typescript
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);
}

triggerEvent.ts

typescript
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');
}

spawnItem() ​

spawnItem(itemStack, location): Entity

Defined in: @minecraft/server/index.d.ts:7977

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.

Remarks ​

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

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

Examples ​

itemStacks.ts

typescript
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);
}

spawnFeatherItem.ts

typescript
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}!`);
}

spawnParticle() ​

spawnParticle(effectName, location, molangVariables?): void

Defined in: @minecraft/server/index.d.ts:8017

Parameters ​

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.

Returns ​

void

Remarks ​

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

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

LocationInUnloadedChunkError

LocationOutOfWorldBoundariesError

Example ​

spawnParticle.ts

typescript
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);
  }
}