Download here:
https://lemon-slime.com/resources/scriptAPI_template.zip
Overview:
This may seem sudden, but have you heard of the “Script API”? The “Script API” is a feature in the integrated version of Minecraft that allows you to customize the game system using a programming language (Javascript). With just knowledge of Javascript, you can tweak Minecraft’s systems to a certain extent. This isn’t possible in regular games. I like this aspect of Minecraft. Below is an example of the “Script API.”

However, using the Script API requires some prior preparation. This poses a certain hurdle for beginners, and some may stumble at this preparation stage. This is a real shame.
This article aims to provide a “Script API” template so you can skip this preparation step and start writing code right away. You can download it by clicking the link above. Please feel free to use it. For details on setting up the environment, please see this article.
How to Use:
First, download the zip file above. Next, create a folder in the com.mojang folder under development_behavior_packs and copy and paste all the template files into it. The com.mojang folder is located at C:\Users\(username)\AppData\Local\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang. The “AppData” file is hidden in File Explorer, so to select it, enable hidden files in File Explorer’s View settings. Alternatively, you can open it by launching the “Run” app and entering “%LocalAppData%\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang.” Once extraction is complete, try launching Minecraft. When launching the world, check the list of behavior packs. If “ScriptAPI Template” is one of them, the installation was successful.

Writing the Script:
Now that the basic preparations are complete, all that’s left is to write your own code. Open main.js in the scripts folder in the ScriptAPI_template folder you downloaded earlier. Any text editor, such as Notepad, will do (although we recommend using a specialized text editor like VSCode). You should see something like this:
import * as server from '@minecraft/server';
//Write your script here!
The first line indicates that you’re using the minecraft/server module. This allows you to interact with the Minecraft world, so it’s essential when writing ScriptAPI. Write your script where it says “Write your script here” (this is a comment, so you can delete it or leave it in). Let’s actually write a script. Try copying and pasting the following:
server.system.runInterval(ev => {
server.world.sendMessage("Hello!");
})
The entire script looks like this. Save it and launch Minecraft.

Then, enable the “ScriptAPI Template” add-on and create a world. Can you see that “Hello!” is now displayed every tick? This is the effect of the “Script API”. This is how the “Script API” works. In a similar way, let’s create a script that triggers a command when an item is used. The template looks like this:
server.world.beforeEvents.itemUse.subscribe(ev => {
if (ev.itemStack.typeId == "minecraft:stick"){
ev.source.runCommandAsync("give @a diamond 1");
}
})
The above is an example where the command “give @a diamond 1” is triggered when a stick is used. Try arranging this to your liking to create your own original script. By the way, this article is very detailed about creating “usable items.” In addition to how to make any item usable, this article covers how to implement cooldowns, set conditions for item use, and how to implement multiple functions in a single item.

Writing Scripts:
As mentioned above, the Script API is based on JavaScript. Therefore, understanding JavaScript will make writing scripts easier. Here are some good books to help you master JavaScript.
The official documentation is also a textbook for the Script API. It’s very helpful, so it’s definitely worth a read : https://learn.microsoft.com/ja-jp/minecraft/creator/scriptapi/minecraft/server/minecraft-server?view=minecraft-bedrock-experimental
For simple scripts, you can also use the ScriptAPI generator I created below. Please feel free to use it. Using the generator, you can easily implement scripts by simply copying and pasting:

Frequently used ScriptAPI phrases are summarized below. Combining these phrases allows you to write scripts efficiently:

Customization:
Since this behavior pack is merely a template, the description and name of the add-on will indicate that it is a “template.” This is somewhat unsuitable for practical use.

To avoid this, you will need to modify the manifest.json file if you want to publish this script. The downloaded zip file should contain a file called manifest.json. This file contains the basic requirements of this add-on in JSON format, and its contents look like this:

You can change the add-on’s name and description by changing the name and description in this header, so please refer to this before publishing your script. We also recommend changing the UUID (a unique string specific to your add-on). It would be troublesome if it overlaps with other add-ons. You can automatically generate a UUID from the following external site:
https://www.uuidgenerator.netYou can also change the pack icon by overwriting pack_icon.png.
Conclusion:
This article provides a Script API template and explains basic information about the Script API and how to use it. Mastering the Script API will dramatically increase your freedom in Minecraft, so please give it a try! Questions about the Script API (including this template) are welcome in the comments section of this article or the YouTube video. Please share this article via social media link buttons, etc., as it will motivate the author.
Going deeper…
Your journey with APIScript doesn’t end here. For example, you can write scripts to display custom UIs. Below is an example.

You can also build an APIScript environment from scratch to increase scalability and flexibility. For more details, please see here:
