Search in sources :

Example 1 with IThemeLoader

use of betterquesting.api.client.themes.IThemeLoader in project BetterQuesting by Funwayguy.

the class ThemeRegistry method reloadThemes.

@Override
public void reloadThemes() {
    resThemes.clear();
    IResourceManager resManager = Minecraft.getMinecraft().getResourceManager();
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    Iterator<String> iterator = resManager.getResourceDomains().iterator();
    while (iterator.hasNext()) {
        String domain = iterator.next();
        try {
            ResourceLocation res = new ResourceLocation(domain, "bq_themes.json");
            List<IResource> list = resManager.getAllResources(res);
            Iterator<IResource> iterator1 = list.iterator();
            while (iterator1.hasNext()) {
                IResource iresource = (IResource) iterator1.next();
                try {
                    InputStreamReader isr = new InputStreamReader(iresource.getInputStream());
                    JsonArray jAry = gson.fromJson(isr, JsonArray.class);
                    isr.close();
                    for (JsonElement je : jAry) {
                        if (je == null || !je.isJsonObject()) {
                            BetterQuesting.logger.log(Level.WARN, "Invalid theme in " + domain);
                            continue;
                        }
                        JsonObject jThm = je.getAsJsonObject();
                        ResourceLocation loadID = new ResourceLocation(JsonHelper.GetString(jThm, "themeType", "betterquesting:standard"));
                        IThemeLoader loader = getLoader(loadID);
                        if (loader == null) {
                            continue;
                        }
                        ITheme theme = loader.loadTheme(jThm, domain);
                        if (theme != null) {
                            resThemes.put(theme.getThemeID(), theme);
                        }
                    }
                } catch (Exception e) {
                    BetterQuesting.logger.log(Level.ERROR, "Error reading bq_themes.json from " + domain, e);
                }
            }
        } catch (Exception e) {
        }
    }
}
Also used : ITheme(betterquesting.api.client.themes.ITheme) InputStreamReader(java.io.InputStreamReader) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) IThemeLoader(betterquesting.api.client.themes.IThemeLoader) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) IResourceManager(net.minecraft.client.resources.IResourceManager) IResource(net.minecraft.client.resources.IResource)

Aggregations

ITheme (betterquesting.api.client.themes.ITheme)1 IThemeLoader (betterquesting.api.client.themes.IThemeLoader)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 InputStreamReader (java.io.InputStreamReader)1 IResource (net.minecraft.client.resources.IResource)1 IResourceManager (net.minecraft.client.resources.IResourceManager)1 ResourceLocation (net.minecraft.util.ResourceLocation)1