文字列との間で TileEntity 定義を保存および復元する必要がある Minecraft Forge モジュールのコードをいくつか書いています。
TileEntity から String に変換するには、次を使用できます。
NBTCompoundTag nbt = new NBTCompoundTag();
TileEntity te = world.getTileEntity(x,y,z);
te.writeToNBT(nbt);
String nbtStr = nbt.toString();
ただし、文字列から TileEntitiy に変換するために、toString メソッド (ある種の NBT パーサー) の逆がありません。
String nbtStr;
NBTTagCompound nbtTag = new NBTTagCompound();
// this function does not exist
// nbtTag.parseString(nbtStr);
TileEntity te = TileEntity.createAndLoadEntity(nbtTag);
world.setTileEntity(x,y,z,te);
さまざまなドキュメントを検索しましたが、文字列表現を解析済みの NBTCompoundTag オブジェクトに変換できる関数が見つかりません。
私の質問は、NBT を保持する文字列で解析する方法は何ですか?