Search in sources :

Example 16 with IResource

use of net.minecraft.client.resources.IResource in project MorePlanets by SteveKunG.

the class OBJLoaderMP method loadModel.

@Override
public IModel loadModel(ResourceLocation modelLocation) throws IOException {
    IModel model = null;
    if (this.cache.containsKey(modelLocation)) {
        model = this.cache.get(modelLocation);
    } else {
        try {
            ResourceLocation file = new ResourceLocation(modelLocation.getNamespace(), "models/obj/" + modelLocation.getPath());
            IResource resource = this.manager.getResource(file);
            if (resource != null) {
                OBJModel.Parser parser = new OBJModel.Parser(resource, this.manager);
                try {
                    model = parser.parse().process(ImmutableMap.of("flip-v", "true"));
                } finally {
                    resource.getInputStream().close();
                    this.cache.put(modelLocation, model);
                }
            }
        } catch (IOException e) {
            throw e;
        }
    }
    if (model == null) {
        return ModelLoaderRegistry.getMissingModel();
    }
    return model;
}
Also used : IModel(net.minecraftforge.client.model.IModel) ResourceLocation(net.minecraft.util.ResourceLocation) IOException(java.io.IOException) OBJModel(net.minecraftforge.client.model.obj.OBJModel) IResource(net.minecraft.client.resources.IResource)

Example 17 with IResource

use of net.minecraft.client.resources.IResource in project MinecraftForge by MinecraftForge.

the class ModelBlockAnimation method loadVanillaAnimation.

/**
     * Load armature associated with a vanilla model.
     */
public static ModelBlockAnimation loadVanillaAnimation(IResourceManager manager, ResourceLocation armatureLocation) {
    try {
        IResource resource = null;
        try {
            resource = manager.getResource(armatureLocation);
        } catch (FileNotFoundException e) {
            // this is normal. FIXME: error reporting?
            return defaultModelBlockAnimation;
        }
        ModelBlockAnimation mba = mbaGson.fromJson(new InputStreamReader(resource.getInputStream(), "UTF-8"), ModelBlockAnimation.class);
        //String json = mbaGson.toJson(mba);
        return mba;
    } catch (IOException e) {
        FMLLog.log(Level.ERROR, e, "Exception loading vanilla model animation %s, skipping", armatureLocation);
        return defaultModelBlockAnimation;
    } catch (JsonParseException e) {
        FMLLog.log(Level.ERROR, e, "Exception loading vanilla model animation %s, skipping", armatureLocation);
        return defaultModelBlockAnimation;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) IResource(net.minecraft.client.resources.IResource)

Example 18 with IResource

use of net.minecraft.client.resources.IResource in project GregTech by GregTechCE.

the class MetaTileEntityRenderer method postInit.

public static void postInit() {
    try {
        IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation("models/block/block.json"));
        try (InputStreamReader reader = new InputStreamReader(resource.getInputStream())) {
            ModelBlock modelBlock = ModelBlock.deserialize(reader);
            for (TransformType transformType : TransformType.values()) {
                ItemTransformVec3f vec3f = modelBlock.getAllTransforms().getTransform(transformType);
                BLOCK_TRANSFORMS.put(transformType, new TRSRTransformation(vec3f));
            }
        }
    } catch (IOException exception) {
        GTLog.logger.error("Failed to load default block transforms", exception);
    }
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) InputStreamReader(java.io.InputStreamReader) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelBlock(net.minecraft.client.renderer.block.model.ModelBlock) ItemTransformVec3f(net.minecraft.client.renderer.block.model.ItemTransformVec3f) IOException(java.io.IOException) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType) IResource(net.minecraft.client.resources.IResource)

Example 19 with IResource

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

the class ColorPaletteParser method onTextureStitchPre.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onTextureStitchPre(TextureStitchEvent.Pre event) {
    this.data = null;
    try {
        for (IResource resource : Minecraft.getMinecraft().getResourceManager().getAllResources(COLOR_PALETTE_LOC)) {
            Data data = gson.fromJson(new InputStreamReader(resource.getInputStream()), Data.class);
            if (data.version != 1) {
                ModCharset.logger.warn("Unsupported version of color_palette.json found in " + resource.getResourcePackName() + " - not loaded.");
                continue;
            }
            if (this.data == null) {
                this.data = data;
            } else {
                this.data.add(data);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    MinecraftForge.EVENT_BUS.post(new ColorPaletteUpdateEvent(this));
}
Also used : InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) IResource(net.minecraft.client.resources.IResource) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 20 with IResource

use of net.minecraft.client.resources.IResource in project BuildCraft by BuildCraft.

the class ResourceLoaderContext method startLoading.

public InputStreamReader startLoading(ResourceLocation location) throws IOException {
    if (!loaded.add(location)) {
        throw new JsonSyntaxException("Already loaded " + location + " from " + loadingStack.peek());
    }
    loadingStack.push(location);
    IResource res = Minecraft.getMinecraft().getResourceManager().getResource(location);
    return new InputStreamReader(res.getInputStream(), StandardCharsets.UTF_8);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) InputStreamReader(java.io.InputStreamReader) IResource(net.minecraft.client.resources.IResource)

Aggregations

IResource (net.minecraft.client.resources.IResource)38 IOException (java.io.IOException)23 ResourceLocation (net.minecraft.util.ResourceLocation)21 InputStreamReader (java.io.InputStreamReader)12 BufferedImage (java.awt.image.BufferedImage)9 IResourceManager (net.minecraft.client.resources.IResourceManager)8 BufferedReader (java.io.BufferedReader)6 JsonObject (com.google.gson.JsonObject)3 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 Nullable (javax.annotation.Nullable)3 PngSizeInfo (net.minecraft.client.renderer.texture.PngSizeInfo)3 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)3 IModel (net.minecraftforge.client.model.IModel)3 JsonElement (com.google.gson.JsonElement)2 RasterFormatException (java.awt.image.RasterFormatException)2 Minecraft (net.minecraft.client.Minecraft)2 CrashReport (net.minecraft.crash.CrashReport)2 CrashReportCategory (net.minecraft.crash.CrashReportCategory)2 ReportedException (net.minecraft.util.ReportedException)2