3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Minecraft】ワールドデータの構成とか格納場所とか解析方法とか

Posted at

これとjqを使ってMinecraftのセーブデータを色々解析したときのメモ

前提

  • Ubuntu 18.04.3 LTS
  • bash

Minecraftサーバーの構成

Minecraftのセーブデータは、デフォルトではサーバーの実行ディレクトリ内にあるworldディレクトリに格納される。

  • サーバー/
    • config/
    • libraries/
    • world/
      • DIM-1/
      • DIM1/
      • advancements/
      • playerdata/
        • 12345678-1234-1234-1234-12345678ABCD.dat
        • 他...
      • region/
        • r.0.-1.mca
        • 他...
      • 他...
    • server.properties
    • eula.txt
    • usernamecache.json
    • 他...

以下では上記ツリーの「サーバー」をカレントディレクトリとする。

プレイヤー名⇔UUID

プレイヤーは、英数字の名前と長いUUIDを持っている。

この対応表はusernamecache.jsonにキャッシュされている。

$ cat usernamecache.json; echo
{
  "00000000-0000-0000-0000-000000000000": "Player0",
  "11111111-1111-1111-1111-111111111111": "Player1",
  "22222222-2222-2222-2222-222222222222": "Player2"
}
$ cat usernamecache.json | jq -r 'with_entries({"key":.value, "value": .key}).Player1'
11111111-1111-1111-1111-111111111111

その他、MojangのWebAPIからも拾ってこれるらしい。

プレイヤーデータ

プレイヤーデータは、world/playerdata/12345678-1234-1234-1234-12345678ABCD.datみたいな場所に格納されている。
ここで、12345678-1234-1234-1234-12345678ABCDは任意のプレイヤーのUUIDである。
UUIDはusernamecache.jsonからコマンドで調べられるので、コマンドだけでユーザー名からそのユーザーのステータスを出したりとかもできる。

以下はユーザー名のキャッシュが残っているすべてのプレイヤーのインベントリ(と装備とオフハンド)の中に直接入っている松明の個数を合計して出力するコマンドである。

bash
for entry in $(cat usernamecache.json | jq -c 'to_entries[] | [.key, .value]')
do
  uuid=$(echo $entry | jq -r '.[0]')
  name=$(echo $entry | jq -r '.[1]')
  count=$(cat world/playerdata/$uuid.dat | \
    inflate-gzip | \
    nbt2json -cp | \
    jq '.C.AInventory.values | [.[] | select(.Tid == "minecraft:torch").BCount] | add // 0')
  echo -e "$count\t$name"
done
3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?