Search in sources :

Example 6 with IResourceManager

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

the class CoreProxyClient method init.

@Override
public void init() {
    MinecraftForge.EVENT_BUS.register(RenderTickListener.INSTANCE);
    IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
    IReloadableResourceManager reloadable = (IReloadableResourceManager) resourceManager;
    reloadable.registerReloadListener(DetailedConfigOption.ReloadListener.INSTANCE);
    ClientRegistry.bindTileEntitySpecialRenderer(TileEngineBase.class, new RenderEngine());
    ClientRegistry.bindTileEntitySpecialRenderer(TilePathMarker.class, new RenderPathMarker());
    ClientRegistry.bindTileEntitySpecialRenderer(TileMarker.class, new RenderMarker());
    RenderingRegistry.registerEntityRenderingHandler(EntityResizableCuboid.class, RenderResizableCuboid.INSTANCE);
    RenderingRegistry.registerEntityRenderingHandler(EntityLaser.class, new RenderLaser());
    for (Block block : blocksToRegisterRenderersFor) {
        if (block instanceof IModelRegister) {
            ((IModelRegister) block).registerModels();
            continue;
        }
        IBlockState defaultState = block.getDefaultState();
        Multimap<Integer, IBlockState> metaStateMap = ArrayListMultimap.create();
        Map<IBlockState, String> stateTypeMap = Maps.newHashMap();
        for (IBlockState state : (List<IBlockState>) block.getBlockState().getValidStates()) {
            String type = BuildCraftStateMapper.getPropertyString(state);
            stateTypeMap.put(state, type);
            metaStateMap.put(block.damageDropped(state), state);
        }
        for (Entry<Integer, Collection<IBlockState>> entry : metaStateMap.asMap().entrySet()) {
            Collection<IBlockState> blockStates = entry.getValue();
            if (blockStates.isEmpty())
                continue;
            if (blockStates.contains(defaultState)) {
                registerBlockItemModel(defaultState, entry.getKey(), stateTypeMap.get(defaultState));
            } else {
                IBlockState state = blockStates.iterator().next();
                registerBlockItemModel(state, entry.getKey(), stateTypeMap.get(state));
            }
        }
    }
    for (Item item : itemsToRegisterRenderersFor) {
        if (item instanceof IModelRegister) {
            ((IModelRegister) item).registerModels();
        }
    }
}
Also used : RenderPathMarker(buildcraft.core.render.RenderPathMarker) IBlockState(net.minecraft.block.state.IBlockState) RenderLaser(buildcraft.core.render.RenderLaser) RenderMarker(buildcraft.core.render.RenderMarker) IModelRegister(buildcraft.core.lib.utils.IModelRegister) Item(net.minecraft.item.Item) IReloadableResourceManager(net.minecraft.client.resources.IReloadableResourceManager) Block(net.minecraft.block.Block) Collection(java.util.Collection) IResourceManager(net.minecraft.client.resources.IResourceManager) List(java.util.List) LinkedList(java.util.LinkedList) RenderEngine(buildcraft.core.lib.engines.RenderEngine)

Example 7 with IResourceManager

use of net.minecraft.client.resources.IResourceManager in project ImmersiveEngineering by BluSunrize.

the class IEShaderLayerCompositeTexture method loadTexture.

@Override
public void loadTexture(IResourceManager resourceManager) {
    this.deleteGlTexture();
    IResource iresource = null;
    BufferedImage bufferedimage;
    BufferedImage scaledImage;
    label255: {
        try {
            iresource = resourceManager.getResource(this.canvasTexture);
            BufferedImage canvasImage = TextureUtil.readBufferedImage(iresource.getInputStream());
            int imageType = canvasImage.getType();
            if (imageType == 0)
                imageType = 6;
            int canvasWidth = canvasImage.getWidth();
            int canvasHeight = canvasImage.getHeight();
            bufferedimage = new BufferedImage(canvasWidth, canvasHeight, imageType);
            int layer = 0;
            while (true) {
                if (layer >= 17 || layer >= this.layers.length)
                    break label255;
                IResource iresource1 = null;
                try {
                    String texPath = this.layers[layer].getTexture().getPath();
                    if (!texPath.startsWith("textures/"))
                        texPath = "textures/" + texPath;
                    if (!texPath.endsWith(".png"))
                        texPath += ".png";
                    String texture = this.layers[layer].getTexture().getNamespace() + ":" + texPath;
                    int colour = this.layers[layer].getColour();
                    iresource1 = resourceManager.getResource(new ResourceLocation(texture));
                    BufferedImage texureImage = TextureUtil.readBufferedImage(iresource1.getInputStream());
                    scaledImage = new BufferedImage(canvasWidth, canvasHeight, imageType);
                    float[] mod = { (colour >> 16 & 255) / 255f, (colour >> 8 & 255) / 255f, (colour & 255) / 255f, (colour >> 24 & 255) / 255f };
                    IntFunction<Integer> uInterpolate = uIn -> uIn;
                    IntFunction<Integer> vInterpolate = vIn -> vIn;
                    int bufImg2Size = Math.min(texureImage.getWidth(), texureImage.getHeight());
                    int uMin = 0;
                    int vMin = 0;
                    int uMax = canvasWidth;
                    int vMax = canvasHeight;
                    final double[] texBounds = this.layers[layer].getTextureBounds();
                    if (texBounds != null) {
                        final double uOffset = texBounds[0] * canvasWidth;
                        final double vOffset = texBounds[1] * canvasHeight;
                        final double uScale = bufImg2Size / ((texBounds[2] - texBounds[0]) * canvasWidth);
                        final double vScale = bufImg2Size / ((texBounds[3] - texBounds[1]) * canvasHeight);
                        uInterpolate = uIn -> (int) Math.round((uIn - uOffset) * uScale);
                        vInterpolate = vIn -> (int) Math.round((vIn - vOffset) * vScale);
                        uMin = (int) uOffset;
                        vMin = (int) vOffset;
                        uMax = (int) (texBounds[2] * canvasWidth);
                        vMax = (int) (texBounds[3] * canvasHeight);
                    }
                    try {
                        for (int v = vMin; v < vMax; ++v) for (int u = uMin; u < uMax; ++u) {
                            int interU = uInterpolate.apply(u) % bufImg2Size;
                            int interV = vInterpolate.apply(v) % bufImg2Size;
                            int iRGB = texureImage.getRGB(interU, interV);
                            float[] rgb = { (iRGB >> 16 & 255) / 255f, (iRGB >> 8 & 255) / 255f, (iRGB & 255) / 255f, (iRGB >> 24 & 255) / 255f };
                            if ((iRGB & -16777216) != 0) {
                                int iNoise = canvasImage.getRGB(u, v);
                                float[] noise = { (iNoise >> 16 & 255) / 255f, (iNoise >> 8 & 255) / 255f, (iNoise & 255) / 255f, (iNoise >> 24 & 255) / 255f };
                                for (int m = 0; m < 4; m++) rgb[m] = rgb[m] * mod[m] * noise[m];
                                int[] irgb = { (int) (rgb[0] * 255), (int) (rgb[1] * 255), (int) (rgb[2] * 255), (int) (rgb[3] * 255) };
                                int i2 = (irgb[0] << 16) + (irgb[1] << 8) + (irgb[2]) + (irgb[3] << 24);
                                scaledImage.setRGB(u, v, i2);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    bufferedimage.getGraphics().drawImage(scaledImage, 0, 0, null);
                } finally {
                    IOUtils.closeQuietly(iresource1);
                }
                ++layer;
            }
        } catch (IOException ioexception) {
            IELogger.error("Couldn't load layered image", ioexception);
        } finally {
            IOUtils.closeQuietly(iresource);
        }
        return;
    }
    TextureUtil.uploadTextureImage(this.getGlTextureId(), bufferedimage);
}
Also used : BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) IOUtils(org.apache.commons.io.IOUtils) AbstractTexture(net.minecraft.client.renderer.texture.AbstractTexture) TextureUtil(net.minecraft.client.renderer.texture.TextureUtil) Side(net.minecraftforge.fml.relauncher.Side) IELogger(blusunrize.immersiveengineering.common.util.IELogger) IResourceManager(net.minecraft.client.resources.IResourceManager) ResourceLocation(net.minecraft.util.ResourceLocation) ShaderLayer(blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) IResource(net.minecraft.client.resources.IResource) IntFunction(java.util.function.IntFunction) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) ResourceLocation(net.minecraft.util.ResourceLocation) IResource(net.minecraft.client.resources.IResource)

Example 8 with IResourceManager

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

the class ResourcePackHook method init.

public static void init() {
    IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
    Minecraft.getMinecraft().defaultResourcePacks.add(instance);
    if (resourceManager instanceof SimpleReloadableResourceManager) {
        ((SimpleReloadableResourceManager) resourceManager).registerReloadListener(instance);
    }
}
Also used : IResourceManager(net.minecraft.client.resources.IResourceManager) SimpleReloadableResourceManager(net.minecraft.client.resources.SimpleReloadableResourceManager)

Example 9 with IResourceManager

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

the class BlockForestryFluid method flowTextureExists.

@SideOnly(Side.CLIENT)
public boolean flowTextureExists() {
    try {
        ResourceLocation resourceLocation = new ResourceLocation(Defaults.ID, "textures/blocks/liquid/" + fluidName + "_flow.png");
        IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
        return resourceManager.getResource(resourceLocation) != null;
    } catch (java.lang.Exception e) {
        return false;
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) IResourceManager(net.minecraft.client.resources.IResourceManager) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 10 with IResourceManager

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

the class SpriteBuilder method addSprite.

/**
 * Performs simple addition of the current image and a new image, replacing old pixels with the new image if the
 * new image's alpha channel is greater than the given value.
 */
public SpriteBuilder addSprite(String location, final int minAlpha) {
    final ResourceLocation resLoc = new ResourceLocation(location);
    buildingActions.add(new ISpriteAction() {

        @Override
        public void apply(Graphics2D original, IResourceManager resourceManager) {
            BufferedImage image = getImage(resourceManager, resLoc);
            int multiplier = original.getClipBounds().width / image.getWidth();
            for (int x = 0; x < image.getWidth(); x++) {
                for (int y = 0; y < image.getHeight(); y++) {
                    int pixel = image.getRGB(x, y);
                    int alpha = (pixel >> 24) & 0xFF;
                    if (alpha < minAlpha)
                        continue;
                    int red = (pixel >> 16) & 0xFF;
                    int green = (pixel >> 8) & 0xFF;
                    int blue = pixel & 0xFF;
                    original.setColor(new Color(red, green, blue));
                    original.fillRect(x * multiplier, y * multiplier, multiplier, multiplier);
                }
            }
        }

        @Override
        public int getMinWidth(IResourceManager resourceManager) {
            return SpriteBuilder.getMinWidth(resourceManager, resLoc);
        }
    });
    return this;
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) Color(java.awt.Color) IResourceManager(net.minecraft.client.resources.IResourceManager) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

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