Bedrock Wiki
  • Discord
  • Contribute
  • bedrock.dev
  • MS Learn
Beginner's Guide
  • Guide
    • 1. Introduction
      guide
    • 2. Add-Ons Explained
    • 3. Software & Preparation
    • 4. Project Setup
    • 5. Create a Custom Item
    • 6. Create a Custom Entity
    • 7. Blockbench: Modeling, Texturing & Animating
    • 8. Adding a Loot Table, Spawn Rule & Crafting Recipe
  • Extra
    • a. Understanding JSON
    • b. Download Example Packs
    • c. Troubleshooting
      help
    • d. Advanced Manifest
    • e. Format Versions
    • f. Project Setup Android
Animation Controllers
  • Intro to Animation Controllers
    guide
  • Entity Commands
  • AFK Detector
  • Death Commands
  • Molang into Scoreboard
  • Respawn Commands
Blocks
  • General
    • Intro to Blocks
      guide
    • Block Components
    • Block Tags
    • Block States
    • Block Traits
    • Block Permutations
    • Block Events
      Scripts
    • Block Event Migration
      help
    • Blocks as Items
    • Troubleshooting Blocks
      help
  • Visuals
    • Block Culling
    • Block Models
      guide
    • Block Texture Animation
    • Block Texture Variation
    • Block Tinting
  • Tutorials
    • Applying Constant Effects
      Scripts
    • Avoiding State Limit
    • Fake Blocks
    • Ore Loot Tables
      Scripts
    • Precise Interaction
      Scripts
    • Precise Rotation
      Scripts
    • Rotatable Blocks
  • Vanilla Re-Creations
    • Custom Crops
      Scripts
    • Custom Glass
    • Custom Glazed Terracotta
    • Custom Trapdoors
      Scripts
  • Documentation
    • Block Format History
    • Block Shapes
    • Block Sounds
    • Vanilla Block Models
Commands
  • General
    • Intro to Command Blocks
    • Functions
    • Block States
    • Coordinate System
    • NBT Commands
    • Scoreboard Operations
    • Understanding Selectors
  • Commands
    • Damage
    • Execute
    • Playanimation
    • Playsound
  • On Event Systems
    • On Player First Join
    • On Player Join
    • On Player Leave
    • On Player Death
    • On Player Respawn
    • On First World Load
  • Scoreboard Systems
    • Entity Counter
    • Scoreboard Timers
    • Comparing And Retrieving Scores
  • Techniques
    • Execute Logic Gates
    • MBE - Max's Block Entity
    • FMBE - A New Way to Create Display Entities
    • Look Detection
    • Movement Detections
    • Orbital Camera
  • Useful Creations
    • Custom Crafter
    • Multiplayer Position Rearrangement
      function
Concepts
  • contents.json
  • Emojis & Symbols
  • Molang
  • Namespaces
  • Overwriting Assets
  • Raw Text
  • Shaders
  • Sounds
  • Subpacks
  • Text and Localization
  • Texture Atlases
  • textures_list.json
Documentation
  • Shared Constructs
  • Advanced Molang
  • File Types
  • Fog IDs
  • Material Configuration Description
  • Menu Categories
  • Molang Queries
  • Pack Folder Structure
  • Sound Definitions
  • Vanilla Materials
Entities
  • General
    • Intro to Entities BP
      guide
    • Intro to Entities RP
      guide
    • Troubleshooting Entities
      help
    • Entity Events
    • Entity Properties
    • NPC Dialogues
    • Render Controllers
    • Spawn Rules
  • Tutorials
    • Convert Points Between Any Space (World, Entity, Bones)
    • Creating Boats
    • Detecting Other Entities
    • Disabling Team Damage
    • Dummy Entities
    • Entity Attacks
    • Entity Holds Item
    • Entity Movement
    • Entity Timers
    • Flying Entities
    • Introduction to AOE Clouds
    • Invulnerable Entities
    • Look at Entity
    • Sleeping Entities
    • Solid Entities
    • Spawning Tamed Entities
      Scripts
    • Village Mechanic
  • Documentation
    • Dummy Components
    • Non-Mob Runtime Identifiers
    • Projectiles
    • Runtime Identifiers
    • Vanilla Usage Components
    • Vanilla Usage Spawn Rules
Items
  • General
    • Intro to Items
      guide
    • Item Components
    • Item Tags
    • Item Events
      Scripts
    • Item Event Migration
      help
    • Troubleshooting Items
      help
  • Tutorials
    • Custom Armor
    • Custom Food
      Scripts
    • Custom Pottery Sherds
    • Custom Weapons
    • Equipment-Based Commands
    • High Resolution Items
    • Spawning Items
    • Throwable Items
  • Documentation
    • Enchantments
    • Attachables
    • Item Format History
    • Numerical Item IDs
    • Vanilla Item Identifiers
    • Vanilla Usage Components
JSON UI
  • General
    • Intro to JSON UI
      guide
    • Best Practices
      guide
  • Tutorials
    • Adding HUD Elements
    • Aseprite Animations
    • Buttons and Toggles
    • Modifying Server Forms
    • Preserve Title Texts
    • String to Number
  • Documentation
    • JSON UI Documentation
Loot, Recipes & Trading
  • General
    • Trading Behavior
  • Documentation
    • Loot Tables
    • Trade Tables
    • Recipes
    • Item Functions
  • Tutorials
    • Randomized Structure Loot
Meta
  • Add-On Performance
  • Style Guide
  • Useful Links
  • Using Schemas
  • Version Control
  • Q&A
    • Blocks and Items Q&A 2024/08/30
    • Deferred Technical Preview Q&A 2024/02/23
    • GameTest Q&A 2021/08/06
    • Scripting and Editor Q&A 2023/09/22
    • World Generation Q&A 2024/11/15
NBT
  • General
    • .mcstructure
  • Tutorials
    • Experiments in Education Edition
    • Extending Structure Limits
  • NBT in Depth
    • About NBT (Named Binary Tag)
    • NBT Libraries
    • Reading NBT Example
Particles
  • General
    • Intro to Particles
      guide
  • Tutorials
    • Disabling Particles
  • Documentation
    • Vanilla Particles
Scripting
  • General
    • Intro to Scripting
    • What is Script API?
    • API Modules
  • Tutorials
    • Block Placement Prevention
    • GameTests
    • Script Core Features
    • Script Forms
    • Script Requests API
    • Simple Chat Commands
  • Documentation
    • Engine Environment
    • Script Resources
    • Script Watchdog
    • Troubleshooting JavaScript
    • TypeScript
Servers
  • Software
    • Bedrock Server Software
  • Protocols
    • Bedrock Protocol
    • NetherNet Protocol
    • RakNet Protocol
Visuals
  • General
    • Introduction to Entity Visuals
      guide
    • Bedrock Modeling
    • Custom Death Animations
    • Effects in Animations
    • Material Creations
    • Materials
    • Math-Based Animations
    • Skin Packs
  • Tutorials
    • Entity Texture Animation
    • Glowing Entity Texture
    • Hurt Animations
    • Leash Position
    • Player Geometry
    • Remove Entity Shadows
    • Retexturing Spawn Eggs
  • Ideas
    • Structure Presentation
World Generation
  • General
    • Intro to World Generation
      guide
    • Biomes
      guide
    • Feature Types
    • Jigsaw Structures
  • Tutorials
    • Block Conditions for Features
    • Generating Custom Ores
    • Generating Custom Structures
    • Generating Patches
    • Heightmap Noise
  • Documentation
    • Biome Tags

Intro to Scripting

Intro to Scripting
  • Overview
  • Create Your First Project
  • Writing Scripts with JS
  • Script API 2.0.0
  • Reference Documentation

TIP

This script API page assumes basic knowledge of pack setup for add-ons. For information on how to set up behaviour packs, please see the Introduction to Add-Ons page.

WARNING

The Script API is currently in active development, and breaking changes are frequent. This page assumes the format of Minecraft 1.21.70x.

Overview ​

The Script API (formerly GameTest Framework) is a feature that allows for a new variety of creations, these are built with JavaScript files in the behavior pack folder. Most parts of the Script API are not experimental.

This page will give you an introduction to the 80% of Minecraft's Creator API concepts that you will use on a daily basis.

Create Your First Project ​

Currently, scripts can only be used in behavior packs.

In the behavior pack manifest, you need to add a script module and set an entry point for your script project. Currently, only "javascript" is supported as a valid language.

BP/manifest.json#modules[0]
json
{
    "uuid": "239c134f-67bf-4738-9bcc-8c69d31b1f72",
    "version": [1, 0, 0],
    "type": "script",
    "language": "javascript",
    "entry": "scripts/main.js"
}
1
2
3
4
5
6
7

Additionally, dependencies will need to be set based on modules used. To import and use script API modules, you must specify dependencies using the module_name and version. In this example, the @minecraft/server module is used.

BP/manifest.json
json
{
    "format_version": 2,
    "header": {
        "name": "Bedrock Add-ons",
        "description": "Script API Template",
        "uuid": "<UUID>",
        "version": [0, 1, 0],
        "min_engine_version": [1, 20, 70]
    },
    "modules": [
        {
            "type": "script",
            "language": "javascript",
            "uuid": "<UUID>",
            // Your entry file; where Minecraft will read your code from.
            "entry": "scripts/main.js",
            "version": [0, 1, 0]
        }
    ],
    // to use eval() and Function() inside your code, remove it if not neccessary
    "capabilities": ["script_eval"],
    "dependencies": [
        {
            // Enables the use of @minecraft/server module, with a version of 1.17.0.
            // It must be the latest version or it might not work!
            "module_name": "@minecraft/server",
            "version": "1.18.0"
        },
        {
            // Enables the use of @minecraft/server-ui module, with a version of 1.3.0.
            // It must be the latest version or it might not work!
            "module_name": "@minecraft/server-ui",
            "version": "1.3.0"
        }
    ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

If your project needs other module to run your code, add the other dependencies that follow the format above.

Stable API modules, these do not require the Beta APIs experiment to be turned on. Most features are included in stable APIs, and will not break or be changed when Minecraft is updated.

  • @minecraft/server:

    • 1.18.0 (Latest version)
    • 1.17.0
    • 1.16.0
    • 1.15.0
    • 1.14.0
    • 1.13.0
    • 1.12.0
    • 1.11.0
    • 1.10.0
    • 1.9.0
    • 1.8.0
    • 1.7.0
    • 1.6.0
    • 1.5.0
    • 1.4.0
    • 1.3.0
    • 1.2.0
    • 1.1.0
    • 1.0.0
  • @minecraft/server-ui:

    • 1.3.0 (Latest version)
    • 1.2.0
    • 1.1.0
    • 1.0.0 (Requires @minecraft/server@1.2.0)

Beta API modules, requirs the Beta APIs experiment to be turned on in world settings, and add many of experimental features in the API. These APIs can be changed, removed, or added to with very little warning, and are prone to breaking. Be warned!

  • @minecraft/server:

    • 2.0.0-beta (1.21.70x only)
    • 1.18.0-beta (1.21.60x only)
    • 1.17.0-beta (1.21.50x only)
    • 1.16.0-beta (1.21.40x only)
    • 1.15.0-beta (1.21.30x only)
    • 1.14.0-beta (1.21.20x only)
  • @minecraft/server-ui:

    • 2.0.0-beta (1.21.70x)
    • 1.4.0-beta (This can be for any version between 1.21.3x to 1.21.6x)
    • 1.3.0-beta
  • @minecraft/server-gametest:

    • 1.0.0-beta
  • @minecraft/server-net:

    • 1.0.0-beta (Bedrock Dedicated Server module only, must be enabled in permission.json as it is not enabled by default)
  • @minecraft/server-admin:

    • 1.0.0-beta (Bedrock Dedicated Server module only)
  • @minecraft/debug-utilities:

    • 1.0.0-beta

In order to use the eval() function or Function() constructors within your code, you can add the following in the manifest capabilities:

BP/manifest.json
json
{
    "capabilities": ["script_eval"]
}
1
2
3

The entry point file can contain scripts and/or imports to other script files. Only one entry point file can be specified.

Writing Scripts with JS ​

Minecraft's scripting engine only runs JavaScript, like any other JavaScript projects. Check out Scripting with TypeScript for compiling TS directly to JavaScript.

BP/scripts/main.js
js
// This file demonstrates that the code is working by
// Spamming the chat with "Hello World"

// Import world & system component from "@minecraft/server", for world & game logic.
import { world, system } from "@minecraft/server";

// Create & run an interval that is called every Minecraft tick
system.runInterval(() => {
    // Spams the chat with "Hello World" with world.sendMessage function from the API
    world.sendMessage("Hello World");
}, 1);
1
2
3
4
5
6
7
8
9
10
11

Script API 2.0.0 ​

With Script API Version 2, scripts now by default execute before the world has loaded. This means that we now have to wait until the world is loaded to run most functions.

BP/scripts/main.js
js
import { world } from "@minecraft/server";

// wait until the world is loaded
world.afterEvents.worldLoad.subscribe(() => {
    // Send a message in chat
    world.sendMessage("World has loaded");

    // import other js files
    import("./path/to/file.js");
});
1
2
3
4
5
6
7
8
9
10

Reference Documentation ​

Official documentation are hosted on Microsoft Learn and can be found here:

  • @minecraft/server
  • @minecraft/server-gametest
  • @minecraft/server-ui
  • @minecraft/server-admin
  • @minecraft/server-net
  • @minecraft/debug-utilities

Official typescript declarations for the latest Beta API modules in Minecraft Preview can be found here:

  • @minecraft/server
  • @minecraft/server-gametest
  • @minecraft/server-ui
  • @minecraft/server-admin
  • @minecraft/server-net
  • @minecraft/debug-utilities

These allow for enhanced auto-completions and validation when used inside of your editor.

  • bridge. v2: Ships with GameTest support built-in.
  • Visual Studio Code: Install Node.js and npm, then run the following in command line:

Latest beta API modules:

bash
npm i @minecraft/server@2.0.0-beta.1.21.70-stable
npm i @minecraft/server-ui@2.0.0-beta.1.21.70-stable
npm i @minecraft/server-gametest@1.0.0-beta.1.21.70-stable
npm i @minecraft/server-admin@1.0.0-beta.1.21.70-stable
npm i @minecraft/server-net@1.0.0-beta.1.21.70-stable
npm i @minecraft/debug-utilities@1.0.0-beta.1.21.70-stable
1
2
3
4
5
6

Latest stable API modules:

bash
npm i @minecraft/server
npm i @minecraft/server-ui
1
2

Contributors

Edit Intro to Scripting on GitHub

Bedrock Wiki by Bedrock OSS

"Minecraft" is a trademark of Mojang AB.

Bedrock OSS, Bedrock Wiki and bedrock.dev are not affiliated in any way with Microsoft or Mojang AB.

  • Privacy Policy
  • Join our Discord
  • Learn how to Contribute
  • Visit our Repository