環境構築からWEBアプリ開発・スマホアプリ開発まで。ときには動画制作やゲームも。

supilog
すぴろぐ

【Minecraftのアドオンを作る】#2 ビヘイビアーパックのお勉強

【Minecraftのアドオンを作る】#2 ビヘイビアーパックのお勉強

今回はビヘイビアーパックについて学ぶ回。引き続きチュートリアルを進めていきます。

https://learn.microsoft.com/ja-jp/minecraft/creator/documents/behaviorpack

ビヘイビアー パックとは、エンティティの行動、戦利品ドロップ、スポーン ルール、アイテム、レシピ、トレード テーブルを制御するファイルが格納されているフォルダー構造のことです。

ビヘイビアーパックの作成

ディレクトリ作成

今回はビヘイビアーパックの名前として、「my_cow」というディレクトリを作成。更に、その直下に「entities」というディレクトリを作成しました。

manifest.json作成

「my_cow」ディレクトリ直下に、manifest.jsonファイルを作成。以下の内容を記述します。

{
  "format_version": 2,
  "header": {
    "description": "My attack cow behavior pack Add-On!",
    "name": "My Behavior Pack",
    "uuid":"",
    "version": [1, 0, 0],
    "min_engine_version": [1, 16, 0]
  },
  "modules":
    [
      {
        "description": "My First Add-On!",
          "type": "data",
          "uuid": "",
          "version": [1, 0, 0]
      }
    ],
  "dependencies": [
    {
     "uuid":"",
      "version":[1,0,0]
    }
 ]
}

前回の記事と同じように、UUIDを生成して入力します。Online UUID Generatorを利用するか、拡張機能「UUID Generator」を利用すると便利です。前回と異なり、”dependencies”という項目にもUUIDを入力する欄があります。

これは、リソースパックを同時に利用したいときに、リソースパック側のUUIDを入力しておくと、ビヘイビアーパックを読み込んだときに、リンクされたリソースパックが自動的に読み込まれて有効化される機能のようです。

一旦今回は利用しないので、適当なUUIDを入れておきます。

エンティティファイルの作成(cow.json)

「entities」ディレクトリ配下に、cow.jsonというファイルを作成し、以下の内容を貼り付ける。

{
    "format_version": "1.16.0",
    "minecraft:entity": {
        "description": {
            "identifier": "minecraft:cow",
            "is_spawnable": true,
            "is_summonable": true,
            "is_experimental": false
        },
        "component_groups": {
            "minecraft:cow_baby": {
                "minecraft:is_baby": {},
                "minecraft:scale": {
                    "value": 0.5
                },
                "minecraft:ageable": {
                    "duration": 1200,
                    "feed_items": "wheat",
                    "grow_up": {
                        "event": "minecraft:ageable_grow_up",
                        "target": "self"
                    }
                },
                "minecraft:behavior.follow_parent": {
                    "priority": 6,
                    "speed_multiplier": 1.1
                }
            },
            "minecraft:cow_adult": {
                "minecraft:experience_reward": {
                    "on_bred": "Math.Random(1,7)",
                    "on_death": "query.last_hit_by_player ? Math.Random(1,3) : 0"
                },
                "minecraft:loot": {
                    "table": "loot_tables/entities/cow.json"
                },
                "minecraft:behavior.breed": {
                    "priority": 3,
                    "speed_multiplier": 1.0
                },
                "minecraft:breedable": {
                    "require_tame": false,
                    "breed_items": "wheat",
                    "breeds_with": {
                        "mate_type": "minecraft:cow",
                        "baby_type": "minecraft:cow",
                        "breed_event": {
                            "event": "minecraft:entity_born",
                            "target": "baby"
                        }
                    }
                },
                "minecraft:interact": {
                    "interactions": [
                        {
                            "on_interact": {
                                "filters": {
                                    "all_of": [
                                        {
                                            "test": "is_family",
                                            "subject": "other",
                                            "value": "player"
                                        },
                                        {
                                            "test": "has_equipment",
                                            "domain": "hand",
                                            "subject": "other",
                                            "value": "bucket:0"
                                        }
                                    ]
                                }
                            },
                            "use_item": true,
                            "transform_to_item": "bucket:1",
                            "play_sounds": "milk",
                            "interact_text": "action.interact.milk"
                        }
                    ]
                }
            }
        },
        "components": {
            "minecraft:is_hidden_when_invisible": {},
            "minecraft:type_family": {
                "family": [
                    "cow",
                    "mob"
                ]
            },
            "minecraft:breathable": {
                "total_supply": 15,
                "suffocate_time": 0
            },
            "minecraft:navigation.walk": {
                "can_path_over_water": true,
                "avoid_water": true,
                "avoid_damage_blocks": true
            },
            "minecraft:movement.basic": {},
            "minecraft:jump.static": {},
            "minecraft:can_climb": {},
            "minecraft:collision_box": {
                "width": 0.9,
                "height": 1.3
            },
            "minecraft:nameable": {},
            "minecraft:health": {
                "value": 10,
                "max": 10
            },
            "minecraft:hurt_on_condition": {
                "damage_conditions": [
                    {
                        "filters": {
                            "test": "in_lava",
                            "subject": "self",
                            "operator": "==",
                            "value": true
                        },
                        "cause": "lava",
                        "damage_per_tick": 4
                    }
                ]
            },
            "minecraft:movement": {
                "value": 0.25
            },
            "minecraft:despawn": {
                "despawn_from_distance": {}
            },
            "minecraft:behavior.float": {
                "priority": 0
            },
            "minecraft:behavior.panic": {
                "priority": 1,
                "speed_multiplier": 1.25
            },
            "minecraft:behavior.mount_pathing": {
                "priority": 2,
                "speed_multiplier": 1.5,
                "target_dist": 0.0,
                "track_target": true
            },
            "minecraft:behavior.breed": {
                "priority": 3,
                "speed_multiplier": 1.0
            },
            "minecraft:behavior.tempt": {
                "priority": 4,
                "speed_multiplier": 1.25,
                "items": [
                    "wheat"
                ]
            },
            "minecraft:behavior.follow_parent": {
                "priority": 5,
                "speed_multiplier": 1.1
            },
            "minecraft:behavior.random_stroll": {
                "priority": 6,
                "speed_multiplier": 0.8
            },
            "minecraft:behavior.look_at_player": {
                "priority": 7,
                "look_distance": 6.0,
                "probability": 0.02
            },
            "minecraft:behavior.random_look_around": {
                "priority": 9
            },
            "minecraft:leashable": {
                "soft_distance": 4.0,
                "hard_distance": 6.0,
                "max_distance": 10.0
            },
            "minecraft:balloonable": {},
            "minecraft:rideable": {
                "seat_count": 1,
                "family_types": [
                    "zombie"
                ],
                "seats": {
                    "position": [
                        0.0,
                        1.105,
                        0.0
                    ]
                }
            },
            "minecraft:physics": {},
            "minecraft:pushable": {
                "is_pushable": true,
                "is_pushable_by_piston": true
            },
            "minecraft:conditional_bandwidth_optimization": {},
            "minecraft:behavior.nearest_attackable_target": {
                "priority": 2,
                "must_see": true,
                "reselect_targets": true,
                "within_radius": 25.0,
                "entity_types": [
                    {
                        "filters": {
                            "test": "is_family",
                            "subject": "other",
                            "value": "player"
                        },
                        "max_dist": 32
                    }
                ]
            },
            "minecraft:behavior.melee_attack": {
                "priority": 3
            },
            "minecraft:attack": {
                "damage": 3
            }
        },
        "events": {
            "minecraft:entity_spawned": {
                "randomize": [
                    {
                        "weight": 95,
                        "trigger": "minecraft:spawn_adult"
                    },
                    {
                        "weight": 5,
                        "add": {
                            "component_groups": [
                                "minecraft:cow_baby"
                            ]
                        }
                    }
                ]
            },
            "minecraft:entity_born": {
                "add": {
                    "component_groups": [
                        "minecraft:cow_baby"
                    ]
                }
            },
            "minecraft:entity_transformed": {
                "remove": {},
                "add": {
                    "component_groups": [
                        "minecraft:cow_adult"
                    ]
                }
            },
            "minecraft:ageable_grow_up": {
                "remove": {
                    "component_groups": [
                        "minecraft:cow_baby"
                    ]
                },
                "add": {
                    "component_groups": [
                        "minecraft:cow_adult"
                    ]
                }
            },
            "minecraft:spawn_adult": {
                "add": {
                    "component_groups": [
                        "minecraft:cow_adult"
                    ]
                }
            }
        }
    }
}

このファイルは牛モブの様々な行動を制御しているファイルのようですが、今のところ、詳しい中身は把握できていません。ただ、今回どこを変更したのか位は、知っておくべきかと思うので、差分をチェックしてみた。

差分の確認

メインの差分のみ記述します。主に以下が追加されていました。攻撃っぽい設定項目が追加されていますね。

■項目
"minecraft:entity":
    "components":
        "minecraft:behavior.nearest_attackable_target":

■内容
            "minecraft:behavior.nearest_attackable_target": {
                "priority": 2,
                "must_see": true,
                "reselect_targets": true,
                "within_radius": 25,
                "entity_types": [
                    {
                        "filters": {
                            "test": "is_family",
                            "subject": "other",
                            "value": "player"
                        },
                        "max_dist": 32
                    }
                ]
            },
            "minecraft:behavior.melee_attack": {
                "priority": 3
            },
            "minecraft:attack": {
                "damage": 3
            }

ビヘイビアーパックの配置

my_cowを配置

「development_behavior_packs」ディレクトリの下に今回作成したファイルを配置します。以下のような感じで、ディレクトリごと配置します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ ls -la development_behavior_packs
drwxr-xr-x 3 root root 20 Jun 16 15:12 .
drwxr-xr-x 14 root root 4096 Jun 15 21:56 ..
drwxr-xr-x 3 root root 43 Jun 16 15:12 my_cow
$ ls -la development_behavior_packs drwxr-xr-x 3 root root 20 Jun 16 15:12 . drwxr-xr-x 14 root root 4096 Jun 15 21:56 .. drwxr-xr-x 3 root root 43 Jun 16 15:12 my_cow
$ ls -la development_behavior_packs

drwxr-xr-x  3 root root   20 Jun 16 15:12 .
drwxr-xr-x 14 root root 4096 Jun 15 21:56 ..
drwxr-xr-x  3 root root   43 Jun 16 15:12 my_cow

world_behavior_packs.jsonを作成

worldsディレクトリには、マイクラのワールドデータが入っていますが、このリソースパックを適用したいワールドのディレクトリに、world_behavior_packs.jsonというファイルを配置し、ビヘイビアーパックを適用させます。

以下のようにワールドデータが存在する場所にファイルを配置します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
drwxr-xr-x 2 root root 80 Jun 16 00:04 db
-rw-r--r-- 1 root root 2929 Jun 16 00:05 level.dat
-rw-r--r-- 1 root root 2929 Jun 16 00:05 level.dat_old
-rw-r--r-- 1 root root 5 Jun 16 00:05 levelname.txt
-rw-r--r-- 1 root root 134 Jun 15 21:55 world_resource_packs.json
-rw-r--r-- 1 root root 134 Jun 15 21:55 world_behavior_packs.json
drwxr-xr-x 2 root root 80 Jun 16 00:04 db -rw-r--r-- 1 root root 2929 Jun 16 00:05 level.dat -rw-r--r-- 1 root root 2929 Jun 16 00:05 level.dat_old -rw-r--r-- 1 root root 5 Jun 16 00:05 levelname.txt -rw-r--r-- 1 root root 134 Jun 15 21:55 world_resource_packs.json -rw-r--r-- 1 root root 134 Jun 15 21:55 world_behavior_packs.json
drwxr-xr-x 2 root root   80 Jun 16 00:04 db
-rw-r--r-- 1 root root 2929 Jun 16 00:05 level.dat
-rw-r--r-- 1 root root 2929 Jun 16 00:05 level.dat_old
-rw-r--r-- 1 root root    5 Jun 16 00:05 levelname.txt
-rw-r--r-- 1 root root  134 Jun 15 21:55 world_resource_packs.json
-rw-r--r-- 1 root root  134 Jun 15 21:55 world_behavior_packs.json

ファイルの中身には、manifest.jsonの「header」項目で記述した、uuidとversionを記載します。

[
         {
                 "pack_id" : "af697d1e-587d-4061-9206-5d248cd3aa8b",
                 "version" : [1, 0, 0]
         }
]

マイクラを再起動して確認してみる

さて、牛の行動は変化しているでしょうか。楽しみです。

無事に襲われました。痛い痛い。。とりあえず成功です。

まとめ

無事にビヘイビアーパックを導入するチュートリアルを終えました。設定項目が多いので、何がどのように操作できるのかは、これから勉強していく必要がありそうです。それでは、また次回にお会いしましょう。

今回のソースコード

https://github.com/supilog/minecraft_addons/tree/main/behaviors/my_cow