public ResourcePack(string path) { Id = path; PackReader = CreatePackReader(path); Log.Info($"Opening resource pack `{path}`, pack reader type {PackReader.GetType().Name}"); if (!PackReader.FileExists("pack.mcmeta")) { throw new FormatException("pack.mcmeta doesn't exist"); } var packMetaRoot = JObject.Parse(PackReader.ReadTextFile("pack.mcmeta")); var packMetaScheme = new ObjectSchema { ["pack"] = new ObjectSchema { ["description"] = "string|object", ["pack_format"] = "number", }, ["language"] = new ObjectSchema() }; JsonValidator.ValidateWithException(packMetaRoot, packMetaScheme, "Invalid pack.mcmeta"); var packMeta = packMetaRoot.Value <JObject>("pack"); PackFormat = packMeta.Value <int>("pack_format"); var descriptionToken = packMeta["description"]; if (descriptionToken.Type == JTokenType.String) { Description = new StringComponent(descriptionToken.Value <string>()); } else { Description = TextComponent.FromJsonObject( packMeta["description"].Value <JObject>(), out string parseError); if (Description == null) { throw new FormatException($"Invalid pack.mcmeta - invalid description - {parseError}"); } } AdditionalLanguages = new List <Language>(); if (packMetaRoot.ContainsKey("language")) { var languagesTag = packMetaRoot["language"]; if (languagesTag.Type != JTokenType.Object) { throw new FormatException("Invalid pack.mcmeta - invalid type of language"); } foreach (var kv in languagesTag.Value <JObject>()) { var value = kv.Value.Value <JObject>(); var languageSchema = new ObjectSchema { ["name"] = "string", ["region"] = "string" }; JsonValidator.ValidateWithException(value, languageSchema, $"Invalid language {kv.Key}"); var language = new Language { Code = kv.Key, Name = value["name"].ToString(), Region = value["region"].ToString(), IsBidirectional = value.ContainsKey("bidirectional") && value.Value <bool>("bidirectional"), }; AdditionalLanguages.Add(language); } } }