How to Create a Custom UI with ScriptAPI in Minecraft Bedrock (Advanced Tutorial)

Introduction


Minecraft is a game with a huge degree of freedom. You can simply survive and defeat the Ender Dragon, master architecture and create highly artistic works, or even create maps for distribution using commands. The possibilities are truly endless.
Now, creating add-ons further increases this freedom. Not only can you create your own original items and weapons, but you can also customize the system and create distribution maps. Below is an example, which recreates the “One-Hit Sword” that appears in a certain game in Minecraft.


This add-on creation is not limited to simply creating items and modifying systems. Although it is not widely known, you can also create your own GUI. This article aims to explain how to create your own GUI from scratch and to assist you in creating add-ons.


This is a scene from a video I made, showing a GUI asking whether you prefer “Mac” or “McDo.” By reading this article, you will be able to create a GUI like this and build your own original worldview. Please read to the end.
YouTube videos
I have created a YouTube video that explains the contents of this article. You can watch it here.

Vocabulary Definitions


First, I will briefly explain the definitions of the main terms that will be frequently used in this article. These are my own interpretations, so please let me know if I am wrong. If you already know the terms, please skip ahead.

termmeaning
functionA program that produces a unique output depending on the input
GUIAn abbreviation for Graphical User Interface, which allows for intuitive and sensory operation.
ModuleElements and parts for running a program
JavaScript.A type of programming language that is primarily used on web pages

Main topic

When creating a GUI, it is necessary to use APIScript. APIScript is a feature that allows you to customize the Minecraft system using the programming language Javascript. For more information about APIScript, please see this article.

【マイクラ統合版】ScriptAPIのテンプレートを配布 – 使い方と基礎知識を解説
ダウンロードはこちら https://lemon-slime.com/resources/scriptAPI_template.zip 概要 突然ですが、皆さんは「スクリプトAPI」をご存じでしょうか? 「スクリプトAPI」とは、マインクラフトの統合版においてプログラミング言語(Javascript)を用いてゲームシステムをカスタマイズできる機能のこと。Javascriptの知識さえあれば、マインクラフトのシステムをある程度いじることができるんです。普通のゲームはそんなことできません。マインクラフトのこういうところが私は好きです。以下は「スクリプトAPI」の一例です。 ちなみに、ScriptAPIはアドオンの一部です しかし、このスクリプトAPIの使用にはある程度の事前準備が必要です。この点で、初心者には一定のハードルがあり、この事前準備の段階で躓いてしまう人も存在するものとみられます。これは非常に勿体ない。 本記事では、「スクリプトAPI」のテンプレートを配布することで、この事前準備の段階を飛ばし、すぐにコードを書き始められるようにすることを目的としています。ダウンロードは上のリンクをクリックすることで可能です。ご自由にお使いください。 一応、環境構築についてはこちらの記事で詳しく説明しています 使い方 まず、上記のzipファイルをダウンロードします、。その後、com.mojangフォルダ内のdevelopment_behavior_packs内に適当なフォルダー作成し、その中にテンプレートのファイルをすべてコピーアンドペーストしてください。フォルダcom.mojangは C:\Users\(ユーザー名)\AppData\Local\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang に存在します。エクスプローラー上で、「AppData」というファイルは隠しファイルなので、これを選択するためには、エクスプローラーの「表示」設定から隠しファイルのチェックをオンにしてください。または、「ファイル名を指定して実行」というアプリを起動し、「%LocalAppData%\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang」と入力することでも開けます。 展開が完了したら、マインクラフトを起動してみてください。ワールド起動時に、ビヘイビアパックの一覧を確認してみてください。その一つに「ScriptAPIのテンプレート」があれば成功です。 Youtube動画もあります 本記事の内容について詳細に解説したYoutube動画を作成しました。こちらも併せてご覧いただくと、APIスクリプトに関してより理解が深まります。 https://youtu.be/331LmvE2Cdk 動画内でいくつかスクリプトが登場しますが、以下にその内容を記載しておりますので、コピー&ペーストしてご利用ください。 スクリプトを記述 さて、基本的な準備は整いました。あとは、オリジナルのコードを書いていくだけです。 先ほどダウンロードしたScriptAPI_templateフォルダ内のscriptsフォルダ内にある、main.jsを開きましょう。メモ帳などのテキストエディタであれば大丈夫です(VSCodeなどの専門のテキストエディタがあるならそれを使うことをお勧めします)。 すると、おそらくこのように表示されることでしょう。 import * as server from '@minecraft/server'; //ここにスクリプトを記述 コピー Copied! 最初の1行目は、「minecraft/serverモジュールを使用する」ことを表しています。これによってマインクラフトの世界に干渉できるようになるので、ScriptAPIの記述においてこれは必須です。 「ここにスクリプトを記述」とあるところにスクリプトを実際に書いていきます(これはコメントなので消しても残してもどちらでも良いです)。実際に、スクリプトを書いてみましょう。試しに以下をコピー&ペーストしてみてください。 server.system.runInterval(ev => { server.world.sendMessage("Hello!"); }) コピー Copied! スクリプト全体は以下のようになります。 これを保存し、マインクラフトを起動しましょう。そして、「ScriptAPIのテンプレート」アドオンを有効化し、ワールドを作成します。すると、毎ティック「Hello!」と表示されるようになったのが分かるでしょうか?これが「スクリプトAPI」の効果です。 このようにして「スクリプトAPI」は動作します。 同様にして、「アイテムを使ったらコマンドが発動するスクリプト」を作ってみましょう。テンプレートはこんな感じです。 server.world.beforeEvents.itemUse.subscribe(ev => { if (ev.itemStack.typeId ==…

In this article, we will first explain how to set up the APIScript environment. If you already know how, please skip this section.

Environment Construction


First, we will show you what you need to build the environment. You can download each item from the links below.

Name of the software you needDownload locationremarks
MinecraftamazonIt goes without saying that this is a well-known game software. The Win10 version is preferable.
vscodehttps://code.visualstudio.com/A text editor specialized for writing code (free). Not necessary if you already have another text editor.
node.jshttps://nodejs.org/A free tool for running javascript on your computer. After downloading, run the msi file.


Of the required software, only Minecraft is paid; the rest are free. A text editor (vscode) is not required, but it is highly recommended. Also, since the ScriptAPI relies on JavaScript, node.js is required to run this JavaScript on your PC.
Regarding node.js, I found this article by another person to be very helpful, so I’d like to introduce it to you.
https://qiita.com/non_cal/items/a8fee0b7ad96e67713eb
The following procedure assumes that these are installed.
First, go to development_behavior_packs in the com.mojang folder and create a new folder (you can name it anything you like). This will be the working folder for your add-on. The location of the com.mojang folder is explained below. If you already know it, you can skip this part.

com.mojang location


The folder com.mojang is
C:\Users\(username)\AppData\Local\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang
It is located in the following location: The “AppData” file is hidden in File Explorer, so to select it, you must 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“.
Inside this com.mojang folder there is a development_behavior_packs folder, so open it and create a new folder.

Creating manifest.json


Next, go to the newly created add-on folder and create a new json file called “manifest.json”. Right-click and select “New” -> “Text Document”, then change the name of the created file to “manifest.json”.
“manifest.json” is a file that describes the add-on’s details (such as its name and ID), allowing Minecraft to recognize the add-on.
The contents of manifest.json are as follows. Open the created manifest.json using vscode or similar that you downloaded earlier, and copy and paste the following.

{
"format_version": 2,
"header": {
"name": "Addon that displays a GUI",
"description": "This is a template",
"uuid": "b1ef9620-a18e-4fa3-bdca-f5f1d3c71c31",
"version": [0, 1, 0],
"min_engine_version": [1, 20, 0]
},
"modules": [
{
"type": "script",
"language": "javascript",
"uuid": "b1ef9620-a18e-4fa3-bdca-f5f1d3c71c32",
"entry": "scripts/main.js",
"version": [0, 1, 0]
}
],
"capabilities": ["script_eval"],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.10.0"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.1.0"
}
]
}
Copied!


The name and description above are the name and description of this add-on. Please adjust these parts as you like. Also, the two uuids are strings unique to the add-on, and overlapping them can be troublesome, so we recommend using the generator below to generate and change them.
https://www.uuidgenerator.net
The version of minecraft/server is (1.10.0 in this case), but you may want to change it by referring to the following page. At the time of writing, the latest version is 1.14.0-beta, but the beta version is unstable, so if you want stability, you may want to use 1.13.0. Note that when using the beta version, you will need to enable the experimental feature “Beta API” when launching the world (this is not necessary if you are not using the beta version).
https://learn.microsoft.com/ja-jp/minecraft/creator/scriptapi/minecraft/server/minecraft-server?view=minecraft-bedrock-experimental
Also, since this add-on displays the UI, it is necessary to specify the server-ui module. Please note that this add-on is different from the other add-ons introduced on this site so far.

Installing “@minecraft/server”


Next, install the “@minecraft/server” module that will be used in this add-on and “@minecraft/server-ui”, which is required to display the UI. Enter “cmd” in the search field on the taskbar to launch the command prompt, or launch the vscode terminal. Then,

cd (path of working folder)


Enter the command. The cd command allows you to move to a directory by specifying the directory. For example, if the add-on folder (the folder containing manifest.json) is
C:\Users\User\AppData\Local\packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang\development_behavior_packs\test_pack
If it was,

cd C:\Users\User\AppData\Local\packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang\development_behavior_packs\test_pack


The folder location (especially the user name) will be different for each user, so please check the path yourself. You can check it in the top column of File Explorer.


Once you have completed the above command, enter the following two commands.

npm install @minecraft/server
npm install @minecraft/server-ui


If an error occurs regarding the command “npm”, the installation of node.js may not have been completed. If an error occurs, we recommend checking this point.

Write a script


Once you’ve completed the above steps, you’re ready to start creating the UI.
Create a folder called “scripts” in the add-on folder. Then create a JavaScript file called “main.js” inside it. This is where you will write your script. This js file can be opened with a text editor such as vscode.

Calling a Module


First, we will call the two modules we installed earlier in this script. This will allow us to interact with the Minecraft world and prepare the UI for display.
Copy and paste the following into main.js:

import * as server from "@minecraft/server";
import * as ui from "@minecraft/server-ui";


The “*” symbol in this script indicates that all of the modules will be installed. You can install what you need for each class (player, world, etc.), but I thought that would be a bit cumbersome and time-consuming, so I installed everything. This is up to you. For reference, the following is an example of installing only the world class and system class modules from @minecraft/server. (This does not need to be written in the script.)

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

Defining the UI


Next, define the UI to be displayed. Below is an example of defining show_form(), a function that displays the UI with the player as an argument.

function show_form(player){
const form = new ui.ActionFormData();
form.title("Selection Menu: Which do you prefer?");
form.button("Mac");
form.button("McDo");
form.show(player).then((response) => {
switch(response.selection){
case 0:
player.sendMessage("You selected Mac.");
player.runCommandAsync("give @s emerald 1");
break;
case 1:
player.sendMessage("You selected McDonald's.");
break;
default:
player.sendMessage("Nothing selected.");
break;
}
}).catch(error =>
player.sendMessage("An error occurred: " + error.message)
);
}
Copied!


Let me explain a bit. form.title() is a function that defines the title of this UI. You can arrange it by entering a title here. Also, a button is placed using the button() function of the form class. This takes a string as an argument and places the argument string on the button. As you can see, it is possible to place multiple buttons.
The final show() function makes it possible to display this UI. You can also define the behavior when buttons are pressed under show(), and here we define the behavior when each button is pressed. At the same time, we use the “sendMessage()” function, which displays a message, and the “runCommandAsync()” function, which executes a command. These are commonly used, so it’s worth remembering.

reference


You will see the notations “case 0” and “case 1”, which are called switch statements and are often used in JavaScript to distinguish between cases. Here, the behavior is distinguished depending on the value of the variable response. The value of response becomes 0 when the top button is pressed, becomes 1 when the next button is pressed, and so on. If nothing is pressed, “default” is assigned.
You can also set the behavior when an error occurs. This is called catch(), and is often used in JavaScript. This setting is not required.
Now, you might think that this is the end, but it’s not. This just defines the function that displays the UI, but does not actually issue a command to display the UI. Separately, you need to issue a command to execute the defined function and display the UI.

Displaying the UI


The UI will be displayed when you call the “show_form()” function defined above, but simply displaying it is not enough. It would be very distracting if the UI was always displayed in the game. In other words, we need to implement a system that displays the UI under certain conditions.
Below is an example of calling show_form() to display the UI when using a wooden stick.

server.world.afterEvents.itemUse.subscribe(ev => {
    if (ev.itemStack.typeId == "minecraft:stick"){
        let player = ev.source;
        show_form(player);
    }
});


One thing to note: This function show_form requires the specification of a “player” as an argument, so the item’s user is declared in advance as the “player” variable. Please note that you must prepare the “player” argument somehow. The function will be executed starting from this “player”.
For more information on how to cause certain actions to occur when using items, please see this article.

How to Create Custom Right-Click Actions for Any Item in Minecraft Bedrock (Script API Tutorial)

Note that we are using the afterEvents property here to trigger the use of the item, but using the beforeEvents property here will result in an error, as mentioned in this article.
【ScriptAPI】UIの表示でエラーが出たときの対処法【マイクラ統合版】
【ScriptAPI】UIの表示でエラーが出たときの対処法【マイクラ統合版】
はじめに ScriptAPIでUIを表示できるのは周知のとおりですが、時としてこのようなエラーメッセージが表示されることがあります。 Native function [ActionFormData::] does not have required privileges 本記事では、このエラーに対する対処法を提示します。 UI表示方法 そもそもですが、UIの表示方法に関してはこちらが詳しいです。この記事をご覧になることで、オリジナルのUIを持ったアドオンを制作することが可能になります。 https://lemon-slime.com/?p=1299 対処法 uiを表示する関数を呼び出す過程で、berforeEventsを使っていませんか?beforeEventsではなく、afterEventsを用いることで問題は解決します。以下は、有効(エラーの出ない)なAPIScriptの例です。 import * as server from '@minecraft/server'; import * as ui from '@minecraft/server-ui'; //ここにスクリプトを記述 function show_form(player){ const form = new ui.ActionFormData(); form.title("Test GUI"); form.button("Test Button"); form.button("Test Button 2"); form.show(player).then((response) => { switch(response.selection){ case 0: player.sendMessage("You…

execution


This completes the definition of the UI in the script. All that’s left is to actually start Minecraft and check its behavior. Enable this add-on and start a world. The UI should then be displayed when you use the stick.


Also, in this example, choosing “Mac” will give you an emerald, so you can see that there are consequences depending on your choices.

ModalFormData


Now, there is a useful function for displaying UI. This is called ModalFormData, and it allows you to place not only buttons, but also text boxes and check boxes. This allows you to create add-ons that are extremely flexible and extensible.


The image above is a frame from a video I created, and you can see that there are various input fields, such as sliders and dropdowns.

YouTube videos


For details on how to create such a form, please see this video.


This is just a simple introduction to the script.

script


Here are some examples of how you can use ModalFormData to implement various functions:

function show_form(player){
const form = new ui.ModalFormData();
form.slider("Slider",0,100,1,50);
form.textField("Enter text here","Text");
form.dropdown("dropdown",["a","b","c"]);
form.toggle("checkbox");
form.show(player).then(response => {
if (response.canceled){
player.sendMessage("Cancelled");
return;
}
player.sendMessage("Slider value: " + String(response.formValues[0]));
player.sendMessage("Enter text: " + String(response.formValues[1]));
player.sendMessage("Dropdown selection: " + String(response.formValues[2]));
player.sendMessage("Checkbox state: " + String(response.formValues[3]));
})
.catch(error => {
player.sendMessage("Error: " + error.message);
});
}
Copied!


The script is slightly different from the one in the video, but the general framework is the same. Here, we’ve only defined a simple system that uses the sendMessage function to convert input data into a String type and then output it, but in reality, you’ll probably want to perform more flexible processing by combining it with functions like runCommand, as shown below.

Example 1


Here’s an example that will award diamonds to the player depending on the slider value:

player.runCommand("give @s diamond " + String(response.formValues[0]));


You can also set a player’s score to a fixed value in the same way:

player.runCommand("scoreboard players set @s test_score " + String(response.formValues[0]));

Example 2


A common question in the comments section of the video above was, “How do I display the player’s name in a dropdown?” Here’s an example function that implements that:

form.dropdown("Dropdown",generate_player_list());


After defining this function, you can use it in a dropdown function to define a dropdown with player names, like this:

let players = server.world.getAllPlayers();
for (let i = 0; i<= players.length; i++){
    if (response.formValues[2] == i){
         player.sendMessage("Selected Player: " + players[i].name);
    }
}

Learning


As mentioned above, the creation of UI and ScriptAPI is based on Javascript. Therefore, understanding Javascript syntax and functions will make writing scripts easier. Here are some good books to help you master Javascript.

created by Rinker
¥3,278 (2025/10/18 11:17:17時点 楽天市場調べ-詳細)

The official documentation is a textbook on the scripting API. It is very helpful, so it's definitely worth taking a look at (note that it's only available in English).
https://learn.microsoft.com/ja-jp/minecraft/creator/scriptapi/minecraft/server/minecraft-server?view=minecraft-bedrock-experimental
The end
In this article, we explained how to display a UI in Minecraft using APIScript. Being able to display a UI greatly increases the extensibility and flexibility of add-ons, so please give it a try.
For more information on the basics of add-ons, see this article.
【初心者向け】オリジナルアドオンとアイテムの作り方【マイクラ統合版】
【初心者向け】オリジナルアドオンとアイテムの作り方【マイクラ統合版】
はじめに タイトルの通り、本記事ではマインクラフトの統合版でオリジナルのアイテムやアドオンを制作する方法について解説します。例えば、こんな感じ↓ ちょっと見切れていますが、この映像は、左の画像が、私の制作したブロック「魔法作業台」を作業台で制作している1コマで、右の画像が自作の剣を追加したものです。 自分独自の世界観が作れます! この記事&動画を見ることで、マイクラ統合版でこうした自作アイテムを作れるようになることを目指します。 まずはこちらの動画をご視聴ください。以前私がYoutubeに投稿したものですが、ゆっくり解説なので見やすいかと思います。 https://youtu.be/WDeWnP5THSQ ちなみに、動画内で「概要欄に記載」と言っていますが、概要欄ではなく以下に記述します。 オリジナルアイテムの制作にあたっては、後述しますが「アドオン」というものを作成する必要があります。まずはアドオンの制作環境を整えましょう! 最低でもMinecraft(PC版)が必要です マインクラフトのパス アドオンを制作するにあたって、まずは作業フォルダを開く必要があります フォルダの場所を変更していない場合、マインクラフト(統合版)のフォルダの場所は以下の通り。C:\Users\(ユーザー名)\AppData\Local\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojangエクスプローラー上で、「AppData」というファイルは隠しファイルです。これを選択するには、エクスプローラーの「表示」設定から隠しファイルのチェックをオンにする必要があります。 または、「ファイル名を指定して実行」というアプリを起動し、「%LocalAppData%\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang」と入力することでも開くことができます。 Windows10の場合、「ファイル名を指定して実行」というアプリは、タスクバーにある「ここに入力して検索」と記された検索ボックスに、「ファイル名を指定して実行」と入力することで起動できます。 まずは、準備としてこのマインクラフト(統合版)のフォルダを開きましょう。 ここがアドオンの作業フォルダです オリジナルのアイテムの制作方法 詳細については上記の動画をご覧いただくことを前提として、本稿では簡単にオリジナルのアイテムの制作方法を解説します。 そもそもですが、オリジナルのアイテムの制作にあたっては「アドオン」の制作が必須です。 アドオンとは何か? アドオンというのは、簡単に言うと既存のソフトウェア(ここではマインクラフト)に新しく機能を追加するソフトウェアのことです。アドオンを使用することで、例えばマーケットプレイスにあるようにオリジナルアイテムを制作したりカスタムエンティティやバイオーム、さらにはコマンドやエンチャントまで制作したりすることが可能になります! ゲームそのものを大きく改変するもの、それがアドオンです このアドオンは、大きく分けて「ビヘイビアパック」と「リソースパック」で構成されます。前者はアイテムの挙動などを、そして後者は見た目の部分をそれぞれ定義します。 ビヘイビアパック;アイテムの動作や挙動を定義 リソースパック;アイテムの見た目を定義 まずはこの2つを制作していきましょう。 [注]2024年8月16日追記: 実験的な機能「ホリデークリエイターの特徴」が14日未明のアップデートにより削除されたため、アドオン制作方法が若干変更になっています。 https://lemon-slime.com/?p=1024 また、ver1.21.10後のアドオン制作の方法や変更点についてはこちらの記事でまとめております。ただ、本ページの情報も当該アップデートに対応しておりますのでご安心ください。 リソースパックの制作 まずは、上記にあるマインクラフトのフォルダ(com.mojang)を開き、development_resource_packs を開きます。そして、development_resource_packs直下にフォルダを新規作成(名前はお好みで決定)し、その中にリソースパック用のmanifest.jsonを作成・配置します。内容は以下: (後述しますが、uuidは変更することをお勧めします) { "format_version": 1, "header": { "description": "サンプルのリソースパック", "name": "サンプルリソースパック", "uuid": "adfbd316-3164-409f-a89c-d31466588931", "version": [1, 0, 0],…

You can also find more information about commonly used APIScript phrases here.
【Minecraft統合版】よく使うAPI Scriptのフレーズ 5選
【Minecraft統合版】よく使うAPI Scriptのフレーズ 5選
はじめに みなさん、こんにちは!突然ですが、「API Script」をご存じでしょうか? 「API Script」というのは、マインクラフトの統合版において、プログラミング言語(Javascript)を用いてゲームシステムをカスタマイズできる機能のこと。Javascriptの知識さえあれば、マインクラフトのシステムをある程度いじることができるんです。普通のゲームはそんなことできません。マインクラフトのこういうところが私は好きです。 これは、APIスクリプト(ScriptAPI)の一例で、「ジャンプしたらkillコマンドが発動する」ことを意味しています。このようにしてゲームシステムに直接干渉するわけですね。 さて、本稿では、この「API Script」を使ったアドオンの制作において、ある程度よく用いられるフレーズを備忘録もかねて5つまとめてみたいと思います。あくまで「経験上」よく使われるか否かが論点であり、主観が多分に含まれていることに予めご了承ください。 個人的によく使うものをまとめてみました APIスクリプトの基本 本記事ではAPIスクリプトの基本事項については触れません。APIスクリプトの概要や基本事項、事前準備などについてはこちらの記事で詳細にまとめております。APIスクリプトの基本的な情報を知りたい方はまずこちらの記事を参照し、後で本記事に戻ることをお勧めします。 https://lemon-slime.com/?p=1210 以下では、APIスクリプトの基本を理解なさっていて、事前準備が完了していることを前提にお話しします。 本題 それでは、APIスクリプトの記述においてよく使われるフレーズをまとめます。 import文 API Scriptはimport文から始まります。これがなければただのjsファイルです。具体的には: import * as server from '@minecraft/server'; コピー のように記述し、これによって、マインクラフトの世界に干渉できるようになります。今のは一例で、人によっては、 from '@minecraft/server' import {world,system}; コピー のように書くこともあるらしいですね。好みが別れるところです。 言うまでもないですが、ここで同時に変数の宣言を行っています。以下で「server」という変数が突拍子もなく出てきますが、ここで宣言されたものです。 毎ティック実行 コマンドブロックに「常時実行」というモードがありますよね。これと同じように、常時プログラムを動かしたいときに重宝する関数があります。 server.system.runInterval(() => { //ここに内容を記述 }); コピー それがsystemクラスのrunInterval()です。これは、関数と間隔(int)を引数とすることで、名前の通り、一定周期で関数を実行することができます。上のように間隔を明記しない場合は常に実行します。常にプレイヤーの動きを監視するのにも使えます。ジャンプしたらkillされるAPI Script: にもこの関数が使われていますね。ちなみに、「常時実行」と言えば、functionsファイル内のtick.jsonを想起させます。ご存じのない方に向けて一応説明しますと、tick.jsonはワールド内で常時実行される関数スクリプト(一連のコマンド群で、mcfunction形式で記述されたもの)を定義します。このtick.jsonを用いることでも簡単に常時実行を達成することはできますが、こちらはあらかじめ定義されたコマンドしか使えないので一長一短です。必要に応じてrunInterval()とtick.jsonを使い分ける感じですね。 各プレイヤーについて実行 マインクラフトの主人公は、プレイヤーです。このプレイヤーを主体として何かを実行したいときもありますよね。そんな時に重宝するフレーズがあります。 for (const player of…

Next article:
【革命】オリジナルのコマンドを作る方法を徹底解説 – ScriptAPIでアドオン制作【マイクラ統合版】
【革命】オリジナルのコマンドを作る方法を徹底解説 – ScriptAPIでアドオン制作【マイクラ統合版】
はじめに マインクラフトには、「コマンド」と呼ばれる機能が存在します。コマンドとは、ゲーム内で特定のテキストをチャット欄に打ち込むことで、ゲームを制御できる機能のことを指します。一般的にはチャットウィンドウを表示し、スラッシュから始まる一連の文字列を打ち込むことでコマンドは発動します。あるいは、コマンドプロンプトや各種アドオンの.mcfunctionファイルによって実行することもできます。コマンドは大変便利なもので、マインクラフトのプレイヤーなら一度は触ったことはあるのではないでしょうか? これは、コマンドの一例で、giveコマンドと呼ばれるものです。このようにマインクラフトには多種多様なコマンドが予め用意されていて、それぞれのコマンドに合わせて正しい構文を入力することによって、ゲームをスクリプト上で改変することができます。 コマンドについての詳細はMinecraft Wikiが詳しいです。 コマンドの欠点 このようにコマンドは大変便利なものである一方で、欠点もあります。それは、予め定義されているコマンドしか使えないということです。勿論、デフォルトで定義されているコマンドは非常に多いので、これが問題になることはあまりないのですが、ちょっと凝ったことをしようとするとこれが問題になり得ます。できることなら、自分でコマンドを作って自由度を上げたいものです。本稿では、ScriptAPIを用いてコマンドを自作する方法について一から徹底解説します。 本ページについて 本ページの前半では、ScriptAPIを使用する上での環境構築について言及したうえで、後半ではコマンドを自作する方法について解説します。既に環境構築についてご存じの場合は、この節を飛ばしてください。以下の目次をクリックすることでジャンプできます。 目次 環境構築 用語の定義 必要なソフト 手順 コマンドを自作 コンセプト 基本編1 基本編2 応用編1 応用編2 問題点 おしまい また、本記事について解説したYoutube動画を作成しました。こちらより視聴できます。 https://youtu.be/Fuae6QiaXG8 環境構築 そもそも、ScriptAPIとはマインクラフトの統合版において、プログラミング言語(Javascript)を用いてゲームシステムをカスタマイズできる機能のことを指します。Javascriptの知識さえあれば、マインクラフトのシステムをある程度いじることができるんです。ScriptAPIに関する詳細についてはこちらの記事が詳しいです: https://lemon-slime.com/?p=1254 さて、このページではScriptAPIを使用する上での環境構築を行っていくわけですが、まずは必要となる用語の説明から入ります。 用語の定義 これらが私が独自の解釈によって説明したものですので、もし間違っている場合にはご指摘ください。 用語 意味 関数 ある入力に応じて一意の出力を行うプログラム モジュール プログラムを動作させるための要素・部品 JavaScript プログラミング言語の一種で、主にWebページ上で用いられる 必要なソフト まず、環境構築にあたって必要なものを提示します。以下のリンクよりそれぞれをダウンロードできます。 必要なソフト名 ダウンロード先 備考 Minecraft amazon 言わずと知れたゲームソフト。Win10版が望ましい。 vscode https://code.visualstudio.com/ コードの記述に特化したテキストエディタ(無料)。既に別のテキストエディタを持っている場合は不要。 node.js…

最新情報をチェックしよう!