Minecraftで進捗共有するデータパックを作る

# はじめに
Minecraftの全進捗解除をサバイバルで目指す有名実況者を見て、これを「自分でもしてみたい！」と思う方はたくさんいるでしょう。けれど1人でするのは辛いので、マルチプレイで、全進捗解除を目指したいと考えている方も居るでしょう。私もその1人でした。
そこで今回は、マルチプレイ中に、「誰か1人でも進捗を達成したら、その進捗は全員が達成したことにする」データパックを作っていこうと思います。

# 単一の進捗用の共有コマンドを作る
Minecraftのコマンドで一番良く使うコマンドは何でしょうか？正解は`execute`コマンドです（異論は認めない）。ということで、**「ある進捗を達成した人が居たら、未達成の全員にコマンドでその進捗を達成させる」** というコマンドを作成（例は進捗`minecraft:story/iron_tools`）すると、以下のようになります。

```
/execute if entity @a[advancements={story/iron_tools=true}] run advancement grant @a[advancements={story/iron_tools=false}] only story/iron_tools
```
これは、こちらのサイトを参考に作成しました。

https://minecraft.fandom.com/ja/wiki/%E3%82%BF%E3%83%BC%E3%82%B2%E3%83%83%E3%83%88%E3%82%BB%E3%83%AC%E3%82%AF%E3%82%BF%E3%83%BC#%E3%82%BF%E3%83%BC%E3%82%B2%E3%83%83%E3%83%88%E3%82%92%E9%80%B2%E6%8D%97%E3%81%A7%E7%B5%9E%E3%82%8A%E8%BE%BC%E3%82%80

# すべての進捗の共有コマンドを作る
上記のコマンドをリピートコマンドブロックにでも入力しておけば、単一の進捗なら共有できます。しかし、1つの進捗しか共有できないので、すべての進捗について、同様のコマンドを生成します。幸いにも、Minecraftの進捗IDは、こちらのページに掲載されていました。

https://minecraft.fandom.com/ja/wiki/%E9%80%B2%E6%8D%97#%E9%80%B2%E6%8D%97%E4%B8%80%E8%A6%A7

この進捗IDをよく見てみると以下のような名前空間に所属していることが分かります。
| 進捗のタブ | IDの名前空間 |
|:-:|:-:|
| Minecraft | `story/` |
| ネザー | `nether/` |
| ジ・エンド | `end/` |
| 冒険 | `adventure/` |
| 農業 | `husbandry/` |

そこで、JavaScriptを使って、すべての進捗IDを抜き出し、コマンドの形に整形してみます。

```javascript:
document.documentElement.innerHTML="<code style='white-space: nowrap;'>"+Array.from(document.getElementsByTagName("code")).filter(e=>!!e.innerText.match(/^(story\/|nether\/|end\/|adventure\/|husbandry\/)/)).map(e=>"execute if entity @a[advancements={"+e.innerText+"=true}] run advancement grant @a[advancements={"+e.innerText+"=false}] only "+e.innerText).join("<br>")+"</code>"
```

[前出のMinecraft Wiki](https://minecraft.fandom.com/ja/wiki/%E9%80%B2%E6%8D%97#%E9%80%B2%E6%8D%97%E4%B8%80%E8%A6%A7)のページに飛び、URL欄をすべて消した上で、`javascript:`と入力します。その後ろに上記のプログラムをコピーし、エンターキーを押します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/197285/9b203ce3-9693-5a42-87fc-26ea9cd4f4d8.png)

すると、すべての進捗を共有するコマンド群が生成されます。

<details><summary>2023/06/18時点での生成結果</summary>

```:main.mcfunction
execute if entity @a[advancements={story/root=true}] run advancement grant @a[advancements={story/root=false}] only story/root
execute if entity @a[advancements={story/mine_stone=true}] run advancement grant @a[advancements={story/mine_stone=false}] only story/mine_stone
execute if entity @a[advancements={story/upgrade_tools=true}] run advancement grant @a[advancements={story/upgrade_tools=false}] only story/upgrade_tools
execute if entity @a[advancements={story/smelt_iron=true}] run advancement grant @a[advancements={story/smelt_iron=false}] only story/smelt_iron
execute if entity @a[advancements={story/obtain_armor=true}] run advancement grant @a[advancements={story/obtain_armor=false}] only story/obtain_armor
execute if entity @a[advancements={story/lava_bucket=true}] run advancement grant @a[advancements={story/lava_bucket=false}] only story/lava_bucket
execute if entity @a[advancements={story/iron_tools=true}] run advancement grant @a[advancements={story/iron_tools=false}] only story/iron_tools
execute if entity @a[advancements={story/deflect_arrow=true}] run advancement grant @a[advancements={story/deflect_arrow=false}] only story/deflect_arrow
execute if entity @a[advancements={story/form_obsidian=true}] run advancement grant @a[advancements={story/form_obsidian=false}] only story/form_obsidian
execute if entity @a[advancements={story/mine_diamond=true}] run advancement grant @a[advancements={story/mine_diamond=false}] only story/mine_diamond
execute if entity @a[advancements={story/enter_the_nether=true}] run advancement grant @a[advancements={story/enter_the_nether=false}] only story/enter_the_nether
execute if entity @a[advancements={story/shiny_gear=true}] run advancement grant @a[advancements={story/shiny_gear=false}] only story/shiny_gear
execute if entity @a[advancements={story/enchant_item=true}] run advancement grant @a[advancements={story/enchant_item=false}] only story/enchant_item
execute if entity @a[advancements={story/cure_zombie_villager=true}] run advancement grant @a[advancements={story/cure_zombie_villager=false}] only story/cure_zombie_villager
execute if entity @a[advancements={story/follow_ender_eye=true}] run advancement grant @a[advancements={story/follow_ender_eye=false}] only story/follow_ender_eye
execute if entity @a[advancements={story/enter_the_end=true}] run advancement grant @a[advancements={story/enter_the_end=false}] only story/enter_the_end
execute if entity @a[advancements={nether/root=true}] run advancement grant @a[advancements={nether/root=false}] only nether/root
execute if entity @a[advancements={nether/return_to_sender=true}] run advancement grant @a[advancements={nether/return_to_sender=false}] only nether/return_to_sender
execute if entity @a[advancements={nether/find_bastion=true}] run advancement grant @a[advancements={nether/find_bastion=false}] only nether/find_bastion
execute if entity @a[advancements={nether/obtain_ancient_debris=true}] run advancement grant @a[advancements={nether/obtain_ancient_debris=false}] only nether/obtain_ancient_debris
execute if entity @a[advancements={nether/fast_travel=true}] run advancement grant @a[advancements={nether/fast_travel=false}] only nether/fast_travel
execute if entity @a[advancements={nether/find_fortress=true}] run advancement grant @a[advancements={nether/find_fortress=false}] only nether/find_fortress
execute if entity @a[advancements={nether/obtain_crying_obsidian=true}] run advancement grant @a[advancements={nether/obtain_crying_obsidian=false}] only nether/obtain_crying_obsidian
execute if entity @a[advancements={nether/distract_piglin=true}] run advancement grant @a[advancements={nether/distract_piglin=false}] only nether/distract_piglin
execute if entity @a[advancements={nether/ride_strider=true}] run advancement grant @a[advancements={nether/ride_strider=false}] only nether/ride_strider
execute if entity @a[advancements={nether/uneasy_alliance=true}] run advancement grant @a[advancements={nether/uneasy_alliance=false}] only nether/uneasy_alliance
execute if entity @a[advancements={nether/loot_bastion=true}] run advancement grant @a[advancements={nether/loot_bastion=false}] only nether/loot_bastion
execute if entity @a[advancements={nether/use_lodestone=true}] run advancement grant @a[advancements={nether/use_lodestone=false}] only nether/use_lodestone
execute if entity @a[advancements={nether/netherite_armor=true}] run advancement grant @a[advancements={nether/netherite_armor=false}] only nether/netherite_armor
execute if entity @a[advancements={nether/get_wither_skull=true}] run advancement grant @a[advancements={nether/get_wither_skull=false}] only nether/get_wither_skull
execute if entity @a[advancements={nether/obtain_blaze_rod=true}] run advancement grant @a[advancements={nether/obtain_blaze_rod=false}] only nether/obtain_blaze_rod
execute if entity @a[advancements={nether/charge_respawn_anchor=true}] run advancement grant @a[advancements={nether/charge_respawn_anchor=false}] only nether/charge_respawn_anchor
execute if entity @a[advancements={nether/ride_strider_in_overworld_lava=true}] run advancement grant @a[advancements={nether/ride_strider_in_overworld_lava=false}] only nether/ride_strider_in_overworld_lava
execute if entity @a[advancements={nether/explore_nether=true}] run advancement grant @a[advancements={nether/explore_nether=false}] only nether/explore_nether
execute if entity @a[advancements={nether/summon_wither=true}] run advancement grant @a[advancements={nether/summon_wither=false}] only nether/summon_wither
execute if entity @a[advancements={nether/brew_potion=true}] run advancement grant @a[advancements={nether/brew_potion=false}] only nether/brew_potion
execute if entity @a[advancements={nether/create_beacon=true}] run advancement grant @a[advancements={nether/create_beacon=false}] only nether/create_beacon
execute if entity @a[advancements={nether/all_potions=true}] run advancement grant @a[advancements={nether/all_potions=false}] only nether/all_potions
execute if entity @a[advancements={nether/create_full_beacon=true}] run advancement grant @a[advancements={nether/create_full_beacon=false}] only nether/create_full_beacon
execute if entity @a[advancements={nether/all_effects=true}] run advancement grant @a[advancements={nether/all_effects=false}] only nether/all_effects
execute if entity @a[advancements={end/root=true}] run advancement grant @a[advancements={end/root=false}] only end/root
execute if entity @a[advancements={end/kill_dragon=true}] run advancement grant @a[advancements={end/kill_dragon=false}] only end/kill_dragon
execute if entity @a[advancements={end/dragon_egg=true}] run advancement grant @a[advancements={end/dragon_egg=false}] only end/dragon_egg
execute if entity @a[advancements={end/enter_end_gateway=true}] run advancement grant @a[advancements={end/enter_end_gateway=false}] only end/enter_end_gateway
execute if entity @a[advancements={end/respawn_dragon=true}] run advancement grant @a[advancements={end/respawn_dragon=false}] only end/respawn_dragon
execute if entity @a[advancements={end/dragon_breath=true}] run advancement grant @a[advancements={end/dragon_breath=false}] only end/dragon_breath
execute if entity @a[advancements={end/find_end_city=true}] run advancement grant @a[advancements={end/find_end_city=false}] only end/find_end_city
execute if entity @a[advancements={end/elytra=true}] run advancement grant @a[advancements={end/elytra=false}] only end/elytra
execute if entity @a[advancements={end/levitate=true}] run advancement grant @a[advancements={end/levitate=false}] only end/levitate
execute if entity @a[advancements={adventure/root=true}] run advancement grant @a[advancements={adventure/root=false}] only adventure/root
execute if entity @a[advancements={adventure/voluntary_exile=true}] run advancement grant @a[advancements={adventure/voluntary_exile=false}] only adventure/voluntary_exile
execute if entity @a[advancements={adventure/spyglass_at_parrot=true}] run advancement grant @a[advancements={adventure/spyglass_at_parrot=false}] only adventure/spyglass_at_parrot
execute if entity @a[advancements={adventure/kill_a_mob=true}] run advancement grant @a[advancements={adventure/kill_a_mob=false}] only adventure/kill_a_mob
execute if entity @a[advancements={adventure/read_power_from_chiseled_bookshelf=true}] run advancement grant @a[advancements={adventure/read_power_from_chiseled_bookshelf=false}] only adventure/read_power_from_chiseled_bookshelf
execute if entity @a[advancements={adventure/trade=true}] run advancement grant @a[advancements={adventure/trade=false}] only adventure/trade
execute if entity @a[advancements={adventure/trim_with_any_armor_pattern=true}] run advancement grant @a[advancements={adventure/trim_with_any_armor_pattern=false}] only adventure/trim_with_any_armor_pattern
execute if entity @a[advancements={adventure/honey_block_slide=true}] run advancement grant @a[advancements={adventure/honey_block_slide=false}] only adventure/honey_block_slide
execute if entity @a[advancements={adventure/ol_besty=true}] run advancement grant @a[advancements={adventure/ol_besty=false}] only adventure/ol_besty
execute if entity @a[advancements={adventure/lightning_rod_with_villager_no_fire=true}] run advancement grant @a[advancements={adventure/lightning_rod_with_villager_no_fire=false}] only adventure/lightning_rod_with_villager_no_fire
execute if entity @a[advancements={adventure/kill_mob_near_sculk_catalyst=true}] run advancement grant @a[advancements={adventure/kill_mob_near_sculk_catalyst=false}] only adventure/kill_mob_near_sculk_catalyst
execute if entity @a[advancements={adventure/fall_from_world_height=true}] run advancement grant @a[advancements={adventure/fall_from_world_height=false}] only adventure/fall_from_world_height
execute if entity @a[advancements={adventure/salvage_sherd=true}] run advancement grant @a[advancements={adventure/salvage_sherd=false}] only adventure/salvage_sherd
execute if entity @a[advancements={adventure/avoid_vibration=true}] run advancement grant @a[advancements={adventure/avoid_vibration=false}] only adventure/avoid_vibration
execute if entity @a[advancements={adventure/sleep_in_bed=true}] run advancement grant @a[advancements={adventure/sleep_in_bed=false}] only adventure/sleep_in_bed
execute if entity @a[advancements={adventure/hero_of_the_village=true}] run advancement grant @a[advancements={adventure/hero_of_the_village=false}] only adventure/hero_of_the_village
execute if entity @a[advancements={adventure/spyglass_at_ghast=true}] run advancement grant @a[advancements={adventure/spyglass_at_ghast=false}] only adventure/spyglass_at_ghast
execute if entity @a[advancements={adventure/throw_trident=true}] run advancement grant @a[advancements={adventure/throw_trident=false}] only adventure/throw_trident
execute if entity @a[advancements={adventure/shoot_arrow=true}] run advancement grant @a[advancements={adventure/shoot_arrow=false}] only adventure/shoot_arrow
execute if entity @a[advancements={adventure/kill_all_mobs=true}] run advancement grant @a[advancements={adventure/kill_all_mobs=false}] only adventure/kill_all_mobs
execute if entity @a[advancements={adventure/totem_of_undying=true}] run advancement grant @a[advancements={adventure/totem_of_undying=false}] only adventure/totem_of_undying
execute if entity @a[advancements={adventure/summon_iron_golem=true}] run advancement grant @a[advancements={adventure/summon_iron_golem=false}] only adventure/summon_iron_golem
execute if entity @a[advancements={adventure/trade_at_world_height=true}] run advancement grant @a[advancements={adventure/trade_at_world_height=false}] only adventure/trade_at_world_height
execute if entity @a[advancements={adventure/trim_with_all_exclusive_armor_patterns=true}] run advancement grant @a[advancements={adventure/trim_with_all_exclusive_armor_patterns=false}] only adventure/trim_with_all_exclusive_armor_patterns
execute if entity @a[advancements={adventure/two_birds_one_arrow=true}] run advancement grant @a[advancements={adventure/two_birds_one_arrow=false}] only adventure/two_birds_one_arrow
execute if entity @a[advancements={adventure/whos_the_pillager_now=true}] run advancement grant @a[advancements={adventure/whos_the_pillager_now=false}] only adventure/whos_the_pillager_now
execute if entity @a[advancements={adventure/arbalistic=true}] run advancement grant @a[advancements={adventure/arbalistic=false}] only adventure/arbalistic
execute if entity @a[advancements={adventure/craft_decorated_pot_using_only_sherds=true}] run advancement grant @a[advancements={adventure/craft_decorated_pot_using_only_sherds=false}] only adventure/craft_decorated_pot_using_only_sherds
execute if entity @a[advancements={adventure/adventuring_time=true}] run advancement grant @a[advancements={adventure/adventuring_time=false}] only adventure/adventuring_time
execute if entity @a[advancements={adventure/play_jukebox_in_meadows=true}] run advancement grant @a[advancements={adventure/play_jukebox_in_meadows=false}] only adventure/play_jukebox_in_meadows
execute if entity @a[advancements={adventure/walk_on_powder_snow_with_leather_boots=true}] run advancement grant @a[advancements={adventure/walk_on_powder_snow_with_leather_boots=false}] only adventure/walk_on_powder_snow_with_leather_boots
execute if entity @a[advancements={adventure/spyglass_at_dragon=true}] run advancement grant @a[advancements={adventure/spyglass_at_dragon=false}] only adventure/spyglass_at_dragon
execute if entity @a[advancements={adventure/very_very_frightening=true}] run advancement grant @a[advancements={adventure/very_very_frightening=false}] only adventure/very_very_frightening
execute if entity @a[advancements={adventure/sniper_duel=true}] run advancement grant @a[advancements={adventure/sniper_duel=false}] only adventure/sniper_duel
execute if entity @a[advancements={adventure/bullseye=true}] run advancement grant @a[advancements={adventure/bullseye=false}] only adventure/bullseye
execute if entity @a[advancements={husbandry/root=true}] run advancement grant @a[advancements={husbandry/root=false}] only husbandry/root
execute if entity @a[advancements={husbandry/safely_harvest_honey=true}] run advancement grant @a[advancements={husbandry/safely_harvest_honey=false}] only husbandry/safely_harvest_honey
execute if entity @a[advancements={husbandry/breed_an_animal=true}] run advancement grant @a[advancements={husbandry/breed_an_animal=false}] only husbandry/breed_an_animal
execute if entity @a[advancements={husbandry/allay_deliver_item_to_player=true}] run advancement grant @a[advancements={husbandry/allay_deliver_item_to_player=false}] only husbandry/allay_deliver_item_to_player
execute if entity @a[advancements={husbandry/ride_a_boat_with_a_goat=true}] run advancement grant @a[advancements={husbandry/ride_a_boat_with_a_goat=false}] only husbandry/ride_a_boat_with_a_goat
execute if entity @a[advancements={husbandry/tame_an_animal=true}] run advancement grant @a[advancements={husbandry/tame_an_animal=false}] only husbandry/tame_an_animal
execute if entity @a[advancements={husbandry/make_a_sign_glow=true}] run advancement grant @a[advancements={husbandry/make_a_sign_glow=false}] only husbandry/make_a_sign_glow
execute if entity @a[advancements={husbandry/fishy_business=true}] run advancement grant @a[advancements={husbandry/fishy_business=false}] only husbandry/fishy_business
execute if entity @a[advancements={husbandry/silk_touch_nest=true}] run advancement grant @a[advancements={husbandry/silk_touch_nest=false}] only husbandry/silk_touch_nest
execute if entity @a[advancements={husbandry/tadpole_in_a_bucket=true}] run advancement grant @a[advancements={husbandry/tadpole_in_a_bucket=false}] only husbandry/tadpole_in_a_bucket
execute if entity @a[advancements={husbandry/obtain_sniffer_egg=true}] run advancement grant @a[advancements={husbandry/obtain_sniffer_egg=false}] only husbandry/obtain_sniffer_egg
execute if entity @a[advancements={husbandry/plant_seed=true}] run advancement grant @a[advancements={husbandry/plant_seed=false}] only husbandry/plant_seed
execute if entity @a[advancements={husbandry/wax_on=true}] run advancement grant @a[advancements={husbandry/wax_on=false}] only husbandry/wax_on
execute if entity @a[advancements={husbandry/bred_all_animals=true}] run advancement grant @a[advancements={husbandry/bred_all_animals=false}] only husbandry/bred_all_animals
execute if entity @a[advancements={husbandry/allay_deliver_cake_to_note_block=true}] run advancement grant @a[advancements={husbandry/allay_deliver_cake_to_note_block=false}] only husbandry/allay_deliver_cake_to_note_block
execute if entity @a[advancements={husbandry/complete_catalogue=true}] run advancement grant @a[advancements={husbandry/complete_catalogue=false}] only husbandry/complete_catalogue
execute if entity @a[advancements={husbandry/tactical_fishing=true}] run advancement grant @a[advancements={husbandry/tactical_fishing=false}] only husbandry/tactical_fishing
execute if entity @a[advancements={husbandry/leash_all_frog_variants=true}] run advancement grant @a[advancements={husbandry/leash_all_frog_variants=false}] only husbandry/leash_all_frog_variants
execute if entity @a[advancements={husbandry/feed_snifflet=true}] run advancement grant @a[advancements={husbandry/feed_snifflet=false}] only husbandry/feed_snifflet
execute if entity @a[advancements={husbandry/balanced_diet=true}] run advancement grant @a[advancements={husbandry/balanced_diet=false}] only husbandry/balanced_diet
execute if entity @a[advancements={husbandry/break_netherite_hoe=true}] run advancement grant @a[advancements={husbandry/break_netherite_hoe=false}] only husbandry/break_netherite_hoe
execute if entity @a[advancements={husbandry/wax_off=true}] run advancement grant @a[advancements={husbandry/wax_off=false}] only husbandry/wax_off
execute if entity @a[advancements={husbandry/froglights=true}] run advancement grant @a[advancements={husbandry/froglights=false}] only husbandry/froglights
execute if entity @a[advancements={husbandry/plant_any_sniffer_seed=true}] run advancement grant @a[advancements={husbandry/plant_any_sniffer_seed=false}] only husbandry/plant_any_sniffer_seed
execute if entity @a[advancements={husbandry/axolotl_in_a_bucket=true}] run advancement grant @a[advancements={husbandry/axolotl_in_a_bucket=false}] only husbandry/axolotl_in_a_bucket
execute if entity @a[advancements={husbandry/kill_axolotl_target=true}] run advancement grant @a[advancements={husbandry/kill_axolotl_target=false}] only husbandry/kill_axolotl_target
```
</details>

# データパックにする
ここまで出来たら、あとはデータパックにするだけです。

```
.
└─ advance
   ├─ data
   │  ├─ adv
   │  │  └─ functions
   │  │     └─ main.mcfunction
   │  └─ minecraft
   │     └─ tags
   │        └─ functions
   │           └─ tick.json
   └─ pack.mcmeta
```
適当に、こんな感じでフォルダを構成します。そして、pack.mcmetaとtick.jsonにこんな感じで書き込んで保存しておきます。

```json:pack.mcmeta
{
    "pack":{
        "pack_format":15,
        "description":"FUNCTIONS"
    }
}
```
```json:tick.json
{
    "values": ["adv:main"]
}
```
最後に、main.mcfunctionへ、先程得られた「すべての進捗を共有するコマンド群」をコピペして完了です。

# おわりに
Minecraftをしていると、JavaScriptも出来るようになるなんて、なんて教育的なゲームなのでしょうか。

　

以上。