https://linen.dev logo
jsからオブジェクトのdatamap値変更への挑戦
# forum
r
IFTTTを活用してスクリプトからワールド内にあるオブジェクトのdatamap値を変更しようと何とかスクリプトまでは用意できたのですが最後にエラーが出てしまいうまくいきません。 下記に詳細を載せておきますので助言お願いしたいです。よろしくおねがいします。 やりたいこと ・ワールド内のオブジェクト(照明モデル)のdatamap値をIFTTTの条件を満たした場合に変更をかけたい。 プロセス ・IFTTT内にて所定の条件入力 ・オブジェクト(照明モデル)側にあらかじめ既存のdatamap値を設定しておく ・条件を満たしたときにIFTTTのjavascriptの構文にて対象オブジェクトのdatamap値を変更←ここで躓き中。。。 ・js内では特定座標を指定し所定のdatamap値へ変更したい(座標、data値ともにカスタム可能) 実際の構文
Copy code
importPackage(Packages.jp.kaiz.atsassistmod.api);

/**
 * @param {TileEntityIFTTT} tile
 * @param {EntityTrainBase} train nullが入る場合があります
 * @param {boolean} first 初回の場合trueになります
 */
function doThat(tile, train, first) {
    ControlTrain.logger("ブロック位置を更新します");

    var world = tile.getWorld(); // 修正ポイント

    // 更新対象のTileEntityの座標(例:表示器)
    var targetX = 10;
    var targetY = 64;
    var targetZ = 20;

    // DataMapに設定する新しいblockposの文字列
    var newBlockPosStr = "125 45 -299";

    // 対象のTileEntityを取得
    var tileEntity = world.getTileEntity(targetX, targetY, targetZ);
    if (tileEntity === null) {
        ControlTrain.logger("TileEntityが見つかりませんでした");
        return;
    }

    // DataMapを取得し、値を更新
    if (typeof tileEntity.getResourceState === "function") {
        var dataMap = tileEntity.getResourceState().getDataMap();
        dataMap.setString("blockpos", newBlockPosStr, 3); // 3 = 永続保存
        ControlTrain.logger("blockposを " + newBlockPosStr + " に更新しました");
    } else {
        ControlTrain.logger("対象TileEntityはResourceStateを持っていません");
    }
}
備考 ・IFTTT側のエラー情報によるとgetWorldがエラー元らしい ・TileEntityIFTTTのtile?entity?関係に原因がありそう? そのほか(開発背景的な) ・車両モデル以外のスクリプト初めてなので皆目見当もつきませんでした… ・これは照明モデルのコマブロ引用データ参照元座標をdatamapにから検索するためのものなのでこのスクリプト自体は初回限定で使用予定 ・座標ごとにデータマップを設定した照明モデルデータを座標分だけ複製しようとしたがさすがに脳筋にもほどがあるので断念 ・一度直下のコマンドブロックのにdatamap値を書いて読み込む方式も検討したが煩雑になるため断念
e
Can you like, set some in-world block (e.g. a stained glass) as signal so that the Object (i your case, some model classified as lights) setect this block and then, "oh, it's a red, I should change the signal to STOP."
r
In order for the object to monitor the contents of the command block, which constantly change depending on the state of the train, and display them appropriately, the position of the command block needs to be known in advance in the datamap, so we want to transfer the coordinates of the command block to the datamap at the initial stage of placing the block. The purpose of using datamap is to increase the versatility of a single model, and the problem is how to change the information of the Datamap that can be set in Train with an object.
4 Views