Class: World
worldBeta
A class that wraps the state of a world - a set of dimensions and the environment of Minecraft.
Properties
afterEvents
readonlyafterEvents:WorldAfterEvents
Early Execution Beta
Remarks
Contains a set of events that are applicable to the entirety of the world. Event callbacks are called in a deferred manner. Event callbacks are executed in read-write mode.
Privilege
early-execution-readable -
allowCheats
实验性allowCheats:
boolean
Beta World Mutation
Remarks
Enables or disables cheats.
Privilege
restricted-execution-read-only -
beforeEvents
readonlybeforeEvents:WorldBeforeEvents
Early Execution Beta
Remarks
Contains a set of events that are applicable to the entirety of the world. Event callbacks are called immediately. Event callbacks are executed in read-only mode.
Privilege
early-execution-readable -
Example
customCommand.ts
gameRules
readonlygameRules:GameRules
Beta
Remarks
The game rules that apply to the world.
isHardcore
readonlyisHardcore:boolean
Beta
primitiveShapesManager
readonlyprimitiveShapesManager:PrimitiveShapesManager
Beta
Remarks
Manager for adding and removing primitive text objects in the world.
scoreboard
readonlyscoreboard:Scoreboard
Beta
Remarks
Returns the general global scoreboard that applies to the world.
seed
readonlyseed:string
Beta
Remarks
The world seed.
soundDefinitionRegistry
实验性
readonlysoundDefinitionRegistry:SoundDefinitionRegistry
Beta
Preview
Remarks
Provides read-only access to the sound definitions loaded for this world.
structureManager
readonlystructureManager:StructureManager
Beta
Remarks
Returns the manager for Structure related APIs.
tickingAreaManager
readonlytickingAreaManager:TickingAreaManager
Beta
Remarks
Manager for adding, removing and querying pack specific ticking areas.
Methods
broadcastClientMessage()
broadcastClientMessage(
id,value):void
Beta World Mutation
Parameters
id
string
The message identifier.
value
string
The message.
Returns
void
Remarks
A method that is internal-only, used for broadcasting specific messages between client and server.
Privilege
no-restricted-execution -
clearDynamicProperties()
clearDynamicProperties():
void
Beta
Returns
void
Remarks
Clears the set of dynamic properties declared for this behavior pack within the world.
getAbsoluteTime()
getAbsoluteTime():
number
Beta
Returns
number
Remarks
Returns the absolute time since the start of the world.
getAimAssist()
getAimAssist():
AimAssistRegistry
Beta
Returns
Remarks
The aim-assist presets and categories that can be used in the world.
getAllPlayers()
getAllPlayers():
Player[]
Beta
Returns
Player[]
Remarks
Returns an array of all active players within the world.
Throws
This function can throw errors.
getClock()
getClock(
name):WorldClock
Beta
Parameters
name
string
The name of the world clock to retrieve.
Returns
The WorldClock with the given name.
Remarks
Retrieves a world clock by its name.
Throws
WorldClockNotFoundError: If the world clock with the given name does not exist.
getDay()
getDay():
number
Beta
Returns
number
The current day, determined by the world time divided by the number of ticks per day. New worlds start at day 0.
Remarks
Returns the current day.
getDefaultSpawnLocation()
getDefaultSpawnLocation():
Vector3
Beta
Returns
The default Overworld spawn location. By default, the Y coordinate is 32767, indicating a player's spawn height is not fixed and will be determined by surrounding blocks.
Remarks
Returns the default Overworld spawn location.
getDifficulty()
getDifficulty():
Difficulty
Beta
Returns
Returns the world difficulty.
Remarks
Gets the difficulty from the world.
getDimension()
getDimension(
dimensionId):Dimension
Beta
Parameters
dimensionId
string
The name of the dimension. For example, "overworld", "nether" or "the_end".
Returns
The requested dimension
Remarks
Returns a dimension object.
Throws
Throws if the given dimension name is invalid
getDynamicProperty()
getDynamicProperty(
identifier):string|number|boolean|Vector3|undefined
Beta
Parameters
identifier
string
The property identifier.
Returns
string | number | boolean | Vector3 | undefined
Returns the value for the property, or undefined if the property has not been set.
Remarks
Returns a property value.
Throws
Throws if the given dynamic property identifier is not defined.
Examples
incrementDynamicProperty.ts
incrementDynamicPropertyInJsonBlob.ts
getDynamicPropertyIds()
getDynamicPropertyIds():
string[]
Beta
Returns
string[]
A string array of active dynamic property identifiers.
Remarks
Gets a set of dynamic property identifiers that have been set in this world.
getDynamicPropertyTotalByteCount()
getDynamicPropertyTotalByteCount():
number
Beta
Returns
number
Remarks
Gets the total byte count of dynamic properties. This could potentially be used for your own analytics to ensure you're not storing gigantic sets of dynamic properties.
getEntity()
getEntity(
id):Entity|undefined
Beta
Parameters
id
string
The id of the entity.
Returns
Entity | undefined
The requested entity object.
Remarks
Returns an entity based on the provided id.
Throws
Throws if the given entity id is invalid.
getLootTableManager()
getLootTableManager():
LootTableManager
Beta
Returns
A loot table manager with a variety of loot generation methods.
Remarks
Returns a manager capable of generating loot from an assortment of sources.
getMoonPhase()
getMoonPhase():
MoonPhase
Beta
Returns
Remarks
Returns the MoonPhase for the current time.
getPackSettings()
getPackSettings():
Record<string,string[] |boolean|number|string>
Early Execution Beta
Returns
Record<string, string[] | boolean | number | string>
Remarks
Returns a map of pack setting name and value pairs.
Privilege
early-execution-allowed -
getPlayers()
getPlayers(
options?):Player[]
Beta
Parameters
options?
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
Throws if the provided EntityQueryOptions are invalid.
getTimeOfDay()
getTimeOfDay():
number
Beta
Returns
number
The time of day, in ticks, between 0 and 24000.
Remarks
Returns the time of day.
playMusic()
playMusic(
trackId,musicOptions?):void
World Mutation Beta
Parameters
trackId
string
musicOptions?
Returns
void
Remarks
Plays a particular music track for all players.
Privilege
no-restricted-execution -
Throws
This function can throw errors.
Example
playMusicAndSound.ts
queueMusic()
queueMusic(
trackId,musicOptions?):void
World Mutation Beta
Parameters
trackId
string
Identifier of the music track to play.
musicOptions?
Additional options for the music track.
Returns
void
Remarks
Queues an additional music track for players. If a track is not playing, a music track will play.
Privilege
no-restricted-execution -
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.
sendMessage()
sendMessage(
message):void
Beta
Parameters
message
string | RawMessage | (string | RawMessage)[]
The message to be displayed.
Returns
void
Remarks
Sends a message to all players.
Throws
This method can throw if the provided RawMessage is
in an invalid format. For example, if an empty name string
is provided to score.
setAbsoluteTime()
setAbsoluteTime(
absoluteTime):void
World Mutation Beta
Parameters
absoluteTime
number
The world time, in ticks.
Returns
void
Remarks
Sets the world time.
Privilege
no-restricted-execution -
setDefaultSpawnLocation()
setDefaultSpawnLocation(
spawnLocation):void
World Mutation Beta
Parameters
spawnLocation
Location of the spawn point. Note that this is assumed to be within the overworld dimension.
Returns
void
Remarks
Sets a default spawn location for all players.
Privilege
no-restricted-execution -
Throws
Throws if the provided spawn location is out of bounds.
Error
LocationOutOfWorldBoundariesError
setDifficulty()
setDifficulty(
difficulty):void
World Mutation Beta
Parameters
difficulty
The difficulty we want to set the world to.
Returns
void
Remarks
Sets the worlds difficulty.
Privilege
no-restricted-execution -
setDynamicProperties()
setDynamicProperties(
values):void
Beta
Parameters
values
Record<string, boolean | number | string | Vector3 | undefined>
A Record of key value pairs of the dynamic properties to set. If the data value is null, it will remove that property instead.
Returns
void
Remarks
Sets multiple dynamic properties with specific values.
Throws
This function can throw errors.
setDynamicProperty()
setDynamicProperty(
identifier,value?):void
Beta
Parameters
identifier
string
The property identifier.
value?
string | number | boolean | Vector3
Data value of the property to set. If the value is null, it will remove the property instead.
Returns
void
Remarks
Sets a specified property to a value.
Throws
Throws if the given dynamic property identifier is not defined.
Examples
incrementDynamicProperty.ts
incrementDynamicPropertyInJsonBlob.ts
setTimeOfDay()
setTimeOfDay(
timeOfDay):void
World Mutation Beta
Parameters
timeOfDay
number
The time of day, in ticks, between 0 and 24000.
Returns
void
Remarks
Sets the time of day.
Privilege
no-restricted-execution -
Throws
Throws if the provided time of day is not within the valid range.
stopMusic()
stopMusic():
void
World Mutation Beta
Returns
void
Remarks
Stops any music tracks from playing.
Privilege
no-restricted-execution -
