    001package net.minecraft.client.renderer;
    002
    003import cpw.mods.fml.client.TextureFXManager;
    004import cpw.mods.fml.common.FMLLog;
    005import cpw.mods.fml.relauncher.Side;
    006import cpw.mods.fml.relauncher.SideOnly;
    007import java.awt.Color;
    008import java.awt.Dimension;
    009import java.awt.Graphics;
    010import java.awt.image.BufferedImage;
    011import java.awt.image.ImageObserver;
    012import java.io.IOException;
    013import java.io.InputStream;
    014import java.nio.ByteBuffer;
    015import java.nio.IntBuffer;
    016import java.util.ArrayList;
    017import java.util.HashMap;
    018import java.util.Iterator;
    019import java.util.List;
    020import java.util.Map;
    021import java.util.logging.Level;
    022import java.util.logging.Logger;
    023
    024import javax.imageio.ImageIO;
    025import net.minecraft.client.renderer.texturefx.TextureFX;
    026import net.minecraft.client.settings.GameSettings;
    027import net.minecraft.client.texturepacks.ITexturePack;
    028import net.minecraft.client.texturepacks.TexturePackList;
    029import net.minecraft.util.IntHashMap;
    030import org.lwjgl.opengl.GL11;
    031
    032import net.minecraftforge.client.ForgeHooksClient;
    033
    034@SideOnly(Side.CLIENT)
    035public class RenderEngine
    036{
    037    private HashMap textureMap = new HashMap();
    038
    039    /** Texture contents map (key: texture name, value: int[] contents) */
    040    private HashMap textureContentsMap = new HashMap();
    041
    042    /** A mapping from GL texture names (integers) to BufferedImage instances */
    043    private IntHashMap textureNameToImageMap = new IntHashMap();
    044
    045    /** An IntBuffer storing 1 int used as scratch space in RenderEngine */
    046    private IntBuffer singleIntBuffer = GLAllocation.createDirectIntBuffer(1);
    047
    048    /** Stores the image data for the texture. */
    049    private ByteBuffer imageData = GLAllocation.createDirectByteBuffer(16777216);
    050    public List textureList = new ArrayList();
    051
    052    /** A mapping from image URLs to ThreadDownloadImageData instances */
    053    private Map urlToImageDataMap = new HashMap();
    054
    055    /** Reference to the GameSettings object */
    056    private GameSettings options;
    057
    058    /** Flag set when a texture should not be repeated */
    059    public boolean clampTexture = false;
    060
    061    /** Flag set when a texture should use blurry resizing */
    062    public boolean blurTexture = false;
    063
    064    /** Texture pack */
    065    public TexturePackList texturePack;
    066
    067    /** Missing texture image */
    068    private BufferedImage missingTextureImage = new BufferedImage(64, 64, 2);
    069
    070    public static Logger log = FMLLog.getLogger();
    071
    072    public RenderEngine(TexturePackList par1TexturePackList, GameSettings par2GameSettings)
    073    {
    074        this.texturePack = par1TexturePackList;
    075        this.options = par2GameSettings;
    076        Graphics var3 = this.missingTextureImage.getGraphics();
    077        var3.setColor(Color.WHITE);
    078        var3.fillRect(0, 0, 64, 64);
    079        var3.setColor(Color.BLACK);
    080        var3.drawString("missingtex", 1, 10);
    081        var3.dispose();
    082    }
    083
    084    public int[] getTextureContents(String par1Str)
    085    {
    086        ITexturePack var2 = this.texturePack.getSelectedTexturePack();
    087        int[] var3 = (int[])this.textureContentsMap.get(par1Str);
    088
    089        if (var3 != null)
    090        {
    091            return var3;
    092        }
    093        else
    094        {
    095            try
    096            {
    097                Object var4 = null;
    098                int[] var7;
    099
    100                if (par1Str.startsWith("##"))
    101                {
    102                    var7 = this.getImageContentsAndAllocate(this.unwrapImageByColumns(this.readTextureImage(var2.getResourceAsStream(par1Str.substring(2)))));
    103                }
    104                else if (par1Str.startsWith("%clamp%"))
    105                {
    106                    this.clampTexture = true;
    107                    var7 = this.getImageContentsAndAllocate(this.readTextureImage(var2.getResourceAsStream(par1Str.substring(7))));
    108                    this.clampTexture = false;
    109                }
    110                else if (par1Str.startsWith("%blur%"))
    111                {
    112                    this.blurTexture = true;
    113                    this.clampTexture = true;
    114                    var7 = this.getImageContentsAndAllocate(this.readTextureImage(var2.getResourceAsStream(par1Str.substring(6))));
    115                    this.clampTexture = false;
    116                    this.blurTexture = false;
    117                }
    118                else
    119                {
    120                    InputStream var8 = var2.getResourceAsStream(par1Str);
    121
    122                    if (var8 == null)
    123                    {
    124                        var7 = this.getImageContentsAndAllocate(this.missingTextureImage);
    125                    }
    126                    else
    127                    {
    128                        var7 = this.getImageContentsAndAllocate(this.readTextureImage(var8));
    129                    }
    130                }
    131
    132                this.textureContentsMap.put(par1Str, var7);
    133                return var7;
    134            }
    135            catch (Exception var6)
    136            {
    137                log.log(Level.INFO, String.format("An error occured reading texture file %s (getTexture)", par1Str), var6);
    138                var6.printStackTrace();
    139                int[] var5 = this.getImageContentsAndAllocate(this.missingTextureImage);
    140                this.textureContentsMap.put(par1Str, var5);
    141                return var5;
    142            }
    143        }
    144    }
    145
    146    private int[] getImageContentsAndAllocate(BufferedImage par1BufferedImage)
    147    {
    148        int var2 = par1BufferedImage.getWidth();
    149        int var3 = par1BufferedImage.getHeight();
    150        int[] var4 = new int[var2 * var3];
    151        par1BufferedImage.getRGB(0, 0, var2, var3, var4, 0, var2);
    152        return var4;
    153    }
    154
    155    private int[] getImageContents(BufferedImage par1BufferedImage, int[] par2ArrayOfInteger)
    156    {
    157        int var3 = par1BufferedImage.getWidth();
    158        int var4 = par1BufferedImage.getHeight();
    159        par1BufferedImage.getRGB(0, 0, var3, var4, par2ArrayOfInteger, 0, var3);
    160        return par2ArrayOfInteger;
    161    }
    162
    163    public int getTexture(String par1Str)
    164    {
    165        Integer var2 = (Integer)this.textureMap.get(par1Str);
    166
    167        if (var2 != null)
    168        {
    169            return var2.intValue();
    170        }
    171        else
    172        {
    173            ITexturePack var6 = this.texturePack.getSelectedTexturePack();
    174
    175            try
    176            {
    177                ForgeHooksClient.onTextureLoadPre(par1Str);
    178                this.singleIntBuffer.clear();
    179                GLAllocation.generateTextureNames(this.singleIntBuffer);
    180                int var3 = this.singleIntBuffer.get(0);
    181
    182                if (par1Str.startsWith("##"))
    183                {
    184                    this.setupTexture(this.unwrapImageByColumns(this.readTextureImage(var6.getResourceAsStream(par1Str.substring(2)))), var3);
    185                }
    186                else if (par1Str.startsWith("%clamp%"))
    187                {
    188                    this.clampTexture = true;
    189                    this.setupTexture(this.readTextureImage(var6.getResourceAsStream(par1Str.substring(7))), var3);
    190                    this.clampTexture = false;
    191                }
    192                else if (par1Str.startsWith("%blur%"))
    193                {
    194                    this.blurTexture = true;
    195                    this.setupTexture(this.readTextureImage(var6.getResourceAsStream(par1Str.substring(6))), var3);
    196                    this.blurTexture = false;
    197                }
    198                else if (par1Str.startsWith("%blurclamp%"))
    199                {
    200                    this.blurTexture = true;
    201                    this.clampTexture = true;
    202                    this.setupTexture(this.readTextureImage(var6.getResourceAsStream(par1Str.substring(11))), var3);
    203                    this.blurTexture = false;
    204                    this.clampTexture = false;
    205                }
    206                else
    207                {
    208                    InputStream var7 = var6.getResourceAsStream(par1Str);
    209
    210                    if (var7 == null)
    211                    {
    212                        this.setupTexture(this.missingTextureImage, var3);
    213                    }
    214                    else
    215                    {
    216                        BufferedImage loadedImage = this.readTextureImage(var7);
    217                        TextureFXManager.instance().fixTransparency(loadedImage, par1Str);
    218                        this.setupTexture(loadedImage, var3);
    219                    }
    220                }
    221
    222                this.textureMap.put(par1Str, Integer.valueOf(var3));
    223                ForgeHooksClient.onTextureLoad(par1Str, var6);
    224                return var3;
    225            }
    226            catch (Exception var5)
    227            {
    228                var5.printStackTrace();
    229                GLAllocation.generateTextureNames(this.singleIntBuffer);
    230                int var4 = this.singleIntBuffer.get(0);
    231                this.setupTexture(this.missingTextureImage, var4);
    232                this.textureMap.put(par1Str, Integer.valueOf(var4));
    233                return var4;
    234            }
    235        }
    236    }
    237
    238    /**
    239     * Takes an image with multiple 16-pixel-wide columns and creates a new 16-pixel-wide image where the columns are
    240     * stacked vertically
    241     */
    242    private BufferedImage unwrapImageByColumns(BufferedImage par1BufferedImage)
    243    {
    244        int var2 = par1BufferedImage.getWidth() / 16;
    245        BufferedImage var3 = new BufferedImage(16, par1BufferedImage.getHeight() * var2, 2);
    246        Graphics var4 = var3.getGraphics();
    247
    248        for (int var5 = 0; var5 < var2; ++var5)
    249        {
    250            var4.drawImage(par1BufferedImage, -var5 * 16, var5 * par1BufferedImage.getHeight(), (ImageObserver)null);
    251        }
    252
    253        var4.dispose();
    254        return var3;
    255    }
    256
    257    /**
    258     * Copy the supplied image onto a newly-allocated OpenGL texture, returning the allocated texture name
    259     */
    260    public int allocateAndSetupTexture(BufferedImage par1BufferedImage)
    261    {
    262        this.singleIntBuffer.clear();
    263        GLAllocation.generateTextureNames(this.singleIntBuffer);
    264        int var2 = this.singleIntBuffer.get(0);
    265        this.setupTexture(par1BufferedImage, var2);
    266        this.textureNameToImageMap.addKey(var2, par1BufferedImage);
    267        return var2;
    268    }
    269
    270    /**
    271     * Copy the supplied image onto the specified OpenGL texture
    272     */
    273    public void setupTexture(BufferedImage par1BufferedImage, int par2)
    274    {
    275        GL11.glBindTexture(GL11.GL_TEXTURE_2D, par2);
    276        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    277        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    278
    279        if (this.blurTexture)
    280        {
    281            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    282            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    283        }
    284
    285        if (this.clampTexture)
    286        {
    287            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
    288            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
    289        }
    290        else
    291        {
    292            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    293            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
    294        }
    295
    296        int var3 = par1BufferedImage.getWidth();
    297        int var4 = par1BufferedImage.getHeight();
    298        TextureFXManager.instance().setTextureDimensions(par2, var3, var4, (List<TextureFX>)textureList);
    299        int[] var5 = new int[var3 * var4];
    300        byte[] var6 = new byte[var3 * var4 * 4];
    301        par1BufferedImage.getRGB(0, 0, var3, var4, var5, 0, var3);
    302
    303        for (int var7 = 0; var7 < var5.length; ++var7)
    304        {
    305            int var8 = var5[var7] >> 24 & 255;
    306            int var9 = var5[var7] >> 16 & 255;
    307            int var10 = var5[var7] >> 8 & 255;
    308            int var11 = var5[var7] & 255;
    309
    310            if (this.options != null && this.options.anaglyph)
    311            {
    312                int var12 = (var9 * 30 + var10 * 59 + var11 * 11) / 100;
    313                int var13 = (var9 * 30 + var10 * 70) / 100;
    314                int var14 = (var9 * 30 + var11 * 70) / 100;
    315                var9 = var12;
    316                var10 = var13;
    317                var11 = var14;
    318            }
    319
    320            var6[var7 * 4 + 0] = (byte)var9;
    321            var6[var7 * 4 + 1] = (byte)var10;
    322            var6[var7 * 4 + 2] = (byte)var11;
    323            var6[var7 * 4 + 3] = (byte)var8;
    324        }
    325
    326        this.imageData.clear();
    327        this.imageData.put(var6);
    328        this.imageData.position(0).limit(var6.length);
    329        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, var3, var4, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.imageData);
    330    }
    331
    332    public void createTextureFromBytes(int[] par1ArrayOfInteger, int par2, int par3, int par4)
    333    {
    334        GL11.glBindTexture(GL11.GL_TEXTURE_2D, par4);
    335        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    336        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    337
    338        if (this.blurTexture)
    339        {
    340            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    341            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    342        }
    343
    344        if (this.clampTexture)
    345        {
    346            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
    347            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
    348        }
    349        else
    350        {
    351            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    352            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
    353        }
    354
    355        byte[] var5 = new byte[par2 * par3 * 4];
    356
    357        for (int var6 = 0; var6 < par1ArrayOfInteger.length; ++var6)
    358        {
    359            int var7 = par1ArrayOfInteger[var6] >> 24 & 255;
    360            int var8 = par1ArrayOfInteger[var6] >> 16 & 255;
    361            int var9 = par1ArrayOfInteger[var6] >> 8 & 255;
    362            int var10 = par1ArrayOfInteger[var6] & 255;
    363
    364            if (this.options != null && this.options.anaglyph)
    365            {
    366                int var11 = (var8 * 30 + var9 * 59 + var10 * 11) / 100;
    367                int var12 = (var8 * 30 + var9 * 70) / 100;
    368                int var13 = (var8 * 30 + var10 * 70) / 100;
    369                var8 = var11;
    370                var9 = var12;
    371                var10 = var13;
    372            }
    373
    374            var5[var6 * 4 + 0] = (byte)var8;
    375            var5[var6 * 4 + 1] = (byte)var9;
    376            var5[var6 * 4 + 2] = (byte)var10;
    377            var5[var6 * 4 + 3] = (byte)var7;
    378        }
    379
    380        this.imageData.clear();
    381        this.imageData.put(var5);
    382        this.imageData.position(0).limit(var5.length);
    383        GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, par2, par3, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.imageData);
    384    }
    385
    386    /**
    387     * Deletes a single GL texture
    388     */
    389    public void deleteTexture(int par1)
    390    {
    391        this.textureNameToImageMap.removeObject(par1);
    392        this.singleIntBuffer.clear();
    393        this.singleIntBuffer.put(par1);
    394        this.singleIntBuffer.flip();
    395        GL11.glDeleteTextures(this.singleIntBuffer);
    396    }
    397
    398    /**
    399     * Takes a URL of a downloadable image and the name of the local image to be used as a fallback.  If the image has
    400     * been downloaded, returns the GL texture of the downloaded image, otherwise returns the GL texture of the fallback
    401     * image.
    402     */
    403    public int getTextureForDownloadableImage(String par1Str, String par2Str)
    404    {
    405        ThreadDownloadImageData var3 = (ThreadDownloadImageData)this.urlToImageDataMap.get(par1Str);
    406
    407        if (var3 != null && var3.image != null && !var3.textureSetupComplete)
    408        {
    409            if (var3.textureName < 0)
    410            {
    411                var3.textureName = this.allocateAndSetupTexture(var3.image);
    412            }
    413            else
    414            {
    415                this.setupTexture(var3.image, var3.textureName);
    416            }
    417
    418            var3.textureSetupComplete = true;
    419        }
    420
    421        return var3 != null && var3.textureName >= 0 ? var3.textureName : (par2Str == null ? -1 : this.getTexture(par2Str));
    422    }
    423
    424    /**
    425     * Checks if urlToImageDataMap has image data for the given key
    426     */
    427    public boolean hasImageData(String par1Str)
    428    {
    429        return this.urlToImageDataMap.containsKey(par1Str);
    430    }
    431
    432    /**
    433     * Return a ThreadDownloadImageData instance for the given URL.  If it does not already exist, it is created and
    434     * uses the passed ImageBuffer.  If it does, its reference count is incremented.
    435     */
    436    public ThreadDownloadImageData obtainImageData(String par1Str, IImageBuffer par2IImageBuffer)
    437    {
    438        ThreadDownloadImageData var3 = (ThreadDownloadImageData)this.urlToImageDataMap.get(par1Str);
    439
    440        if (var3 == null)
    441        {
    442            this.urlToImageDataMap.put(par1Str, new ThreadDownloadImageData(par1Str, par2IImageBuffer));
    443        }
    444        else
    445        {
    446            ++var3.referenceCount;
    447        }
    448
    449        return var3;
    450    }
    451
    452    /**
    453     * Decrements the reference count for a given URL, deleting the image data if the reference count hits 0
    454     */
    455    public void releaseImageData(String par1Str)
    456    {
    457        ThreadDownloadImageData var2 = (ThreadDownloadImageData)this.urlToImageDataMap.get(par1Str);
    458
    459        if (var2 != null)
    460        {
    461            --var2.referenceCount;
    462
    463            if (var2.referenceCount == 0)
    464            {
    465                if (var2.textureName >= 0)
    466                {
    467                    this.deleteTexture(var2.textureName);
    468                }
    469
    470                this.urlToImageDataMap.remove(par1Str);
    471            }
    472        }
    473    }
    474
    475    public void registerTextureFX(TextureFX par1TextureFX)
    476    {
    477        TextureFXManager.instance().onPreRegisterEffect(par1TextureFX);
    478        this.textureList.add(par1TextureFX);
    479        par1TextureFX.onTick();
    480    }
    481
    482    public void updateDynamicTextures()
    483    {
    484        int var1 = -1;
    485
    486        for (int var2 = 0; var2 < this.textureList.size(); ++var2)
    487        {
    488            TextureFX var3 = (TextureFX)this.textureList.get(var2);
    489            var3.anaglyphEnabled = this.options.anaglyph;
    490            if (TextureFXManager.instance().onUpdateTextureEffect(var3))
    491            {
    492                var1 = this.updateDynamicTexture(var3, var1);
    493            }
    494        }
    495    }
    496
    497    /**
    498     * Updates a single dynamic texture
    499     */
    500    public int updateDynamicTexture(TextureFX par1TextureFX, int par2)
    501    {
    502        Dimension dim = TextureFXManager.instance().getTextureDimensions(par1TextureFX);
    503        int tWidth  = dim.width >> 4;
    504        int tHeight = dim.height >> 4;
    505        int tLen = tWidth * tHeight << 2;
    506
    507        if (par1TextureFX.imageData.length == tLen)
    508        {
    509            this.imageData.clear();
    510            this.imageData.put(par1TextureFX.imageData);
    511            this.imageData.position(0).limit(par1TextureFX.imageData.length);
    512        }
    513        else
    514        {
    515            TextureFXManager.instance().scaleTextureFXData(par1TextureFX.imageData, imageData, tWidth, tLen);
    516        }
    517
    518        if (par1TextureFX.textureId != par2)
    519        {
    520            par1TextureFX.bindImage(this);
    521            par2 = par1TextureFX.textureId;
    522        }
    523
    524        for (int var3 = 0; var3 < par1TextureFX.tileSize; ++var3)
    525        {
    526            int xOffset = par1TextureFX.iconIndex % 16 * tWidth + var3 * tWidth;
    527            for (int var4 = 0; var4 < par1TextureFX.tileSize; ++var4)
    528            {
    529                int yOffset = par1TextureFX.iconIndex / 16 * tHeight + var4 * tHeight;
    530                GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, xOffset, yOffset, tWidth, tHeight, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.imageData);
    531            }
    532        }
    533
    534        return par2;
    535    }
    536
    537    /**
    538     * Call setupTexture on all currently-loaded textures again to account for changes in rendering options
    539     */
    540    public void refreshTextures()
    541    {
    542        ITexturePack var1 = this.texturePack.getSelectedTexturePack();
    543        Iterator var2 = this.textureNameToImageMap.getKeySet().iterator();
    544        BufferedImage var4;
    545
    546        while (var2.hasNext())
    547        {
    548            int var3 = ((Integer)var2.next()).intValue();
    549            var4 = (BufferedImage)this.textureNameToImageMap.lookup(var3);
    550            this.setupTexture(var4, var3);
    551        }
    552
    553        ThreadDownloadImageData var8;
    554
    555        for (var2 = this.urlToImageDataMap.values().iterator(); var2.hasNext(); var8.textureSetupComplete = false)
    556        {
    557            var8 = (ThreadDownloadImageData)var2.next();
    558        }
    559
    560        var2 = this.textureMap.keySet().iterator();
    561        String var9;
    562
    563        while (var2.hasNext())
    564        {
    565            var9 = (String)var2.next();
    566
    567            try
    568            {
    569                if (var9.startsWith("##"))
    570                {
    571                    var4 = this.unwrapImageByColumns(this.readTextureImage(var1.getResourceAsStream(var9.substring(2))));
    572                }
    573                else if (var9.startsWith("%clamp%"))
    574                {
    575                    this.clampTexture = true;
    576                    var4 = this.readTextureImage(var1.getResourceAsStream(var9.substring(7)));
    577                }
    578                else if (var9.startsWith("%blur%"))
    579                {
    580                    this.blurTexture = true;
    581                    var4 = this.readTextureImage(var1.getResourceAsStream(var9.substring(6)));
    582                }
    583                else if (var9.startsWith("%blurclamp%"))
    584                {
    585                    this.blurTexture = true;
    586                    this.clampTexture = true;
    587                    var4 = this.readTextureImage(var1.getResourceAsStream(var9.substring(11)));
    588                }
    589                else
    590                {
    591                    var4 = this.readTextureImage(var1.getResourceAsStream(var9));
    592                }
    593
    594                int var5 = ((Integer)this.textureMap.get(var9)).intValue();
    595                this.setupTexture(var4, var5);
    596                this.blurTexture = false;
    597                this.clampTexture = false;
    598            }
    599            catch (Exception var7)
    600            {
    601                log.log(Level.INFO,String.format("An error occured reading texture file %s (refreshTexture)", var9), var7);
    602                var7.printStackTrace();
    603            }
    604        }
    605
    606        var2 = this.textureContentsMap.keySet().iterator();
    607
    608        while (var2.hasNext())
    609        {
    610            var9 = (String)var2.next();
    611
    612            try
    613            {
    614                if (var9.startsWith("##"))
    615                {
    616                    var4 = this.unwrapImageByColumns(this.readTextureImage(var1.getResourceAsStream(var9.substring(2))));
    617                }
    618                else if (var9.startsWith("%clamp%"))
    619                {
    620                    this.clampTexture = true;
    621                    var4 = this.readTextureImage(var1.getResourceAsStream(var9.substring(7)));
    622                }
    623                else if (var9.startsWith("%blur%"))
    624                {
    625                    this.blurTexture = true;
    626                    var4 = this.readTextureImage(var1.getResourceAsStream(var9.substring(6)));
    627                }
    628                else
    629                {
    630                    var4 = this.readTextureImage(var1.getResourceAsStream(var9));
    631                }
    632
    633                this.getImageContents(var4, (int[])this.textureContentsMap.get(var9));
    634                this.blurTexture = false;
    635                this.clampTexture = false;
    636            }
    637            catch (Exception var6)
    638            {
    639                log.log(Level.INFO,String.format("An error occured reading texture file data %s (refreshTexture)", var9), var6);
    640                var6.printStackTrace();
    641            }
    642        }
    643    }
    644
    645    /**
    646     * Returns a BufferedImage read off the provided input stream.  Args: inputStream
    647     */
    648    private BufferedImage readTextureImage(InputStream par1InputStream) throws IOException
    649    {
    650        BufferedImage var2 = ImageIO.read(par1InputStream);
    651        par1InputStream.close();
    652        return var2;
    653    }
    654
    655    public void bindTexture(int par1)
    656    {
    657        if (par1 >= 0)
    658        {
    659            GL11.glBindTexture(GL11.GL_TEXTURE_2D, par1);
    660        }
    661    }
    662}