Minecraft Scripting API

Please note: Some examples on this page may be outdated or may not work as expected.

Hello World - Your First Add-on

A basic example to get you started with Minecraft Bedrock scripting.

What This Does

This is a minimal add-on that logs when the world initializes and greets players when they join. It demonstrates the core pattern: import modules, set up event listeners, react to events.

The pattern you'll use everywhere:

  1. Import what you need (world, system)
  2. Subscribe to events
  3. React to those events

Setup

  1. Create a behavior pack folder
  2. Add a manifest.json file
  3. Create your main script

Basic Script

import { world, system } from "@minecraft/server";

// Run once when world loads
system.run(() => {
  console.log("Add-on loaded!");  // Shows in server console
});

// Listen for player joins
world.afterEvents.playerJoin.subscribe((event) => {
  const player = event.player;
  player.sendMessage("§6Welcome to the realm!");  // Shows to player
});

Understanding imports: world is how you access server-wide events. system is for scheduling code to run at specific times.

manifest.json

{
  "format_version": 2,
  "header": {
    "description": "My First Add-on",
    "name": "Hello World",
    "uuid": "12345678-1234-5678-1234-567812345678",
    "version": [1, 0, 0],
    "min_engine_version": [1, 14, 0]
  },
  "modules": [
    {
      "description": "Scripts",
      "type": "script",
      "uuid": "87654321-4321-8765-4321-876543218765",
      "entry": "scripts/main.js",
      "version": [1, 0, 0]
    }
  ],
  "dependencies": [
    {
      "module_name": "@minecraft/server",
      "version": "1.14.0"
    }
  ]
}

What's Happening

  • Import: Load Minecraft APIs
  • system.run(): Run code once
  • afterEvents.playerJoin: Subscribe to player join event
  • player.sendMessage(): Send message to player

Next Steps

  • Add more event listeners
  • Create commands
  • Store player data
  • Add items and blocks

Testing

  1. Move your behavior pack to Minecraft
  2. Create a world with your pack enabled
  3. Open world logs to see console output (use !help to test)

This is the foundation for everything else you'll build!

Navigation