ルッキーのコマンドメモ

主にマイクラのコマンドやデータパックに関することを書いていきます。

(マイクラ コマンド・データパック)釣りのルートテーブル変更方法や応用例

釣りのルートテーブルを整理する

今回はマイクラの釣りのルートテーブルとその変更方法について紹介していきます

目次

デフォルトのルートテーブル

イクラの釣りのデフォルトのルートテーブルは以下のようになります(JE ver1.20.2のものです。)

fishing.json

{
  "type": "minecraft:fishing",
  "pools": [
    {
      "bonus_rolls": 0.0,
      "entries": [
        {
          "type": "minecraft:loot_table",
          "name": "minecraft:gameplay/fishing/junk",
          "quality": -2,
          "weight": 10
        },
        {
          "type": "minecraft:loot_table",
          "conditions": [
            {
              "condition": "minecraft:entity_properties",
              "entity": "this",
              "predicate": {
                "type_specific": {
                  "type": "fishing_hook",
                  "in_open_water": true
                }
              }
            }
          ],
          "name": "minecraft:gameplay/fishing/treasure",
          "quality": 2,
          "weight": 5
        },
        {
          "type": "minecraft:loot_table",
          "name": "minecraft:gameplay/fishing/fish",
          "quality": -1,
          "weight": 85
        }
      ],
      "rolls": 1.0
    }
  ],
  "random_sequence": "minecraft:gameplay/fishing"
}

何が出るかを決めているのは上から6行目の"entries"という部分の中になります。

下から5行目の"rolls"で設定された回数だけ、この"entries"の中からどれか一つが抽選されます。

"entries"の中にはジャンクアイテム(ゾンビ肉や骨などのハズレアイテム)、宝アイテム(エンチャント本など)、魚の3つの要素が入っています。

それぞれの要素が選択される確率を決めているのが"weight"と"quality"という部分です。

1回の抽選でそれぞれの要素が選択される確率は以下の計算式で表されます。

(選択される確率) = (その要素のweight) / (全要素のweightの和)

また、"quality"という部分により、プレイヤの幸運の値によってweightが変動します。

その変化量は以下の計算式で求められます。

(weightの変化量) = (その要素のquality) × (プレイヤの幸運の値)

そのため、プレイヤの幸運の値が85を超えると宝しか釣れなくなり、一方で幸運の値が-5以下になると宝は一切釣れなくなります。

ちなみに、宝釣りによるエンチャント効果もおそらく幸運の値をレベル分上昇させるものだと考えられます。(幸運値を-85にした状態で宝釣り85レベルの釣竿で釣りをすると三種類全てのアイテムが釣れたため)

3種類のアイテムの中身

上記の釣りのルートテーブルでは釣りをするごとに1回抽選が行われ、ジャンクアイテム、宝アイテム、魚の3種類の中のどれかが出現するように設定されていました。

3種類それぞれのアイテムの中から具体的に何が釣れるのかを決めるのが以下のルートテーブルです。

ジャンクアイテム

junk.json

{
  "type": "minecraft:fishing",
  "pools": [
    {
      "bonus_rolls": 0.0,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:lily_pad",
          "weight": 17
        },
        {
          "type": "minecraft:item",
          "functions": [
            {
              "add": false,
              "damage": {
                "type": "minecraft:uniform",
                "max": 0.9,
                "min": 0.0
              },
              "function": "minecraft:set_damage"
            }
          ],
          "name": "minecraft:leather_boots",
          "weight": 10
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:leather",
          "weight": 10
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:bone",
          "weight": 10
        },
        {
          "type": "minecraft:item",
          "functions": [
            {
              "function": "minecraft:set_potion",
              "id": "minecraft:water"
            }
          ],
          "name": "minecraft:potion",
          "weight": 10
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:string",
          "weight": 5
        },
        {
          "type": "minecraft:item",
          "functions": [
            {
              "add": false,
              "damage": {
                "type": "minecraft:uniform",
                "max": 0.9,
                "min": 0.0
              },
              "function": "minecraft:set_damage"
            }
          ],
          "name": "minecraft:fishing_rod",
          "weight": 2
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:bowl",
          "weight": 10
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:stick",
          "weight": 5
        },
        {
          "type": "minecraft:item",
          "functions": [
            {
              "add": false,
              "count": 10.0,
              "function": "minecraft:set_count"
            }
          ],
          "name": "minecraft:ink_sac"
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:tripwire_hook",
          "weight": 10
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:rotten_flesh",
          "weight": 10
        },
        {
          "type": "minecraft:item",
          "conditions": [
            {
              "condition": "minecraft:any_of",
              "terms": [
                {
                  "condition": "minecraft:location_check",
                  "predicate": {
                    "biome": "minecraft:jungle"
                  }
                },
                {
                  "condition": "minecraft:location_check",
                  "predicate": {
                    "biome": "minecraft:sparse_jungle"
                  }
                },
                {
                  "condition": "minecraft:location_check",
                  "predicate": {
                    "biome": "minecraft:bamboo_jungle"
                  }
                }
              ]
            }
          ],
          "name": "minecraft:bamboo",
          "weight": 10
        }
      ],
      "rolls": 1.0
    }
  ],
  "random_sequence": "minecraft:gameplay/fishing/junk"
}

宝アイテム

treasure.json

{
  "type": "minecraft:fishing",
  "pools": [
    {
      "bonus_rolls": 0.0,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:name_tag"
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:saddle"
        },
        {
          "type": "minecraft:item",
          "functions": [
            {
              "add": false,
              "damage": {
                "type": "minecraft:uniform",
                "max": 0.25,
                "min": 0.0
              },
              "function": "minecraft:set_damage"
            },
            {
              "function": "minecraft:enchant_with_levels",
              "levels": 30.0,
              "treasure": true
            }
          ],
          "name": "minecraft:bow"
        },
        {
          "type": "minecraft:item",
          "functions": [
            {
              "add": false,
              "damage": {
                "type": "minecraft:uniform",
                "max": 0.25,
                "min": 0.0
              },
              "function": "minecraft:set_damage"
            },
            {
              "function": "minecraft:enchant_with_levels",
              "levels": 30.0,
              "treasure": true
            }
          ],
          "name": "minecraft:fishing_rod"
        },
        {
          "type": "minecraft:item",
          "functions": [
            {
              "function": "minecraft:enchant_with_levels",
              "levels": 30.0,
              "treasure": true
            }
          ],
          "name": "minecraft:book"
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:nautilus_shell"
        }
      ],
      "rolls": 1.0
    }
  ],
  "random_sequence": "minecraft:gameplay/fishing/treasure"
}

fish.json

{
  "type": "minecraft:fishing",
  "pools": [
    {
      "bonus_rolls": 0.0,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:cod",
          "weight": 60
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:salmon",
          "weight": 25
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:tropical_fish",
          "weight": 2
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:pufferfish",
          "weight": 13
        }
      ],
      "rolls": 1.0
    }
  ],
  "random_sequence": "minecraft:gameplay/fishing/fish"
}

釣りからモブが釣れるようにする

釣りのルートテーブルにモブと変換するためのアイテムを追加し、そのアイテムの座標にモブを召喚して、アイテムをkillすることで、擬似的に釣りによってモブが釣れるようになります。

詳しくは釣りからモブが釣れるようにする方法を参照してください。

実装方法

まずデフォルトのルートテーブルを以下のように書き換えます。

fishing.json

{
  "type": "minecraft:fishing",
  "pools": [
    {
      "bonus_rolls": 0.0,
      "entries": [
        {
          "type": "minecraft:loot_table",
          "name": "minecraft:gameplay/fishing/junk",
          "quality": -2,
          "weight": 10
        },
        {
          "type": "minecraft:loot_table",
          "conditions": [
            {
              "condition": "minecraft:entity_properties",
              "entity": "this",
              "predicate": {
                "type_specific": {
                  "type": "fishing_hook",
                  "in_open_water": true
                }
              }
            }
          ],
          "name": "minecraft:gameplay/fishing/treasure",
          "quality": 2,
          "weight": 5
        },
        {
          "type": "minecraft:loot_table",
          "name": "minecraft:gameplay/fishing/fish",
          "quality": -1,
          "weight": 85
        },
        {
          "type": "minecraft:loot_table",
          "name": "test:mobs",
          "quality": 0,
          "weight": 50
        }
      ],
      "rolls": 1.0
    }
  ],
  "random_sequence": "minecraft:gameplay/fishing"
}

これによって、釣りをした時に(特に幸運値が変化していなければ)3回に1回の確率でtest:mobsというルートテーブルが適用されるようになりました。

次に、このルートテーブルを以下のように設定します。

mobs.json

{
  "type": "minecraft:fishing",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:stone",
          "functions": [
            {
              "function": "minecraft:set_nbt",
              "tag": "{fishing:1}"
            }
          ]
        }
      ]
    }
  ]
}

以上の設定により、釣りをすると3回に1回{fishing:1}というタグがついた石が釣れるようになります。

あとは、以下のようにコマンドを毎tick実行してアイテムとモブを置き換えることにより、擬似的にモブが釣れるようになります。

tick.mcfunction

# ゾンビを召喚してアイテムのMotionの値を代入
execute as @e[type=item,nbt={Item:{tags:{fishing:1}}}] at @s positioned ~ ~1 ~ summon zombie run data modify entity @s Motion set from entity @e[type=item,nbt={Item:{id:"minecraft:stone"}},sort=nearest,limit=1] Motion

#釣れたアイテムをkill
kill @e[type=item,nbt={Item:{tags:{fishing:1}}}]

特定の釣竿を使った時だけ別のアイテムが釣れるようにする

特定の釣竿を使った時だけ、別のアイテムが釣れるようにする方法です。
今回は{sugoi_turizao:1}というタグがついたアイテムを使った場合だけ石が釣れるようにします。

まず、datapack内にデフォルトの釣りのルートテーブルをコピーしておきます。
今回は<data/test/loot_tables/fishing.json>にコピーしておいたものとします。

そして、以下のようにデフォルトの釣りのルートテーブルを書き換えます。

fishing.json

{
  "type": "minecraft:fishing",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:alternatives",
          "children": [
            {
              "type": "minecraft:item",
              "name": "minecraft:stone",
              "conditions": [
                {
                  "condition": "minecraft:match_tool",
                  "predicate": {
                    "nbt": "{sugoi_turizao:1}"
                  }
                }
              ]
            },
            {
              "type": "minecraft:loot_table",
              "name": "test:fishing"
            }
          ]
        }
      ]
    }
  ]
}

"alternatives"というのは"children"の中に設定されている要素の中で上から順番に条件が当てはまるものを調べていき、一番最初に条件が当てはまったものを適用するというものになります。

今回であれば、釣りをしたプレイヤの使っていたアイテムに{sugoi_turizao:1}というタグがついていれば、石が釣れ、それ以外の場合であれば、別の場所にコピーしたデフォルトの釣りのルートテーブルを使用するようにしています。

このようにして、特定の釣竿で釣った場合だけ、別のアイテムが釣れるようにすることができます。

まとめ

このように釣りのルートテーブルを編集することで、モブが釣れるようにしたり、特定の釣竿を使った場合だけ別のアイテムを釣れるようにしたりすることができます。