Script API - v1.21.31

Script API References

Landing page for Minecraft Bedrock Script API Reference, containing documentation related to experimental and stable Minecraft Script APIs to interact with a Minecraft world programmatically.

The libraries of Script APIs are grouped under the @minecraft scope on Minecraft and npm.

Documentation

Visit one of the following links to view the full documentation that matches your Minecraft version.

Minecraft Module

The Minecraft module, also known as @minecraft/server module, is the main script module to manipulate a Minecraft world. Here are some programmatic features that are available in the Minecraft module:

Common Capabilities

Here are some core features the module provides:

  • Manipulate a Minecraft world, including entities, blocks, dimensions, and more.
  • Register Custom Components for blocks and items.
  • Provides input and device infomation for a Minecraft player's client instance.
  • Changes game rules that apply to the world.
  • Controls player's camera view.
  • Use the System API to process long running operations.

Events

The Minecraft module allows you to respond to specific event occurs in Minecraft using event handlers in JavaScript. Event handlers are callback routines made by you. They are triggered in response to an interaction, like when a player interacts with an entity.

Minecraft Script API's events are broken down into following categories:

  • System Events: Event handlers are triggered when a system-level operation is triggered.
  • World Events: Event handlers are triggered when an event happens within a Minecraft world.

Data Storage

The Minecraft module also provides mechanisms for script plugins to store data, in key/value pairs, in a Minecraft world.

The two mechanisms within Minecraft world storage (accessible through Script API) are as follows:

  • Dynamic Properties: Maintains a separate storage for entities, items and world, that is accessible with only script API per behavior pack.
  • Scoreboards: Stores the score of entities in objectives. An objective tracks a single statistic for entities.

Minecraft UI Module

The @minecraft/server-ui module helps you build simple form or dialogs to players.

Action Forms

A form with a list of buttons with captions and images for presenting a set of options to a player.

Message Forms

A form with two-button that are functional for Yes/No or OK/Cancel questions.

Modal Forms

A more flexible "questionnaire-style" list of controls in a form that can be used to take input.

GameTest Framework

One of the sample GameTests from Microsoft sample GameTest repository on GitHub

GameTest Framework is a toolset available to creators to build and test any new content using the @minecraft/server-gametest script module and the /gametest command in Minecraft. Each GameTest is broken into the following:

  • Register a test: create an environment to conduct a test.
  • Setup a test: Setup the environment to run the test.
  • Validate a test: Evaluates whether a test passed or failed.

Minecraft HTTP module

Use the Script API to send HTTP requests to the internet using the @minecraft/server-net module.

Minecraft Editor Module

Bedrock Editor with Editor Samples Add-On in Minecraft Preview v1.21.30 (August 2024)

The Minecraft Editor or the @minecraft/server-editor module is a built-in JavaScript library for Editor extensions to build complex tools to build, edit, and test worlds. Currently, this API is only accessible in Bedrock Preview on Windows.

An Editor extension is a set of resource pack and behavior packs, like .mcaddon files but for Editor, uses this API to perform most actions in the Bedrock Editor.

Here are some examples of what you can achieve with the Extension API:

  • Add built-in Ore UI components & views in the editor UI.
  • Create custom tools in the Editor panel.
  • Register custom actions and hotkeys to use a tool.
  • Export and playtest an Editor project as playable world.

Server Admin Module

Load configuration of variables and secrets in Bedrock Dedicated Server folder using Script API.

Debug Utilities Module

A Script API module that is used for debugging purposes. Currently features:

  • Configure performance watchdog timing warnings for a plugin.
  • Provide access to performance-related infomation for script runtimes.