3
0

More than 3 years have passed since last update.

マイクラのScriptingAPIって何?

Posted at

はじめに

導入の方法とかは他にも書いている人がいるので、省きます
Minecraft BE ScriptingAPI 第1回講座 By @Button
MinecraftBEでscriptingAPI!part1.棒で叩いたブロックをダイヤブロックに By @mcjixif

質問形式で

Win10版じゃないと使えないってホント?

クライアント側でしかできないことをしようとすると、クライアントもWin10版である必要がありますが、サーバー側のスクリプトだけ使う場合は、ホストがWin10版であれば、参加者はどんな環境でも参加できます

Realmsって使える?

「試験的なゲームプレイで遊ぶ」をオンにする必要があるため、Realmsでは使えないようです

「試験的なゲームプレイで遊ぶ」って必要?

1.16.10の段階ではまだ必要です

nodejsなの?

違います、たぶん

非同期処理とかってどうなってるの?

setTimeoutやsetIntervalとかは基本使えません
executeCommandはコールバックがありますが、そういうのは多分稀で、基本は同期処理で書いていくことになりそうです

エラーが起きたのかどうか知りたい

こんな感じにすれば、簡単なエラーは分かる
ファイルと行数も出るよ

ServerSystem.emit = function(identifier, properties) {
    const data = this.createEventData(identifier);
    data.data = Object.assign({}, data.data, properties);

    return this.broadcastEvent(identifier, data);
}

ServerSystem.initialize = function () {
    this.emit("minecraft:script_logger_config", {
        log_errors : true,
        log_warnings : true,
        log_infomation : true,
    });
}

ログ出力したいよ

これで我慢して。(チャットに出る)

ServerSystem.log = function(...items) {
    const toString = item => {
        switch(Object.prototype.toString.call(item)) {
            case '[object Undefined]':
                return 'undefined';
            case '[object Null]':
                return 'null';
            case '[object String]':
                return `"${item}"`;
            case '[object Array]':
                const array = item.map(toString);
                return `[${array.join(', ')}]`;
            case '[object Object]':
                const object = Object.keys(item).map(key => `${key}: ${toString(item[key])}`);
                return `{${object.join(', ')}}`;
            case '[object Function]':
                return item.toString();
            default:
                return item;
        }
    }

    this.emit('minecraft:display_chat_event', {message: items.map(toString).join(' ')});
}

チェストの中とかインベントリーの中とかっていじれるの?

現状ではreadonlyなんで、コマンドでやってください

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0