Search in sources :

Example 1 with IResourceManager

use of net.minecraft.client.resources.IResourceManager in project Charset by CharsetMC.

the class WordImage method autosize.

private void autosize() {
    Pair<Integer, Integer> cached = size_cache.get(resource);
    if (cached != null) {
        width = cached.getLeft();
        height = cached.getRight();
        return;
    }
    IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
    try {
        IResource iresource = resourceManager.getResource(resource);
        BufferedImage bufferedimage = TextureUtil.readBufferedImage(iresource.getInputStream());
        this.width = bufferedimage.getWidth();
        this.height = bufferedimage.getHeight();
        size_cache.put(resource, Pair.of(width, height));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IResourceManager(net.minecraft.client.resources.IResourceManager) IOException(java.io.IOException) IResource(net.minecraft.client.resources.IResource) BufferedImage(java.awt.image.BufferedImage)

Example 2 with IResourceManager

use of net.minecraft.client.resources.IResourceManager in project Tropicraft by Tropicraft.

the class UtilBuild method getContentsFromResourceLocation.

public static String getContentsFromResourceLocation(ResourceLocation resourceLocation) {
    try {
        IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
        IResource iresource = resourceManager.getResource(resourceLocation);
        String contents = IOUtils.toString(iresource.getInputStream(), StandardCharsets.UTF_8);
        return contents;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return "";
}
Also used : IResourceManager(net.minecraft.client.resources.IResourceManager) IResource(net.minecraft.client.resources.IResource)

Example 3 with IResourceManager

use of net.minecraft.client.resources.IResourceManager in project YABBA by LatvianModder.

the class YabbaClient method loadModelsAndSkins.

public static void loadModelsAndSkins() {
    TEXTURES.clear();
    MODELS.clear();
    SKINS.clear();
    ALL_MODELS.clear();
    ALL_SKINS.clear();
    IResourceManager manager = ClientUtils.MC.getResourceManager();
    for (String domain : manager.getResourceDomains()) {
        try {
            for (IResource resource : manager.getAllResources(new ResourceLocation(domain, "yabba_models/_index.json"))) {
                for (JsonElement element : DataReader.get(resource).json().getAsJsonArray()) {
                    try {
                        JsonObject modelFile = DataReader.get(manager.getResource(new ResourceLocation(domain, "yabba_models/" + element.getAsString() + ".json"))).json().getAsJsonObject();
                        BarrelModel model = new BarrelModel(new ResourceLocation(domain, element.getAsString()), modelFile);
                        MODELS.put(model.id, model);
                        for (TextureSet textureSet : model.textures.values()) {
                            TEXTURES.addAll(textureSet.getTextures());
                        }
                    } catch (Exception ex1) {
                    }
                }
            }
        } catch (Exception ex) {
            if (!(ex instanceof FileNotFoundException)) {
                ex.printStackTrace();
            }
        }
        try {
            for (IResource resource : manager.getAllResources(new ResourceLocation(domain, "yabba_models/_skins.json"))) {
                parseSkinsJson(DataReader.get(resource).json().getAsJsonArray());
                VARIABLES.clear();
            }
        } catch (Exception ex) {
            if (!(ex instanceof FileNotFoundException)) {
                ex.printStackTrace();
            }
        }
    }
    for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) {
        FluidStack stack = new FluidStack(fluid, 1000);
        String displayName = stack.getLocalizedName();
        Color4I color = Color4I.rgba(fluid.getColor(stack));
        if (color.equals(Color4I.WHITE)) {
            color = Icon.EMPTY;
        }
        ResourceLocation still = fluid.getStill(stack);
        BarrelSkin skin = new BarrelSkin(fluid.getName() + "_still", TextureSet.of("all=" + still));
        skin.displayName = StringUtils.translate("lang.fluid.still", displayName);
        skin.color = color;
        skin.layer = BlockRenderLayer.TRANSLUCENT;
        REGISTER_SKIN.addSkin(skin);
        ResourceLocation flowing = fluid.getFlowing(stack);
        if (!still.equals(flowing)) {
            skin = new BarrelSkin(fluid.getName() + "_flowing", TextureSet.of("up&down=" + still + ",all=" + flowing));
            skin.displayName = StringUtils.translate("lang.fluid.flowing", displayName);
            skin.color = color;
            skin.layer = BlockRenderLayer.TRANSLUCENT;
            REGISTER_SKIN.addSkin(skin);
        }
    }
    new YabbaSkinsEvent(REGISTER_SKIN).post();
    for (BarrelSkin skin : SKINS.values()) {
        if (skin.displayName.isEmpty() && skin.state != CommonUtils.AIR_STATE) {
            try {
                skin.displayName = new ItemStack(skin.state.getBlock(), 1, skin.state.getBlock().getMetaFromState(skin.state)).getDisplayName();
            } catch (Exception ex) {
            }
        }
        if (skin.displayName.isEmpty() || skin.displayName.contains("air")) {
            skin.displayName = "";
        }
        if (skin.icon.isEmpty()) {
            skin.icon = ItemIcon.getItemIcon(((BlockItemBarrel) YabbaItems.ITEM_BARREL).createStack(YabbaItems.ITEM_BARREL.getDefaultState(), BarrelLook.get(Yabba.MOD_ID + ":block", skin.id), Tier.WOOD));
        }
    }
    ALL_MODELS.addAll(MODELS.values());
    DEFAULT_MODEL = MODELS.get(BarrelLook.DEFAULT_MODEL_ID);
    if (DEFAULT_MODEL == null) {
        DEFAULT_MODEL = ALL_MODELS.isEmpty() ? null : ALL_MODELS.get(0);
    }
    Yabba.LOGGER.info("Models: " + ALL_MODELS.size());
    if (FTBLibConfig.debugging.print_more_info) {
        for (BarrelModel model : ALL_MODELS) {
            Yabba.LOGGER.info("-- " + model.id + " :: " + model);
        }
    }
    ALL_SKINS.addAll(SKINS.values());
    ALL_SKINS.sort(StringUtils.ID_COMPARATOR);
    DEFAULT_SKIN = SKINS.get(BarrelLook.DEFAULT_SKIN_ID);
    if (DEFAULT_SKIN == null) {
        DEFAULT_SKIN = ALL_SKINS.isEmpty() ? null : ALL_SKINS.get(0);
    }
    Yabba.LOGGER.info("Skins: " + ALL_SKINS.size());
    if (FTBLibConfig.debugging.print_more_info) {
        for (BarrelSkin skin : ALL_SKINS) {
            Yabba.LOGGER.info("-- " + skin.id + " :: " + skin);
        }
    }
    for (BarrelModel model : ALL_MODELS) {
        model.icon = ItemIcon.getItemIcon(((BlockItemBarrel) YabbaItems.ITEM_BARREL).createStack(YabbaItems.ITEM_BARREL.getDefaultState(), BarrelLook.get(model.id, ""), Tier.WOOD));
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) FileNotFoundException(java.io.FileNotFoundException) JsonObject(com.google.gson.JsonObject) Color4I(com.feed_the_beast.ftblib.lib.icon.Color4I) YabbaSkinsEvent(com.latmod.yabba.api.YabbaSkinsEvent) FileNotFoundException(java.io.FileNotFoundException) TextureSet(com.feed_the_beast.ftblib.lib.util.misc.TextureSet) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) IResourceManager(net.minecraft.client.resources.IResourceManager) ItemStack(net.minecraft.item.ItemStack) IResource(net.minecraft.client.resources.IResource) BarrelSkin(com.latmod.yabba.api.BarrelSkin) BlockItemBarrel(com.latmod.yabba.block.BlockItemBarrel)

Example 4 with IResourceManager

use of net.minecraft.client.resources.IResourceManager 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)

Example 5 with IResourceManager

use of net.minecraft.client.resources.IResourceManager in project DynamicSurroundings by OreCruncher.

the class ProxyClient method postInit.

@Override
public void postInit(@Nonnull final FMLPostInitializationEvent event) {
    MusicTickerReplacement.initialize();
    // Register for resource load events
    final IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
    ((IReloadableResourceManager) resourceManager).registerReloadListener(this);
}
Also used : IReloadableResourceManager(net.minecraft.client.resources.IReloadableResourceManager) IResourceManager(net.minecraft.client.resources.IResourceManager) ParticleDripOverride(org.blockartistry.DynSurround.client.fx.particle.ParticleDripOverride)

Aggregations

IResourceManager (net.minecraft.client.resources.IResourceManager)14 IResource (net.minecraft.client.resources.IResource)8 ResourceLocation (net.minecraft.util.ResourceLocation)6 IOException (java.io.IOException)5 BufferedImage (java.awt.image.BufferedImage)4 IReloadableResourceManager (net.minecraft.client.resources.IReloadableResourceManager)3 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 ITheme (betterquesting.api.client.themes.ITheme)1 IThemeLoader (betterquesting.api.client.themes.IThemeLoader)1 StyleSheetManager (binnie.core.gui.resource.stylesheet.StyleSheetManager)1 ShaderLayer (blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer)1 IELogger (blusunrize.immersiveengineering.common.util.IELogger)1 RenderEngine (buildcraft.core.lib.engines.RenderEngine)1 IModelRegister (buildcraft.core.lib.utils.IModelRegister)1 RenderLaser (buildcraft.core.render.RenderLaser)1 RenderMarker (buildcraft.core.render.RenderMarker)1