アドオン詳細解説 - ルートテーブル

アップロード:2023/01/01 最終更新:2023/01/01

いろんなところで活躍するルートテーブルですが、JSONが見づらいのでなかなか思い通りにいかないかもしれません。

今回はルートテーブルのJSONを見極めるコツを中心に作り方を解説していこうと思います。

目次 (折りたたみ可)

ルートテーブルとは

モブを倒したり、ブロックを壊したりしたときに、どんなアイテムを落とすか決めるものです。

その派生で、チェストの中身や釣りのアイテム、敵モブの装備などにも流用されます。

ファイルの場所

基本的にルートテーブルを指定するときはファイルパスで指定するのでビヘイビアパック内のどこでもいいと思いますが、 オススメはこのloot_tablesフォルダです。

ビヘイビアパック
┣ manifest.json
loot_tables
┗ pack_icon.png

自分で場所を指定できるので、指定する場所に注意してこの中にさらにフォルダを作って分けることができます。

オススメのフォルダ構成はこんな感じです。もちろん作るのは必要な分だけでいいです。

ビヘイビアパック
┣ manifest.json
┣ pack_icon.png
┗ loot_tables
  ┣ blocks
  ┣ chests
  ┣ entities
  ┣ equipment
  ┗ gameplay

ルートテーブルのJSON(基礎)

まず、一番シンプルに「リンゴを必ず一つ落とす」というルートテーブルです。

{ "pools": [ { "rolls": 1, "entries": [ { "type": "item", "name": "minecraft:apple", "weight": 1 } ] } ] }

もうこの時点でカッコが多くて見づらいんですよね。

主な構成

{ "pools": [ { "rolls": 1, "entries": [ { "type": "item", "name": "minecraft:apple", "weight": 1 } ] } ] }
{ "pools": [ ~#B(f00){ "rolls": 1, "entries": [ ~#B(00f){ "type": "item", "name": "minecraft:apple", "weight": 1 }B#~ ] }B#~ ] }

このように枠で囲うと一気に分かりやすくなると思います。それぞれの枠をどのように増やすかでいろいろ変わってきます。

選択肢を増やす

{ "pools": [ { "rolls": 1, "entries": [ { "type": "item", "name": "minecraft:apple", "weight": 1 }, { "type": "item", "name": "minecraft:apple_golden", "weight": 1 } ] } ] }
{ "pools": [ ~#B(f00){ "rolls": 1, "entries": [ ~#B(00f){ "type": "item", "name": "minecraft:apple", "weight": 1 },B#~ ~#B(00f){ "type": "item", "name": "minecraft:apple_golden", "weight": 1 }B#~ ] }B#~ ] }

このように青い枠の部分を増やすと「選択肢」が増えます。

この例では「リンゴか金リンゴどちらか一つを必ず落とす」というルートテーブルになります。確率はどちらも50%です。

確率を変える

{ "pools": [ { "rolls": 1, "entries": [ { "type": "item", "name": "minecraft:apple", "weight": 9 }, { "type": "item", "name": "minecraft:apple_golden", "weight": 1 } ] } ] }
{ "pools": [ ~#B(f00){ "rolls": 1, "entries": [ ~#B(00f){ "type": "item", "name": "minecraft:apple", "weight": ~#M(83ffd9)9M#~ },B#~ ~#B(00f){ "type": "item", "name": "minecraft:apple_golden", "weight": 1 }B#~ ] }B#~ ] }

このweight(ウェイト)」値を変えると確率が変わります。これでリンゴが90%、金リンゴが10%になりました。 くじ引きの箱に「リンゴ」と書かれた紙が何枚、「金リンゴ」と書かれた紙が何枚入っているかみたいなイメージですね。

パーセントの計算は「(確率を求めたいアイテムのweight)÷(赤い枠の中に登場するweightをぜんぶ足した値)×100」です。4と1ならば80%と20%、3と2ならば60%と40%になります。

確率のイメージがどうしてもわからないという場合は、赤い枠の中に登場するweightをぜんぶ足して最初から100になるようにしてもいいかもしれません。(9:1を90:10にしても比は変わりませんよね)

ハズレをつくる

{ "pools": [ { "rolls": 1, "entries": [ { "type": "empty", "weight": 10 }, { "type": "item", "name": "minecraft:apple", "weight": 9 }, { "type": "item", "name": "minecraft:apple_golden", "weight": 1 } ] } ] }
{ "pools": [ ~#B(f00){ "rolls": 1, "entries": [ ~#B(00f){ "type": "empty", "weight": 10 },B#~ ~#B(00f){ "type": "item", "name": "minecraft:apple", "weight": 9 },B#~ ~#B(00f){ "type": "item", "name": "minecraft:apple_golden", "weight": 1 }B#~ ] }B#~ ] }

このようにemptyタイプを指定してハズレを追加します。ちなみにweightが上から10:9:1なので、確率は50%、45%、5%ということです。

抽選対象を増やす

今度はこのように、赤い枠を増やしたらどうなるでしょうか?

{ "pools": [ { "rolls": 1, "entries": [ { "type": "item", "name": "minecraft:apple", "weight": 1 } ] }, { "rolls": 1, "entries": [ { "type": "item", "name": "minecraft:iron_ingot", "weight": 1 } ] } ] }
{ "pools": [ ~#B(f00){ "rolls": 1, "entries": [ ~#B(00f){ "type": "item", "name": "minecraft:apple", "weight": 1 }B#~ ] },B#~ ~#B(f00){ "rolls": 1, "entries": [ ~#B(00f){ "type": "item", "name": "minecraft:iron_ingot", "weight": 1 }B#~ ] }B#~ ] }

この場合は「リンゴと鉄インゴットを必ず落とす」というルートテーブルになります。

こんがらがってきたでしょうか? 次のように青枠部分を増やすと分かると思います。

{ "pools": [ { "rolls": 1, "entries": [ { "type": "item", "name": "minecraft:apple", "weight": 9 }, { "type": "item", "name": "minecraft:apple_golden", "weight": 1 } ] }, { "rolls": 1, "entries": [ { "type": "item", "name": "minecraft:iron_ingot", "weight": 1 } ] } ] }
{ "pools": [ ~#B(f00){ "rolls": 1, "entries": [ ~#B(00f){ "type": "item", "name": "minecraft:apple", "weight": 9 },B#~ ~#B(00f){ "type": "item", "name": "minecraft:apple_golden", "weight": 1 }B#~ ] },B#~ ~#B(f00){ "rolls": 1, "entries": [ ~#B(00f){ "type": "item", "name": "minecraft:iron_ingot", "weight": 1 }B#~ ] }B#~ ] }

この場合「90%の確率でリンゴ、10%の確率で金リンゴをどちらか1つ落とし、さらに鉄を100%で落とす」というものになります。

くじ引きの箱が二つあり、一つ目の箱には「リンゴ」と書かれた紙が9枚と「金リンゴ」と書かれた紙が1枚、 二つ目の箱には「鉄インゴット」と書かれた紙が1枚だけ入っているという感じです。

しかし、今までのままだとアイテムは一つしか落としません。 個数なども含め、特殊な落としかたをどうやって指定するか見ていきましょう。

ファンクション

{ "pools": [ { "rolls": 1, "entries": [ { "type": "item", "name": "minecraft:apple", "weight": 1, "functions": [ { // ファンクションの中身 } ] } ] } ] }
{ "pools": [ ~#B(f00){ "rolls": 1, "entries": [ ~#B(00f){ "type": "item", "name": "minecraft:apple", "weight": 1, ~#B(0c0)"functions": [ { // ファンクションの中身 } ]B#~ }B#~ ] }B#~ ] }

ここにファンクションというものを追加して特殊な方法でドロップするようにします。

個数を指定

{ "pools": [ { "rolls": 1, "entries": [ { "type": "item", "name": "minecraft:apple", "weight": 1, "functions": [ { "function": "set_count", "count": { "min": 0, "max": 2 } } ] } ] } ] }
{ "pools": [ ~#B(f00){ "rolls": 1, "entries": [ ~#B(00f){ "type": "item", "name": "minecraft:apple", "weight": 1, ~#B(0c0)"functions": [ { "function": "set_count", "count": { "min": 0, "max": 2 } } ]B#~ }B#~ ] }B#~ ] }

例えばこのようにすると「リンゴが必ず0~2個ドロップする」ようになります。

スキーマ的なやつ

ファンクションをすべて解説するわけにはいかないので、ここにおそらく全てのファンクションを載せました。

JSON全体をコピーするよりはファンクションなど一部をコピーすることをお勧めします。

順番はファンクション名のアルファベット順になっていると思います。

{ "pools": [ { "conditions": [ { "condition": "killed_by_player" }, { "condition": "random_chance_with_looting", "chance": 0.025, "looting_multiplier": 0.01 }, { "condition": "random_difficulty_chance", "default_chance": 0.5, "peaceful": 0, "hard": 0.6 } ], "rolls": 1, "entries": [ { "type": "empty", "weight": 1 }, { "type": "loot_table", "name": "loot_tables/gameplay/fishing/fish", "quarity": 1, "weight": 1 }, { "type": "item", "name": "ItemID", "weight": 1, "functions": [ { "function": "enchant_book_for_trading", "base_cost": 2, "base_random_cost": 5, "per_level_random_cost": 10, "per_level_cost": 3 }, { // ランダムにエンチャントします "function": "enchant_randomly", "treasure": true }, { // ランダムにエンチャントします(equipment用) "function": "enchant_random_gear", "chance": 0.25 }, { // レベルを指定してランダムにエンチャント "function": "enchant_with_levels", "treasure": true, "levels": { "min": 15, "max": 20 } }, { // 探検家の地図 "function": "exploration_map", "destination": "buriedtreasure" // 選べる値:"buriedtreasure", "monument", "mansion" }, { // 燃え死んだときにかまどレシピに基づいてアイテムを焼くか "function": "furnace_smelt", "conditions": [ { "condition": "entity_properties", "entity": "this", "properties": { "on_fire": true } } ] }, { // ドロップ増加エンチャントで追加される個数 "function": "looting_enchant", "count": { "min": 0, "max": 1 } }, { // ランダムなデータ値 "function": "random_aux_value", "values": { "min": 0, "max": 15 } }, { // ブロックステートをランダムにします "function": "random_block_state", "block_state": "flower_type", "values": { "min": 0, "max": 10 } }, { // ランダムに染色 "function": "random_dye" }, { // スポーンエッグの中身 "function": "set_actor_id", "id": "ID" }, { // 旗の模様 "function": "set_banner_details", "type": 1 }, { // ドロップする個数 "function": "set_count", "count": { "min": 0, "max": 2 } }, { // 耐久を減らす(0.0~1.0の割合) "function": "set_damage", "damage": { "min": 0.0, "max": 0.9 } }, { // データ値を指定 "function": "set_data", "data": 0 }, { "function": "minecraft:set_data_from_color_index" }, { // 説明文を追加 "function": "set_lore", "lore": [ "Lore1", "Lore2", "..." ] }, { // 名前を指定 "function": "set_name", "name": "Name" }, { // 指定したエンチャント "function": "specific_enchants", "enchants": [ { "id": "soul_speed", "level": [ 1, 3 ] } ] } // ... ] } ] } ] }
{ "pools": [ { ~#B(f00)"conditions": [ { "condition": "killed_by_player" }, { "condition": "random_chance_with_looting", "chance": 0.025, "looting_multiplier": 0.01 }, { "condition": "random_difficulty_chance", "default_chance": 0.5, "peaceful": 0, "hard": 0.6 } ],B#~ "rolls": 1, "entries": [ ~#B(00f){ "type": "empty", "weight": 1 },B#~ ~#B(00f){ "type": "loot_table", "name": "loot_tables/gameplay/fishing/fish", "quarity": 1, "weight": 1 },B#~ ~#B(00f){ "type": "item", "name": "ItemID", "weight": 1, "functions": [ ~#B(0c0){ "function": "enchant_book_for_trading", "base_cost": 2, "base_random_cost": 5, "per_level_random_cost": 10, "per_level_cost": 3 },B#~ ~#B(0c0){ // ランダムにエンチャントします "function": "enchant_randomly", "treasure": true },B#~ ~#B(0c0){ // ランダムにエンチャントします(equipment用) "function": "enchant_random_gear", "chance": 0.25 },B#~ ~#B(0c0){ // レベルを指定してランダムにエンチャント "function": "enchant_with_levels", "treasure": true, "levels": { "min": 15, "max": 20 } },B#~ ~#B(0c0){ // 探検家の地図 "function": "exploration_map", "destination": "buriedtreasure" // 選べる値:"buriedtreasure", "monument", "mansion" },B#~ ~#B(0c0){ // 燃え死んだときにかまどレシピに基づいてアイテムを焼くか "function": "furnace_smelt", "conditions": [ { "condition": "entity_properties", "entity": "this", "properties": { "on_fire": true } } ] },B#~ ~#B(0c0){ // ドロップ増加エンチャントで追加される個数 "function": "looting_enchant", "count": { "min": 0, "max": 1 } },B#~ ~#B(0c0){ // ランダムなデータ値 "function": "random_aux_value", "values": { "min": 0, "max": 15 } },B#~ ~#B(0c0){ // ブロックステートをランダムにします "function": "random_block_state", "block_state": "flower_type", "values": { "min": 0, "max": 10 } },B#~ ~#B(0c0){ // ランダムに染色 "function": "random_dye" },B#~ ~#B(0c0){ // スポーンエッグの中身 "function": "set_actor_id", "id": "ID" },B#~ ~#B(0c0){ // 旗の模様 "function": "set_banner_details", "type": 1 },B#~ ~#B(0c0){ // ドロップする個数 "function": "set_count", "count": { "min": 0, "max": 2 } },B#~ ~#B(0c0){ // 耐久を減らす(0.0~1.0の割合) "function": "set_damage", "damage": { "min": 0.0, "max": 0.9 } },B#~ ~#B(0c0){ // データ値を指定 "function": "set_data", "data": 0 },B#~ ~#B(0c0){ "function": "minecraft:set_data_from_color_index" },B#~ ~#B(0c0){ // 説明文を追加 "function": "set_lore", "lore": [ "Lore1", "Lore2", "..." ] },B#~ ~#B(0c0){ // 名前を指定 "function": "set_name", "name": "Name" },B#~ ~#B(0c0){ // 指定したエンチャント "function": "specific_enchants", "enchants": [ { "id": "soul_speed", "level": [ 1, 3 ] } ] }B#~ // ... ] }B#~ ] } ] }