0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

mobの性質を書き換えるビヘイビアーパックの考え方【統合版マイクラ】

Last updated at Posted at 2025-12-07

ウーパールーパー(以下ウパと表記)を染料で染められるようにするアドオン「ウパ染め」を作成しながら、ビヘイビアーパックの作り方を紹介します。

ウパ染め.png

追加したい「性質」に対して、似たような「性質」をもつmobの定義ファイルを参考に、ファイルを書き換えてビヘイビアーパックを組み立てていきます。

本記事は統合版マインクラフトで動作確認を行っています。
Minecraft for Windows 1.21.124

用語解説

mob

mobはMobileの短縮形で「動くもの」という意味です。ウシや羊といった動物、ゾンビやクリーパーといったモンスターが対象です。動きをもつ、生き物のことをさします。

entity

entityはマイクラの世界における「動きをもつ」ものすべてをさします。mobもentityの一種です。ほかに、トロッコやボート、発射された矢や、エンドクリスタルが対象です。

本記事では、entityの中でも生き物であるmobに注目して、ビヘイビアーパックの作り方を紹介します。

アドオンの機能を調べる

バニラ(デフォルト)のビヘイビアーパックをダウンロードし、mob の性質を定義するファイルを確認します。

bedrock-samples-1.21.120.4\behavior_pack\entitiesに、マイクラに存在するmobの設定ファイルがあります。ファイル名はコマンドでそのmobを召喚するときの名称とだいたい同じです。

entitiesファイルの構造

entitiesにはjson形式で各mobの定義が書かれています。大枠を抜粋したものが次の通りです。

{
  "format_version": "1.21.90",
  "minecraft:entity": {
    "description": {},
    "component_groups": {},
    "components": {},
    "events": {}
  }
}

各項目について解説します。

  • description
    コマンドで召喚するときのidなどを定義しています。

  • components
    そのmobの不変の性質を定義しています。大きさや体力、攻撃力など。

  • component_groups
    そのmobの変化する性質を定義しています。子どものときの大きさ、大人だけの振る舞いなど。主にeventsから呼ばれます。

  • events
    component_groupsで定義した性質を追加したり、削除する処理が定義されています。子どもが成長する、大人になるなど。主にcomponentsから呼ばれます。

ウパ色のしくみ

ウパ色を変えるにあたって、まず、どのような仕組みで色が決まっているか調べます。ウパファイルを確認します。

component_groupsに各ウパ色を定義しているオブジェクトがありました。minecraft:variantの値によって、ウパ色が変わるようです。

"axolotl_lucy": {
  "minecraft:variant": { "value": 0 }
},
"axolotl_cyan": {
  "minecraft:variant": { "value": 1 }
},
"axolotl_gold": {
  "minecraft:variant": { "value": 2 }
},
"axolotl_wild": {
  "minecraft:variant": { "value": 3 }
},
"axolotl_blue": {
  "minecraft:variant": { "value": 4 }
},

ウパはリューシ(ピンク)、ワイルド(茶色)、金色(黄色)、水色、青色の5色存在します。

ちなみにリューシはリューシスティック(Leucistic)の略で、白変種という色素が薄くなった個体のことです。アルビノとは異なります。

色が決定するタイミングは、eventsのスポーンイベントです。ランダムにコンポーネントが選択され、色が決まっています。

"minecraft:entity_spawned": {
  "sequence": [
    {
      "add": {
        "component_groups": [
          "axolotl_adult",
          "axolotl_in_water"
        ]
      }
    },
    {
      "randomize": [
        {
          "weight": 25,
          "add": {
            "component_groups": [ "axolotl_cyan" ]
          }
        },
        {
          "weight": 25,
          "add": {
            "component_groups": [ "axolotl_gold" ]
          }
        },
        {
          "weight": 25,
          "add": {
            "component_groups": [ "axolotl_lucy" ]
          }
        },
        {
          "weight": 25,
          "add": {
            "component_groups": [ "axolotl_wild" ]
          }
        }
      ]
    }
  ]
}

青ウパは自然スポーンしないのでminecraft:entity_spawnedには記載がありません。繁殖で生まれるときに、青色になる可能性があります。

"minecraft:entity_born": {
  "sequence": [
    {
      "remove": {
        "component_groups": [
          "axolotl_adult"
        ]
      },
      "add": {
        "component_groups": [
          "axolotl_baby",
          "axolotl_in_water"
        ]
      }
    },
    {
      "filters": {
        "test": "has_component",
        "operator": "!=",
        "value": "minecraft:variant"
      },
      "add": { "component_groups": [ "axolotl_blue" ] }
    }
  ]
},

以上の内容よりcomponent_groupsで定義されたaxolotl_lucyaxolotl_cyanaxolotl_goldaxolotl_wildaxolotl_blueのいずれかをeventでaddすることで、色を変更できることが分かりました。

シュルカー染めのしくみ

染料を使用した色変えができるmobとして、シュルカーがあげられます。クリエイティブモード時に限り、シュルカーに対して直接染料を使うと、殻の色が変えられます。1.21.124 現在、統合版限定の仕様です。ウパを染料で染めるにあたって、シュルカー染めのしくみが参考になりそうです。

なお染料で染められるmobとして、羊もいますが専用システムで管理されているようで仕組みは不明です。おそらくハードコーディングされています。ゲーミング羊もビヘイビアーパックからは確認できません。

シュルカーもウパ同様に、component_groupsに各色の定義されています。minecraft:variantの値によって色が変わるのも同じしくみです。

"minecraft:shulker_purple": {
  "minecraft:variant": {
    "value": 5
  }
},
"minecraft:shulker_black": {
  "minecraft:variant": {
    "value": 0
  }
},
"minecraft:shulker_blue": {
  "minecraft:variant": {
    "value": 4
  }
},

eventsには、それぞれの色ごとに色変えイベントが用意されています。

"minecraft:turn_purple": {
  "add": {
    "component_groups": [
      "minecraft:shulker_purple"
    ]
  }
},
"minecraft:turn_black": {
  "add": {
    "component_groups": [
      "minecraft:shulker_black"
    ]
  }
},
"minecraft:turn_blue": {
  "add": {
    "component_groups": [
      "minecraft:shulker_blue"
    ]
  }
}

componentsには色を変えるイベントを呼び出すminecraft:interactが定義されています。

"minecraft:interact": {
  "interactions": [
    {
      "on_interact": {
        "filters": {
            "all_of": [
              {
                "any_of": [
                  {
                    "test": "has_equipment",
                    "subject": "other",
                    "domain":"hand",
                    "value": "dye:0"
                  },
                  {
                    "test": "has_equipment",
                    "subject": "other",
                    "domain":"hand",
                    "value": "dye:16"
                  }
                ]
              },
              {
                "test": "is_family",
                "subject": "other",
                "value": "player"
              },
              {
                "test": "has_ability",
                "subject":"other",
                "value": "instabuild"
              }
            ]
        },
        "event": "minecraft:turn_black"
      },
      "use_item": true
    },
    {
            "on_interact": {
              "filters": {
                  "all_of": [
                    {
                      "test": "has_equipment",
                      "subject": "other",
                      "domain": "hand",
                      "value": "dye:7"
                    },
                    { 
                      "test": "is_family", 
                      "subject": "other", 
                      "value": "player" 
                    },
                    { 
                      "test": "has_ability",
                      "subject": "other", 
                      "value": "instabuild" 
                    }
                  ]
              },
              "event": "minecraft:turn_silver"
            },
            "use_item": true
          },
          {
          // 色ごとの定義が続く

filtersの値が、all_ofと、配下にany_ofを含む2つのパターンがあります。染料(dye)が2種類使えるものは、どっちでもよいようにany_of、染料が1種類固定のものはall_ofになっているようです。

オブジェクトごとに分解してみていきます。

手に持っている染料の識別

{
  "test": "has_equipment",
  "subject": "other",
  "domain": "hand",
  "value": "dye:7"
}

プレイヤーか確認

{ 
  "test": "is_family", 
  "subject": "other", 
  "value": "player" 
},

インスタントビルド、つまりクリエイティブモードかどうかの判定

{ 
  "test": "has_ability",
  "subject": "other", 
  "value": "instabuild" 
}

色変えイベントの呼び出し

"event": "minecraft:turn_black"

アイテムの消費

"use_item": true

この処理をウパに移植すれば、染料での色変えが作れそうです。

ボートアクションヒントのしくみ

シュルカー色変えシステムを移植すれば、染料を使うことができそうです。しかし、元のウパ色を確認していないため、染料を無駄に消費してしまう可能性があります。シュルカー染めはクリエイティブモードの時しか動作しないため、アイテム消費の心配がない。

そこでボートの処理を参考にします。
https://github.com/Mojang/bedrock-samples/blob/v1.21.120.4/behavior_pack/entities/boat.json

ボートに乗った時、木製のボートと竹のイカダで乗れる位置が若干異なります。variantを比較して、ボートとイカダか判定しています。

{
  "test": "is_variant", "subject": "self", "operator": "!=", "value": 7
},

7(竹のイカダ)以外のときテストに合格する例です。このしくみを利用して、染料と同じ色のウパには使えないようにします。

ビヘイビアーパック作成

シュルカーやボートのファイルを参考に、ウパ染めビヘイビアーパックを作成します。

ファイル構成

ビヘイビアーパック用のフォルダを作成します。マイクラに読み込まれるように、次の場所に作成します。

development_behavior_packs
%APPDATA%\Minecraft Bedrock\Users\Shared\games\com.mojang\development_behavior_packs

作成したフォルダの内部は次のような構造になります。

ファイル構成
ウパ染め
│  manifest.json          ← ビヘイビアーパックの定義ファイル
└─entities
        axolotl.json      ← ウーパールーパーの定義ファイル

axolotl.jsonbedrock-samplesからコピーしたものをベースに改造していきます。

manifest.json

ビヘイビアーパックの定義ファイルです。マイクラ内に表示される名前や説明文を記載します。

{
  "format_version": 2,
  "header": {
    "description": "染料を使ってウーパールーパーの色を変えよう",
    "name": "ウパ染め",
    "uuid": "77806ef7-3484-42d7-8a75-f60d4157bf21",
    "version": [1, 0, 0],
    "min_engine_version": [1, 21, 120]
  },
  "modules": [
    {
      "type": "data",
      "uuid": "f164cc00-c068-44b2-8b67-88fb069ad5a3",
      "version": [1, 0, 0]
    }
  ]
}

名前nameと説明descriptionを逆に記載すると、逆に表示されます(1敗)。

イベントの追加

シュルカーの色変えイベントを、ウーパールーパーに移植します。
axolotl.jsonevents要素に追加します。

"minecraft:turn_pink": {
  "add": {
    "component_groups": [
      "axolotl_lucy"
    ]
  }
},
"minecraft:turn_cyan": {
  "add": {
    "component_groups": [
      "axolotl_cyan"
    ]
  }
},
"minecraft:turn_yellow": {
  "add": {
    "component_groups": [
      "axolotl_gold"
    ]
  }
},
"minecraft:turn_brown": {
  "add": {
    "component_groups": [
      "axolotl_wild"
    ]
  }
},
"minecraft:turn_blue": {
  "add": {
    "component_groups": [
      "axolotl_blue"
    ]
  }
},

ウパ色に合わせてイベントを作成します。

コンポーネントの追加

minecraft:interactコンポーネントをシュルカーから移植します。サバイバルでも利用できるようにinstabuildの判定処理を削ります。同じ色の染料を使っても消費しないように、variantが変わらない場合は変更しないように条件を追加します。

axolotl.jsoncomponentsに追加します。染料はいつでも使える不変の性質にしたいのでcomponentsに追加します。component_groupsではありません。

"minecraft:interact": {
  "interactions": [
    {
      "on_interact": {
        "filters": {
            "all_of": [
              { "test": "has_equipment", "subject": "other", "domain": "hand", "value": "dye:9" },
              { "test": "is_family", "subject": "other", "value": "player" },
              { "test": "is_variant", "subject": "self", "operator": "!=", "value": 0 }
            ]
        },
        "event": "minecraft:turn_pink"
      },
      "use_item": true
    },
    {
      "on_interact": {
        "filters": {
            "all_of": [
              { "test": "has_equipment", "subject": "other", "domain": "hand", "value": "dye:6" },
              { "test": "is_family", "subject": "other", "value": "player" },
              { "test": "is_variant", "subject": "self", "operator": "!=", "value": 1 }
            ]
        },
        "event": "minecraft:turn_cyan"
      },
      "use_item": true
    },
    {
      "on_interact": {
        "filters": {
            "all_of": [
              { "test": "has_equipment", "subject": "other", "domain": "hand", "value": "dye:11" },
              { "test": "is_family", "subject": "other", "value": "player" },
              { "test": "is_variant", "subject": "self", "operator": "!=", "value": 2 }
            ]
        },
        "event": "minecraft:turn_yellow"
      },
      "use_item": true
    },
    {
      "on_interact": {
        "filters": {
            "all_of": [
              {
                "any_of": [
                  { "test": "has_equipment", "subject": "other", "domain": "hand", "value": "dye:3" },
                  { "test": "has_equipment", "subject": "other", "domain": "hand", "value": "dye:17" }
                ]
              },
              { "test": "is_family", "subject": "other", "value": "player" },
              { "test": "is_variant", "subject": "self", "operator": "!=", "value": 3 }
            ]
        },
        "event": "minecraft:turn_brown"
      },
      "use_item": true
    },
    {
      "on_interact": {
        "filters": {
            "all_of": [
              {
                "any_of": [
                  { "test": "has_equipment", "subject": "other", "domain": "hand", "value": "dye:4" },
                  { "test": "has_equipment", "subject": "other", "domain": "hand", "value": "dye:18" }
                ]
              },
              { "test": "is_family", "subject": "other", "value": "player" },
              { "test": "is_variant", "subject": "self", "operator": "!=", "value": 4 }
            ]
        },
        "event": "minecraft:turn_blue"
      },
      "use_item": true
    }
  ]
}

動作確認

統合版マイクラを起動、適当なワールドを作成しビヘイビアーパックを有効化します。
うまく読み込まれない、動作しない場合は、ログを確認します。

ログを表示させるには、設定のクリエイター設定より表示を有効化します。

  • コンテンツ ログ ファイルの有効化
  • コンテンツ ログ GUIの有効化
  • 読み込み時のエラーでコンテンツ ログを表示

クリエイター

ビヘイビアーパックを読み込んだ際に、何か間違っていると画面にエラー表示されます。

[Log][warning] (中略) evelopment_behavior_packs/ウパ染め | minecraft:axolotl | minecraft:entity |  -> component_groups -> minecraft:interact -> interactions: this component was found in the input, but is not present in the Schema

[Actor][error](中略) development_behavior_packs/ウパ染め | minecraft:axolotl | minecraft:entity | ERROR: Entity 'minecraft:axolotl' failed to load from JSON

minecraft:axolotlつまりウパのファイルが読み込まれていません。

interactions: this component was found in the input, but is not present in the Schema

minecraft:interactのコンポーネントを誤ってcomponent_groupsに記載していました。修正しました。

動作確認して完成です。

ウパ染めデモ.gif

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?