Search in sources :

Example 11 with IResourceManager

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

the class MetadataLoader method getData.

/**
 * @param samePack If true, then only the data
 * @return
 */
@Nullable
public static DataMetadataSection getData(ResourceLocation location, boolean samePack) {
    IResourceManager resManager = Minecraft.getMinecraft().getResourceManager();
    register();
    try {
        List<IResource> resources = resManager.getAllResources(location);
        DataMetadataSection section = null;
        for (IResource resource : resources) {
            section = resource.getMetadata(DataMetadataSection.SECTION_NAME);
            if (section != null || samePack) {
                break;
            }
        }
        for (IResource res : resources) {
            try {
                res.close();
            } catch (IOException io) {
                io.printStackTrace();
            }
        }
        return section;
    } catch (FileNotFoundException fnfe) {
        // That's fine
        return null;
    } catch (IOException e) {
        // That's not fine
        e.printStackTrace();
        return null;
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IResourceManager(net.minecraft.client.resources.IResourceManager) IOException(java.io.IOException) IResource(net.minecraft.client.resources.IResource) Nullable(javax.annotation.Nullable)

Example 12 with IResourceManager

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

the class ProxyClient method preInit.

@Override
public void preInit(@Nonnull final FMLPreInitializationEvent event) {
    super.preInit(event);
    // Extract the preset config files present in the JAR
    final IResourceManager manager = Minecraft.getMinecraft().getResourceManager();
    for (final String preset : presetFiles) {
        final String name = preset + ".presets";
        try {
            final IResource r = manager.getResource(new ResourceLocation(Presets.MOD_ID, "data/" + name));
            try (final InputStream stream = r.getInputStream()) {
                Streams.copy(stream, new File(Presets.dataDirectory(), name));
            }
        } catch (final Throwable t) {
            Presets.log().error("Unable to extract preset file " + name, t);
        }
    }
}
Also used : InputStream(java.io.InputStream) ResourceLocation(net.minecraft.util.ResourceLocation) IResourceManager(net.minecraft.client.resources.IResourceManager) File(java.io.File) IResource(net.minecraft.client.resources.IResource)

Example 13 with IResourceManager

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

the class ModelUtil method loadMultipartMBD.

private static ModelBlockDefinition loadMultipartMBD(ResourceLocation location, ResourceLocation fileIn) {
    List<ModelBlockDefinition> list = Lists.newArrayList();
    Minecraft mc = Minecraft.getMinecraft();
    IResourceManager manager = mc.getResourceManager();
    try {
        for (IResource resource : manager.getAllResources(fileIn)) {
            list.add(loadModelBlockDefinition(location, resource));
        }
    } catch (IOException e) {
        throw new RuntimeException("Encountered an exception when loading model definition of model " + fileIn, e);
    }
    return new ModelBlockDefinition(list);
}
Also used : ModelBlockDefinition(net.minecraft.client.renderer.block.model.ModelBlockDefinition) IResourceManager(net.minecraft.client.resources.IResourceManager) IOException(java.io.IOException) Minecraft(net.minecraft.client.Minecraft) IResource(net.minecraft.client.resources.IResource)

Example 14 with IResourceManager

use of net.minecraft.client.resources.IResourceManager in project Binnie by ForestryMC.

the class BinnieProxyClient method preInit.

@Override
public void preInit() {
    final IResourceManager manager = Minecraft.getMinecraft().getResourceManager();
    if (manager instanceof IReloadableResourceManager) {
        IReloadableResourceManager resourceManager = (IReloadableResourceManager) manager;
        resourceManager.registerReloadListener(new StyleSheetManager());
        resourceManager.registerReloadListener(resourceManager1 -> I18N.onResourceReload());
    }
}
Also used : IReloadableResourceManager(net.minecraft.client.resources.IReloadableResourceManager) StyleSheetManager(binnie.core.gui.resource.stylesheet.StyleSheetManager) IResourceManager(net.minecraft.client.resources.IResourceManager)

Example 15 with IResourceManager

use of net.minecraft.client.resources.IResourceManager in project Galacticraft by micdoodle8.

the class MapUtil method getOverworldImageFromRaw.

@SideOnly(Side.CLIENT)
public static void getOverworldImageFromRaw(int cx, int cz, byte[] raw) throws IOException {
    File folder = MapUtil.getClientMapsFolder();
    if (raw.length == OVERWORLD_LARGEMAP_WIDTH * OVERWORLD_LARGEMAP_HEIGHT * 2) {
        if (folder != null) {
            File file0 = new File(folder, "overworldRaw.bin");
            if (!file0.exists() || (file0.canRead() && file0.canWrite())) {
                FileUtils.writeByteArrayToFile(file0, raw);
            } else {
                System.err.println("Cannot write to file %minecraft%/assets/galacticraftMaps/overworldRaw.bin");
            }
        } else {
            System.err.println("No folder for file %minecraft%/assets/galacticraftMaps/overworldRaw.bin");
        }
        // raw is a WIDTH_WORLD x HEIGHT_WORLD array of 2 byte entries: biome type followed by height
        // Here we will make a texture from that, but twice as large: 4 pixels for each data point, it just looks better that way when the texture is used
        BufferedImage worldImageLarge = new BufferedImage(OVERWORLD_LARGEMAP_WIDTH * 2, OVERWORLD_LARGEMAP_HEIGHT * 2, BufferedImage.TYPE_INT_RGB);
        ArrayList<Integer> cols = new ArrayList<Integer>();
        int lastcol = -1;
        int idx = 0;
        for (int x = 0; x < OVERWORLD_LARGEMAP_WIDTH; x++) {
            for (int z = 0; z < OVERWORLD_LARGEMAP_HEIGHT; z++) {
                int arrayIndex = (x * OVERWORLD_LARGEMAP_HEIGHT + z) * 2;
                int biome = ((int) raw[arrayIndex]) & 255;
                int height = ((int) raw[arrayIndex + 1]) & 255;
                if (height < OCEAN_HEIGHT && biome != 2 && biome != 10) {
                    // Includes ponds, lakes and rivers in other biomes
                    biome = 0;
                }
                if (height < DEEP_OCEAN && biome == 0) {
                    biome = 24;
                }
                worldImageLarge.setRGB(x * 2, z * 2, convertBiomeColour(biome, height));
                worldImageLarge.setRGB(x * 2, z * 2 + 1, convertBiomeColour(biome, height));
                worldImageLarge.setRGB(x * 2 + 1, z * 2, convertBiomeColour(biome, height));
                worldImageLarge.setRGB(x * 2 + 1, z * 2 + 1, convertBiomeColour(biome, height));
            }
        }
        // Write it to a .jpg file on client for beta preview
        if (GalacticraftCore.enableJPEG && folder != null) {
            ImageOutputStream outputStream = new FileImageOutputStream(new File(folder, "large.jpg"));
            GalacticraftCore.jpgWriter.setOutput(outputStream);
            GalacticraftCore.jpgWriter.write(null, new IIOImage(worldImageLarge, null, null), GalacticraftCore.writeParam);
            outputStream.close();
        }
    } else // This is the dimensions of the Overworld texture map
    if (raw.length == OVERWORLD_TEXTURE_WIDTH * OVERWORLD_TEXTURE_HEIGHT * 2) {
        // raw is a WIDTH_STD x HEIGHT_STD array of 2 byte entries: biome type followed by height
        BufferedImage worldImage = new BufferedImage(OVERWORLD_TEXTURE_WIDTH, OVERWORLD_TEXTURE_HEIGHT, BufferedImage.TYPE_INT_RGB);
        ArrayList<Integer> cols = new ArrayList<Integer>();
        int lastcol = -1;
        int idx = 0;
        for (int x = 0; x < OVERWORLD_TEXTURE_WIDTH; x++) {
            for (int z = 0; z < OVERWORLD_TEXTURE_HEIGHT; z++) {
                int arrayIndex = (x * OVERWORLD_TEXTURE_HEIGHT + z) * 2;
                int biome = ((int) raw[arrayIndex]) & 255;
                int height = ((int) raw[arrayIndex + 1]) & 255;
                if (height < OCEAN_HEIGHT && biome != 2 && biome != 10) {
                    // Includes ponds, lakes and rivers in other biomes
                    biome = 0;
                }
                if (height < DEEP_OCEAN && biome == 0) {
                    biome = 24;
                }
                worldImage.setRGB(x, z, convertBiomeColour(biome, height));
            }
        }
        IResourceManager rm = Minecraft.getMinecraft().getResourceManager();
        BufferedImage paletteImage = null;
        try {
            InputStream in = rm.getResource(new ResourceLocation(Constants.ASSET_PREFIX, "textures/gui/celestialbodies/earth.png")).getInputStream();
            paletteImage = ImageIO.read(in);
            in.close();
            paletteImage.getHeight();
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        BufferedImage result = convertTo12pxTexture(worldImage, paletteImage);
        if (result != null) {
            if (ClientProxyCore.overworldTextureWide == null) {
                ClientProxyCore.overworldTextureWide = new DynamicTextureProper(OVERWORLD_TEXTURE_WIDTH, OVERWORLD_TEXTURE_HEIGHT);
            }
            if (ClientProxyCore.overworldTextureClient == null) {
                ClientProxyCore.overworldTextureClient = new DynamicTextureProper(OVERWORLD_TEXTURE_HEIGHT, OVERWORLD_TEXTURE_HEIGHT);
            }
            ClientProxyCore.overworldTextureWide.update(result);
            ClientProxyCore.overworldTextureClient.update(result);
            ClientProxyCore.overworldTexturesValid = true;
        }
    } else if (folder != null) {
        File file0 = makeFileName(folder, cx, cz);
        if (!file0.exists() || (file0.canRead() && file0.canWrite())) {
            FileUtils.writeByteArrayToFile(file0, raw);
        }
    } else {
        System.err.println("No folder %minecraft%/assets/galacticraftMaps for local map file.");
    }
}
Also used : FileImageOutputStream(javax.imageio.stream.FileImageOutputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) InputStream(java.io.InputStream) DynamicTextureProper(micdoodle8.mods.galacticraft.core.client.DynamicTextureProper) BufferedImage(java.awt.image.BufferedImage) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) ResourceLocation(net.minecraft.util.ResourceLocation) IResourceManager(net.minecraft.client.resources.IResourceManager) File(java.io.File) ImageOutputStream(javax.imageio.stream.ImageOutputStream) FileImageOutputStream(javax.imageio.stream.FileImageOutputStream) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

IResourceManager (net.minecraft.client.resources.IResourceManager)15 IResource (net.minecraft.client.resources.IResource)8 ResourceLocation (net.minecraft.util.ResourceLocation)7 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