Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 66.09 KB  |  hits: 43  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package net.minecraft.src;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Dimension;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.awt.RenderingHints;
  8. import java.awt.image.BufferedImage;
  9. import java.io.File;
  10. import java.io.FileInputStream;
  11. import java.io.IOException;
  12. import java.io.InputStream;
  13. import java.io.PrintStream;
  14. import java.nio.Buffer;
  15. import java.nio.ByteBuffer;
  16. import java.nio.IntBuffer;
  17. import java.util.ArrayList;
  18. import java.util.Collection;
  19. import java.util.Enumeration;
  20. import java.util.HashMap;
  21. import java.util.IdentityHashMap;
  22. import java.util.Iterator;
  23. import java.util.Map;
  24. import java.util.Properties;
  25. import java.util.Set;
  26. import java.util.zip.ZipEntry;
  27. import java.util.zip.ZipFile;
  28. import javax.imageio.ImageIO;
  29. import net.minecraft.client.Minecraft;
  30. import org.lwjgl.opengl.ContextCapabilities;
  31. import org.lwjgl.opengl.GL11;
  32. import org.lwjgl.opengl.GL12;
  33. import org.lwjgl.opengl.GLContext;
  34.  
  35. public class RenderEngine
  36. {
  37.     /** Use mipmaps for all bound textures (unused at present) */
  38.     public static boolean useMipmaps = true;
  39.     private HashMap textureMap;
  40.  
  41.     /** Texture contents map (key: texture name, value: int[] contents) */
  42.     private HashMap textureContentsMap;
  43.  
  44.     /** A mapping from GL texture names (integers) to BufferedImage instances */
  45.     private IntHashMap textureNameToImageMap;
  46.  
  47.     /** An IntBuffer storing 1 int used as scratch space in RenderEngine */
  48.     private IntBuffer singleIntBuffer;
  49.  
  50.     /** Stores the image data for the texture. */
  51.     private ByteBuffer imageData;
  52.     private java.util.List textureList;
  53.  
  54.     /** A mapping from image URLs to ThreadDownloadImageData instances */
  55.     private Map urlToImageDataMap;
  56.  
  57.     /** Reference to the GameSettings object */
  58.     private GameSettings options;
  59.  
  60.     /** Flag set when a texture should not be repeated */
  61.     public boolean clampTexture;
  62.  
  63.     /** Flag set when a texture should use blurry resizing */
  64.     public boolean blurTexture;
  65.  
  66.     /** Texture pack */
  67.     public TexturePackList texturePack;
  68.  
  69.     /** Missing texture image */
  70.     private BufferedImage missingTextureImage;
  71.     private int field_48512_n;
  72.     private int terrainTextureId;
  73.     private int guiItemsTextureId;
  74.     private int ctmTextureId;
  75.     private boolean hdTexturesInstalled;
  76.     private Map textureDimensionsMap;
  77.     private Map textureDataMap;
  78.     private int tickCounter;
  79.     private ByteBuffer mipImageDatas[];
  80.     private boolean dynamicTexturesUpdated;
  81.     private Map textureFxMap;
  82.     private Map mipDataBufsMap;
  83.     private Map customAnimationMap;
  84.     private CustomAnimation textureAnimations[];
  85.  
  86.     public RenderEngine(TexturePackList par1TexturePackList, GameSettings par2GameSettings)
  87.     {
  88.         terrainTextureId = -1;
  89.         guiItemsTextureId = -1;
  90.         ctmTextureId = -1;
  91.         hdTexturesInstalled = false;
  92.         textureDimensionsMap = new HashMap();
  93.         textureDataMap = new HashMap();
  94.         tickCounter = 0;
  95.         dynamicTexturesUpdated = false;
  96.         textureFxMap = new IdentityHashMap();
  97.         mipDataBufsMap = new HashMap();
  98.         customAnimationMap = new HashMap();
  99.         textureAnimations = null;
  100.         textureMap = new HashMap();
  101.         textureContentsMap = new HashMap();
  102.         textureNameToImageMap = new IntHashMap();
  103.         singleIntBuffer = GLAllocation.createDirectIntBuffer(1);
  104.         allocateImageData(256);
  105.         textureList = new ArrayList();
  106.         urlToImageDataMap = new HashMap();
  107.         clampTexture = false;
  108.         blurTexture = false;
  109.         missingTextureImage = new BufferedImage(64, 64, 2);
  110.         field_48512_n = 16;
  111.         texturePack = par1TexturePackList;
  112.         options = par2GameSettings;
  113.         Graphics g = missingTextureImage.getGraphics();
  114.         g.setColor(Color.WHITE);
  115.         g.fillRect(0, 0, 64, 64);
  116.         g.setColor(Color.BLACK);
  117.         g.drawString("missingtex", 1, 10);
  118.         g.dispose();
  119.     }
  120.  
  121.     public int[] getTextureContents(String par1Str)
  122.     {
  123.         TexturePackBase texturepackbase = texturePack.selectedTexturePack;
  124.         int ai[] = (int[])textureContentsMap.get(par1Str);
  125.  
  126.         if (ai != null)
  127.         {
  128.             return ai;
  129.         }
  130.  
  131.         try
  132.         {
  133.             int ai1[] = null;
  134.  
  135.             if (par1Str.startsWith("##"))
  136.             {
  137.                 ai1 = getImageContentsAndAllocate(unwrapImageByColumns(readTextureImage(texturepackbase.getResourceAsStream(par1Str.substring(2)))));
  138.             }
  139.             else if (par1Str.startsWith("%clamp%"))
  140.             {
  141.                 clampTexture = true;
  142.                 ai1 = getImageContentsAndAllocate(readTextureImage(texturepackbase.getResourceAsStream(par1Str.substring(7))));
  143.                 clampTexture = false;
  144.             }
  145.             else if (par1Str.startsWith("%blur%"))
  146.             {
  147.                 blurTexture = true;
  148.                 clampTexture = true;
  149.                 ai1 = getImageContentsAndAllocate(readTextureImage(texturepackbase.getResourceAsStream(par1Str.substring(6))));
  150.                 clampTexture = false;
  151.                 blurTexture = false;
  152.             }
  153.             else
  154.             {
  155.                 InputStream inputstream = texturepackbase.getResourceAsStream(par1Str);
  156.  
  157.                 if (inputstream == null)
  158.                 {
  159.                     ai1 = getImageContentsAndAllocate(missingTextureImage);
  160.                 }
  161.                 else
  162.                 {
  163.                     ai1 = getImageContentsAndAllocate(readTextureImage(inputstream));
  164.                 }
  165.             }
  166.  
  167.             textureContentsMap.put(par1Str, ai1);
  168.             return ai1;
  169.         }
  170.         catch (IOException ioexception)
  171.         {
  172.             ioexception.printStackTrace();
  173.         }
  174.  
  175.         int ai2[] = getImageContentsAndAllocate(missingTextureImage);
  176.         textureContentsMap.put(par1Str, ai2);
  177.         return ai2;
  178.     }
  179.  
  180.     private int[] getImageContentsAndAllocate(BufferedImage par1BufferedImage)
  181.     {
  182.         int i = par1BufferedImage.getWidth();
  183.         int j = par1BufferedImage.getHeight();
  184.         int ai[] = new int[i * j];
  185.         par1BufferedImage.getRGB(0, 0, i, j, ai, 0, i);
  186.         return ai;
  187.     }
  188.  
  189.     private int[] getImageContents(BufferedImage par1BufferedImage, int par2ArrayOfInteger[])
  190.     {
  191.         int i = par1BufferedImage.getWidth();
  192.         int j = par1BufferedImage.getHeight();
  193.         par1BufferedImage.getRGB(0, 0, i, j, par2ArrayOfInteger, 0, i);
  194.         return par2ArrayOfInteger;
  195.     }
  196.  
  197.     public int getTexture(String par1Str)
  198.     {
  199.         TexturePackBase texturepackbase = texturePack.selectedTexturePack;
  200.         Integer integer = (Integer)textureMap.get(par1Str);
  201.  
  202.         if (integer != null)
  203.         {
  204.             return integer.intValue();
  205.         }
  206.  
  207.         try
  208.         {
  209.             singleIntBuffer.clear();
  210.             GLAllocation.generateTextureNames(singleIntBuffer);
  211.  
  212.             if (Tessellator.renderingWorldRenderer)
  213.             {
  214.                 System.out.printf("Warning: Texture %s not preloaded, will cause render glitches!\n", new Object[]
  215.                         {
  216.                             par1Str
  217.                         });
  218.             }
  219.  
  220.             int i = singleIntBuffer.get(0);
  221.             Config.dbg((new StringBuilder()).append("setupTexture: \"").append(par1Str).append("\", id: ").append(i).toString());
  222.  
  223.             if (par1Str.startsWith("##"))
  224.             {
  225.                 setupTexture(unwrapImageByColumns(readTextureImage(texturepackbase.getResourceAsStream(par1Str.substring(2)))), i);
  226.             }
  227.             else if (par1Str.startsWith("%clamp%"))
  228.             {
  229.                 clampTexture = true;
  230.                 setupTexture(readTextureImage(texturepackbase.getResourceAsStream(par1Str.substring(7))), i);
  231.                 clampTexture = false;
  232.             }
  233.             else if (par1Str.startsWith("%blur%"))
  234.             {
  235.                 blurTexture = true;
  236.                 setupTexture(readTextureImage(texturepackbase.getResourceAsStream(par1Str.substring(6))), i);
  237.                 blurTexture = false;
  238.             }
  239.             else if (par1Str.startsWith("%blurclamp%"))
  240.             {
  241.                 blurTexture = true;
  242.                 clampTexture = true;
  243.                 setupTexture(readTextureImage(texturepackbase.getResourceAsStream(par1Str.substring(11))), i);
  244.                 blurTexture = false;
  245.                 clampTexture = false;
  246.             }
  247.             else
  248.             {
  249.                 InputStream inputstream = texturepackbase.getResourceAsStream(par1Str);
  250.  
  251.                 if (inputstream == null)
  252.                 {
  253.                     setupTexture(missingTextureImage, i);
  254.                 }
  255.                 else
  256.                 {
  257.                     if (par1Str.equals("/terrain.png"))
  258.                     {
  259.                         terrainTextureId = i;
  260.                     }
  261.  
  262.                     if (par1Str.equals("/gui/items.png"))
  263.                     {
  264.                         guiItemsTextureId = i;
  265.                     }
  266.  
  267.                     if (par1Str.equals("/ctm.png"))
  268.                     {
  269.                         ctmTextureId = i;
  270.                     }
  271.  
  272.                     setupTexture(readTextureImage(inputstream), i);
  273.                 }
  274.             }
  275.  
  276.             textureMap.put(par1Str, Integer.valueOf(i));
  277.  
  278.             if (Reflector.hasClass(1))
  279.             {
  280.                 Reflector.callVoid(18, new Object[]
  281.                         {
  282.                             par1Str, Integer.valueOf(i)
  283.                         });
  284.             }
  285.  
  286.             return i;
  287.         }
  288.         catch (Exception exception)
  289.         {
  290.             exception.printStackTrace();
  291.         }
  292.  
  293.         GLAllocation.generateTextureNames(singleIntBuffer);
  294.         int j = singleIntBuffer.get(0);
  295.         setupTexture(missingTextureImage, j);
  296.         textureMap.put(par1Str, Integer.valueOf(j));
  297.         return j;
  298.     }
  299.  
  300.     /**
  301.      * Takes an image with multiple 16-pixel-wide columns and creates a new 16-pixel-wide image where the columns are
  302.      * stacked vertically
  303.      */
  304.     private BufferedImage unwrapImageByColumns(BufferedImage par1BufferedImage)
  305.     {
  306.         int i = par1BufferedImage.getWidth() / 16;
  307.         BufferedImage bufferedimage = new BufferedImage(16, par1BufferedImage.getHeight() * i, 2);
  308.         Graphics g = bufferedimage.getGraphics();
  309.  
  310.         for (int j = 0; j < i; j++)
  311.         {
  312.             g.drawImage(par1BufferedImage, -j * 16, j * par1BufferedImage.getHeight(), null);
  313.         }
  314.  
  315.         g.dispose();
  316.         return bufferedimage;
  317.     }
  318.  
  319.     /**
  320.      * Copy the supplied image onto a newly-allocated OpenGL texture, returning the allocated texture name
  321.      */
  322.     public int allocateAndSetupTexture(BufferedImage par1BufferedImage)
  323.     {
  324.         singleIntBuffer.clear();
  325.         GLAllocation.generateTextureNames(singleIntBuffer);
  326.         int i = singleIntBuffer.get(0);
  327.         setupTexture(par1BufferedImage, i);
  328.         textureNameToImageMap.addKey(i, par1BufferedImage);
  329.         return i;
  330.     }
  331.  
  332.     /**
  333.      * Copy the supplied image onto the specified OpenGL texture
  334.      */
  335.     public void setupTexture(BufferedImage par1BufferedImage, int par2)
  336.     {
  337.         GL11.glBindTexture(GL11.GL_TEXTURE_2D, par2);
  338.         boolean flag = useMipmaps && Config.isUseMipmaps();
  339.  
  340.         if (flag && par2 != guiItemsTextureId)
  341.         {
  342.             int i = Config.getMipmapType();
  343.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, i);
  344.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
  345.  
  346.             if (GLContext.getCapabilities().OpenGL12)
  347.             {
  348.                 GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_BASE_LEVEL, 0);
  349.                 int k = Config.getMipmapLevel();
  350.  
  351.                 if (k >= 4)
  352.                 {
  353.                     int i1 = Math.min(par1BufferedImage.getWidth(), par1BufferedImage.getHeight());
  354.                     k = getMaxMipmapLevel(i1) - 4;
  355.  
  356.                     if (k < 0)
  357.                     {
  358.                         k = 0;
  359.                     }
  360.                 }
  361.  
  362.                 GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, k);
  363.             }
  364.         }
  365.         else
  366.         {
  367.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
  368.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
  369.         }
  370.  
  371.         if (blurTexture)
  372.         {
  373.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
  374.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
  375.         }
  376.  
  377.         if (clampTexture)
  378.         {
  379.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
  380.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
  381.         }
  382.         else
  383.         {
  384.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
  385.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
  386.         }
  387.  
  388.         int j = par1BufferedImage.getWidth();
  389.         int l = par1BufferedImage.getHeight();
  390.         setTextureDimension(par2, new Dimension(j, l));
  391.         int ai[] = new int[j * l];
  392.         byte abyte0[] = new byte[j * l * 4];
  393.         par1BufferedImage.getRGB(0, 0, j, l, ai, 0, j);
  394.         int ai1[] = new int[256];
  395.  
  396.         if (flag && isTerrainTexture(par2))
  397.         {
  398.             for (int j1 = 0; j1 < 16; j1++)
  399.             {
  400.                 for (int l1 = 0; l1 < 16; l1++)
  401.                 {
  402.                     ai1[j1 * 16 + l1] = getAverageOpaqueColor(ai, l1, j1, j, l);
  403.                 }
  404.             }
  405.         }
  406.  
  407.         for (int k1 = 0; k1 < ai.length; k1++)
  408.         {
  409.             int i2 = ai[k1] >> 24 & 0xff;
  410.             int j2 = ai[k1] >> 16 & 0xff;
  411.             int k2 = ai[k1] >> 8 & 0xff;
  412.             int l2 = ai[k1] & 0xff;
  413.  
  414.             if (options != null && options.anaglyph)
  415.             {
  416.                 int i3 = (j2 * 30 + k2 * 59 + l2 * 11) / 100;
  417.                 int k3 = (j2 * 30 + k2 * 70) / 100;
  418.                 int i4 = (j2 * 30 + l2 * 70) / 100;
  419.                 j2 = i3;
  420.                 k2 = k3;
  421.                 l2 = i4;
  422.             }
  423.  
  424.             if (i2 == 0)
  425.             {
  426.                 if (isTerrainTexture(par2))
  427.                 {
  428.                     j2 = 255;
  429.                     k2 = 255;
  430.                     l2 = 255;
  431.  
  432.                     if (flag)
  433.                     {
  434.                         int j3 = k1 % j;
  435.                         int l3 = k1 / j;
  436.                         int j4 = j3 / (j / 16);
  437.                         int k4 = l3 / (l / 16);
  438.                         int l4 = ai1[k4 * 16 + j4];
  439.  
  440.                         if (l4 != 0)
  441.                         {
  442.                             j2 = l4 >> 16 & 0xff;
  443.                             k2 = l4 >> 8 & 0xff;
  444.                             l2 = l4 & 0xff;
  445.                         }
  446.                     }
  447.                 }
  448.                 else
  449.                 {
  450.                     j2 = 0;
  451.                     k2 = 0;
  452.                     l2 = 0;
  453.                 }
  454.             }
  455.  
  456.             abyte0[k1 * 4 + 0] = (byte)j2;
  457.             abyte0[k1 * 4 + 1] = (byte)k2;
  458.             abyte0[k1 * 4 + 2] = (byte)l2;
  459.             abyte0[k1 * 4 + 3] = (byte)i2;
  460.         }
  461.  
  462.         checkImageDataSize(j);
  463.         imageData.clear();
  464.         imageData.put(abyte0);
  465.         imageData.position(0).limit(abyte0.length);
  466.         GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, j, l, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, imageData);
  467.  
  468.         if (useMipmaps)
  469.         {
  470.             generateMipMaps(imageData, j, l);
  471.         }
  472.     }
  473.  
  474.     private int getAverageOpaqueColor(int ai[], int i, int j, int k, int l)
  475.     {
  476.         int i1 = k / 16;
  477.         int j1 = l / 16;
  478.         int k1 = j * j1 * k + i * i1;
  479.         long l1 = 0L;
  480.         long l2 = 0L;
  481.         long l3 = 0L;
  482.         long l4 = 0L;
  483.  
  484.         for (int i2 = 0; i2 < j1; i2++)
  485.         {
  486.             for (int j2 = 0; j2 < i1; j2++)
  487.             {
  488.                 int i3 = k1 + i2 * k + j2;
  489.                 int k3 = ai[i3] >> 24 & 0xff;
  490.  
  491.                 if (k3 != 0)
  492.                 {
  493.                     int j4 = ai[i3] >> 16 & 0xff;
  494.                     int k4 = ai[i3] >> 8 & 0xff;
  495.                     int i5 = ai[i3] & 0xff;
  496.                     l1 += j4;
  497.                     l2 += k4;
  498.                     l3 += i5;
  499.                     l4++;
  500.                 }
  501.             }
  502.         }
  503.  
  504.         if (l4 <= 0L)
  505.         {
  506.             return 0;
  507.         }
  508.         else
  509.         {
  510.             char c = '\377';
  511.             int k2 = (int)(l1 / l4);
  512.             int j3 = (int)(l2 / l4);
  513.             int i4 = (int)(l3 / l4);
  514.             return c << 24 | k2 << 16 | j3 << 8 | i4;
  515.         }
  516.     }
  517.  
  518.     private boolean isTerrainTexture(int i)
  519.     {
  520.         if (i == terrainTextureId)
  521.         {
  522.             return true;
  523.         }
  524.  
  525.         return i == ctmTextureId;
  526.     }
  527.  
  528.     private void generateMipMaps(ByteBuffer bytebuffer, int i, int j)
  529.     {
  530.         ByteBuffer bytebuffer1 = bytebuffer;
  531.         int k = 1;
  532.  
  533.         do
  534.         {
  535.             if (k > 16)
  536.             {
  537.                 break;
  538.             }
  539.  
  540.             int l = i >> k - 1;
  541.             int i1 = i >> k;
  542.             int j1 = j >> k;
  543.  
  544.             if (i1 <= 0 || j1 <= 0)
  545.             {
  546.                 break;
  547.             }
  548.  
  549.             ByteBuffer bytebuffer2 = mipImageDatas[k - 1];
  550.             bytebuffer2.limit(i1 * j1 * 4);
  551.  
  552.             for (int k1 = 0; k1 < i1; k1++)
  553.             {
  554.                 for (int l1 = 0; l1 < j1; l1++)
  555.                 {
  556.                     int i2 = bytebuffer1.getInt((k1 * 2 + 0 + (l1 * 2 + 0) * l) * 4);
  557.                     int j2 = bytebuffer1.getInt((k1 * 2 + 1 + (l1 * 2 + 0) * l) * 4);
  558.                     int k2 = bytebuffer1.getInt((k1 * 2 + 1 + (l1 * 2 + 1) * l) * 4);
  559.                     int l2 = bytebuffer1.getInt((k1 * 2 + 0 + (l1 * 2 + 1) * l) * 4);
  560.                     int i3 = alphaBlend(i2, j2, k2, l2);
  561.                     bytebuffer2.putInt((k1 + l1 * i1) * 4, i3);
  562.                 }
  563.             }
  564.  
  565.             bytebuffer2.rewind();
  566.             GL11.glTexImage2D(GL11.GL_TEXTURE_2D, k, GL11.GL_RGBA, i1, j1, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, bytebuffer2);
  567.             bytebuffer1 = bytebuffer2;
  568.             k++;
  569.         }
  570.         while (true);
  571.     }
  572.  
  573.     public void createTextureFromBytes(int par1ArrayOfInteger[], int par2, int par3, int par4)
  574.     {
  575.         GL11.glBindTexture(GL11.GL_TEXTURE_2D, par4);
  576.  
  577.         if (useMipmaps && Config.isUseMipmaps())
  578.         {
  579.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
  580.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
  581.         }
  582.         else
  583.         {
  584.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
  585.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
  586.         }
  587.  
  588.         if (blurTexture)
  589.         {
  590.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
  591.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
  592.         }
  593.  
  594.         if (clampTexture)
  595.         {
  596.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
  597.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
  598.         }
  599.         else
  600.         {
  601.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
  602.             GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
  603.         }
  604.  
  605.         byte abyte0[] = new byte[par2 * par3 * 4];
  606.  
  607.         for (int i = 0; i < par1ArrayOfInteger.length; i++)
  608.         {
  609.             int j = par1ArrayOfInteger[i] >> 24 & 0xff;
  610.             int k = par1ArrayOfInteger[i] >> 16 & 0xff;
  611.             int l = par1ArrayOfInteger[i] >> 8 & 0xff;
  612.             int i1 = par1ArrayOfInteger[i] & 0xff;
  613.  
  614.             if (options != null && options.anaglyph)
  615.             {
  616.                 int j1 = (k * 30 + l * 59 + i1 * 11) / 100;
  617.                 int k1 = (k * 30 + l * 70) / 100;
  618.                 int l1 = (k * 30 + i1 * 70) / 100;
  619.                 k = j1;
  620.                 l = k1;
  621.                 i1 = l1;
  622.             }
  623.  
  624.             abyte0[i * 4 + 0] = (byte)k;
  625.             abyte0[i * 4 + 1] = (byte)l;
  626.             abyte0[i * 4 + 2] = (byte)i1;
  627.             abyte0[i * 4 + 3] = (byte)j;
  628.         }
  629.  
  630.         imageData.clear();
  631.         imageData.put(abyte0);
  632.         imageData.position(0).limit(abyte0.length);
  633.         GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, par2, par3, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, imageData);
  634.     }
  635.  
  636.     /**
  637.      * Deletes a single GL texture
  638.      */
  639.     public void deleteTexture(int par1)
  640.     {
  641.         textureNameToImageMap.removeObject(par1);
  642.         singleIntBuffer.clear();
  643.         singleIntBuffer.put(par1);
  644.         singleIntBuffer.flip();
  645.         GL11.glDeleteTextures(singleIntBuffer);
  646.     }
  647.  
  648.     /**
  649.      * Takes a URL of a downloadable image and the name of the local image to be used as a fallback.  If the image has
  650.      * been downloaded, returns the GL texture of the downloaded image, otherwise returns the GL texture of the fallback
  651.      * image.
  652.      */
  653.     public int getTextureForDownloadableImage(String par1Str, String par2Str)
  654.     {
  655.         if (Config.isRandomMobs())
  656.         {
  657.             int i = RandomMobs.getTexture(par1Str, par2Str);
  658.  
  659.             if (i >= 0)
  660.             {
  661.                 return i;
  662.             }
  663.         }
  664.  
  665.         ThreadDownloadImageData threaddownloadimagedata = (ThreadDownloadImageData)urlToImageDataMap.get(par1Str);
  666.  
  667.         if (threaddownloadimagedata != null && threaddownloadimagedata.image != null && !threaddownloadimagedata.textureSetupComplete)
  668.         {
  669.             if (threaddownloadimagedata.textureName < 0)
  670.             {
  671.                 threaddownloadimagedata.textureName = allocateAndSetupTexture(threaddownloadimagedata.image);
  672.             }
  673.             else
  674.             {
  675.                 setupTexture(threaddownloadimagedata.image, threaddownloadimagedata.textureName);
  676.             }
  677.  
  678.             threaddownloadimagedata.textureSetupComplete = true;
  679.         }
  680.  
  681.         if (threaddownloadimagedata == null || threaddownloadimagedata.textureName < 0)
  682.         {
  683.             if (par2Str == null)
  684.             {
  685.                 return -1;
  686.             }
  687.             else
  688.             {
  689.                 return getTexture(par2Str);
  690.             }
  691.         }
  692.         else
  693.         {
  694.             return threaddownloadimagedata.textureName;
  695.         }
  696.     }
  697.  
  698.     /**
  699.      * Return a ThreadDownloadImageData instance for the given URL.  If it does not already exist, it is created and
  700.      * uses the passed ImageBuffer.  If it does, its reference count is incremented.
  701.      */
  702.     public ThreadDownloadImageData obtainImageData(String par1Str, ImageBuffer par2ImageBuffer)
  703.     {
  704.         ThreadDownloadImageData threaddownloadimagedata = (ThreadDownloadImageData)urlToImageDataMap.get(par1Str);
  705.  
  706.         if (threaddownloadimagedata == null)
  707.         {
  708.             urlToImageDataMap.put(par1Str, new ThreadDownloadImageData(par1Str, par2ImageBuffer));
  709.         }
  710.         else
  711.         {
  712.             threaddownloadimagedata.referenceCount++;
  713.         }
  714.  
  715.         return threaddownloadimagedata;
  716.     }
  717.  
  718.     /**
  719.      * Decrements the reference count for a given URL, deleting the image data if the reference count hits 0
  720.      */
  721.     public void releaseImageData(String par1Str)
  722.     {
  723.         ThreadDownloadImageData threaddownloadimagedata = (ThreadDownloadImageData)urlToImageDataMap.get(par1Str);
  724.  
  725.         if (threaddownloadimagedata != null)
  726.         {
  727.             threaddownloadimagedata.referenceCount--;
  728.  
  729.             if (threaddownloadimagedata.referenceCount == 0)
  730.             {
  731.                 if (threaddownloadimagedata.textureName >= 0)
  732.                 {
  733.                     deleteTexture(threaddownloadimagedata.textureName);
  734.                 }
  735.  
  736.                 urlToImageDataMap.remove(par1Str);
  737.             }
  738.         }
  739.     }
  740.  
  741.     public void registerTextureFX(TextureFX par1TextureFX)
  742.     {
  743.         int i = getTextureId(par1TextureFX);
  744.  
  745.         for (int j = 0; j < textureList.size(); j++)
  746.         {
  747.             TextureFX texturefx = (TextureFX)textureList.get(j);
  748.             int k = getTextureId(texturefx);
  749.  
  750.             if (k == i && texturefx.iconIndex == par1TextureFX.iconIndex)
  751.             {
  752.                 textureList.remove(j);
  753.                 j--;
  754.                 Config.log((new StringBuilder()).append("TextureFX removed: ").append(texturefx).append(", texId: ").append(k).append(", index: ").append(texturefx.iconIndex).toString());
  755.             }
  756.         }
  757.  
  758.         if (par1TextureFX instanceof TextureHDFX)
  759.         {
  760.             TextureHDFX texturehdfx = (TextureHDFX)par1TextureFX;
  761.             texturehdfx.setTexturePackBase(texturePack.selectedTexturePack);
  762.             Dimension dimension = getTextureDimensions(i);
  763.  
  764.             if (dimension != null)
  765.             {
  766.                 texturehdfx.setTileWidth(dimension.width / 16);
  767.             }
  768.         }
  769.  
  770.         textureList.add(par1TextureFX);
  771.         par1TextureFX.onTick();
  772.         Config.log((new StringBuilder()).append("TextureFX registered: ").append(par1TextureFX).append(", texId: ").append(i).append(", index: ").append(par1TextureFX.iconIndex).toString());
  773.         dynamicTexturesUpdated = false;
  774.     }
  775.  
  776.     private int getTextureId(TextureFX texturefx)
  777.     {
  778.         Integer integer = (Integer)textureFxMap.get(texturefx);
  779.  
  780.         if (integer != null)
  781.         {
  782.             return integer.intValue();
  783.         }
  784.         else
  785.         {
  786.             int i = getBoundTexture();
  787.             texturefx.bindImage(this);
  788.             int j = getBoundTexture();
  789.             bindTexture(i);
  790.             textureFxMap.put(texturefx, new Integer(j));
  791.             return j;
  792.         }
  793.     }
  794.  
  795.     private int getBoundTexture()
  796.     {
  797.         int i = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
  798.         return i;
  799.     }
  800.  
  801.     private void generateMipMapsSub(int i, int j, int k, int l, ByteBuffer bytebuffer, int i1, boolean flag, String s)
  802.     {
  803.         ByteBuffer bytebuffer1 = bytebuffer;
  804.         byte abyte0[][] = (byte[][])null;
  805.  
  806.         if (s.length() > 0)
  807.         {
  808.             abyte0 = (byte[][])mipDataBufsMap.get(s);
  809.  
  810.             if (abyte0 == null)
  811.             {
  812.                 abyte0 = new byte[17][];
  813.                 mipDataBufsMap.put(s, abyte0);
  814.             }
  815.         }
  816.  
  817.         int j1 = 1;
  818.  
  819.         do
  820.         {
  821.             if (j1 > 16)
  822.             {
  823.                 break;
  824.             }
  825.  
  826.             int k1 = k >> j1 - 1;
  827.             int l1 = k >> j1;
  828.             int i2 = l >> j1;
  829.             int j2 = i >> j1;
  830.             int k2 = j >> j1;
  831.  
  832.             if (l1 <= 0 || i2 <= 0)
  833.             {
  834.                 break;
  835.             }
  836.  
  837.             ByteBuffer bytebuffer2 = mipImageDatas[j1 - 1];
  838.             bytebuffer2.limit(l1 * i2 * 4);
  839.             byte abyte1[] = null;
  840.  
  841.             if (abyte0 != null)
  842.             {
  843.                 abyte1 = abyte0[j1];
  844.             }
  845.  
  846.             if (abyte1 != null && abyte1.length != l1 * i2 * 4)
  847.             {
  848.                 abyte1 = null;
  849.             }
  850.  
  851.             if (abyte1 == null)
  852.             {
  853.                 if (abyte0 != null)
  854.                 {
  855.                     abyte1 = new byte[l1 * i2 * 4];
  856.                 }
  857.  
  858.                 for (int l2 = 0; l2 < l1; l2++)
  859.                 {
  860.                     for (int j3 = 0; j3 < i2; j3++)
  861.                     {
  862.                         int l3 = bytebuffer1.getInt((l2 * 2 + 0 + (j3 * 2 + 0) * k1) * 4);
  863.                         int j4 = bytebuffer1.getInt((l2 * 2 + 1 + (j3 * 2 + 0) * k1) * 4);
  864.                         int l4 = bytebuffer1.getInt((l2 * 2 + 1 + (j3 * 2 + 1) * k1) * 4);
  865.                         int i5 = bytebuffer1.getInt((l2 * 2 + 0 + (j3 * 2 + 1) * k1) * 4);
  866.                         int j5;
  867.  
  868.                         if (flag)
  869.                         {
  870.                             j5 = averageColor(averageColor(l3, j4), averageColor(l4, i5));
  871.                         }
  872.                         else
  873.                         {
  874.                             j5 = alphaBlend(l3, j4, l4, i5);
  875.                         }
  876.  
  877.                         bytebuffer2.putInt((l2 + j3 * l1) * 4, j5);
  878.                     }
  879.                 }
  880.  
  881.                 if (abyte0 != null)
  882.                 {
  883.                     bytebuffer2.rewind();
  884.                     bytebuffer2.get(abyte1);
  885.                     abyte0[j1] = abyte1;
  886.                 }
  887.             }
  888.  
  889.             if (abyte1 != null)
  890.             {
  891.                 bytebuffer2.rewind();
  892.                 bytebuffer2.put(abyte1);
  893.             }
  894.  
  895.             bytebuffer2.rewind();
  896.  
  897.             for (int i3 = 0; i3 < i1; i3++)
  898.             {
  899.                 for (int k3 = 0; k3 < i1; k3++)
  900.                 {
  901.                     int i4 = i3 * l1;
  902.                     int k4 = k3 * i2;
  903.                     GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, j1, j2 + i4, k2 + k4, l1, i2, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, bytebuffer2);
  904.                 }
  905.             }
  906.  
  907.             bytebuffer1 = bytebuffer2;
  908.             j1++;
  909.         }
  910.         while (true);
  911.     }
  912.  
  913.     public void updateDynamicTextures()
  914.     {
  915.         boolean flag = useMipmaps && Config.isUseMipmaps();
  916.         checkHdTextures();
  917.         tickCounter++;
  918.         terrainTextureId = getTexture("/terrain.png");
  919.         guiItemsTextureId = getTexture("/gui/items.png");
  920.         ctmTextureId = getTexture("/ctm.png");
  921.         StringBuffer stringbuffer = new StringBuffer();
  922.         int i = -1;
  923.         label0:
  924.  
  925.         for (int j = 0; j < textureList.size(); j++)
  926.         {
  927.             TextureFX texturefx = (TextureFX)textureList.get(j);
  928.             texturefx.anaglyphEnabled = options.anaglyph;
  929.  
  930.             if (texturefx.getClass().getName().equals("ModTextureStatic") && dynamicTexturesUpdated)
  931.             {
  932.                 continue;
  933.             }
  934.  
  935.             int l = getTextureId(texturefx);
  936.             Dimension dimension = getTextureDimensions(l);
  937.  
  938.             if (dimension == null)
  939.             {
  940.                 throw new IllegalArgumentException((new StringBuilder()).append("Unknown dimensions for texture id: ").append(l).toString());
  941.             }
  942.  
  943.             int j1 = dimension.width / 16;
  944.             int k1 = dimension.height / 16;
  945.             checkImageDataSize(dimension.width);
  946.             imageData.limit(0);
  947.             stringbuffer.setLength(0);
  948.             boolean flag3 = updateCustomTexture(texturefx, l, imageData, dimension.width / 16, stringbuffer);
  949.  
  950.             if (flag3 && imageData.limit() <= 0)
  951.             {
  952.                 continue;
  953.             }
  954.  
  955.             if (imageData.limit() <= 0)
  956.             {
  957.                 boolean flag4 = updateDefaultTexture(texturefx, l, imageData, dimension.width / 16, stringbuffer);
  958.  
  959.                 if (flag4 && imageData.limit() <= 0)
  960.                 {
  961.                     continue;
  962.                 }
  963.             }
  964.  
  965.             if (imageData.limit() <= 0)
  966.             {
  967.                 texturefx.onTick();
  968.  
  969.                 if (texturefx.imageData == null)
  970.                 {
  971.                     continue;
  972.                 }
  973.  
  974.                 int l1 = j1 * k1 * 4;
  975.  
  976.                 if (texturefx.imageData.length == l1)
  977.                 {
  978.                     imageData.clear();
  979.                     imageData.put(texturefx.imageData);
  980.                     imageData.position(0).limit(texturefx.imageData.length);
  981.                 }
  982.                 else
  983.                 {
  984.                     copyScaled(texturefx.imageData, imageData, j1);
  985.                 }
  986.             }
  987.  
  988.             if (l != i)
  989.             {
  990.                 texturefx.bindImage(this);
  991.                 i = l;
  992.             }
  993.  
  994.             boolean flag5 = scalesWithFastColor(texturefx);
  995.             int i2 = 0;
  996.  
  997.             do
  998.             {
  999.                 if (i2 >= texturefx.tileSize)
  1000.                 {
  1001.                     continue label0;
  1002.                 }
  1003.  
  1004.                 for (int j2 = 0; j2 < texturefx.tileSize; j2++)
  1005.                 {
  1006.                     int k2 = (texturefx.iconIndex % 16) * j1 + i2 * j1;
  1007.                     int l2 = (texturefx.iconIndex / 16) * k1 + j2 * k1;
  1008.                     GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, k2, l2, j1, k1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, imageData);
  1009.  
  1010.                     if (!flag || l == guiItemsTextureId)
  1011.                     {
  1012.                         continue;
  1013.                     }
  1014.  
  1015.                     String s = stringbuffer.toString();
  1016.  
  1017.                     if (i2 == 0 && j2 == 0)
  1018.                     {
  1019.                         generateMipMapsSub(k2, l2, j1, k1, imageData, texturefx.tileSize, flag5, s);
  1020.                     }
  1021.                 }
  1022.  
  1023.                 i2++;
  1024.             }
  1025.             while (true);
  1026.         }
  1027.  
  1028.         if (textureAnimations != null)
  1029.         {
  1030.             boolean flag1 = options.ofAnimatedTextures;
  1031.  
  1032.             for (int k = 0; k < textureAnimations.length; k++)
  1033.             {
  1034.                 CustomAnimation customanimation = textureAnimations[k];
  1035.                 int i1 = getTexture(customanimation.destTexture);
  1036.  
  1037.                 if (i1 < 0)
  1038.                 {
  1039.                     continue;
  1040.                 }
  1041.  
  1042.                 Dimension dimension1 = getTextureDimensions(i1);
  1043.  
  1044.                 if (dimension1 == null)
  1045.                 {
  1046.                     continue;
  1047.                 }
  1048.  
  1049.                 checkImageDataSize(dimension1.width);
  1050.                 imageData.limit(0);
  1051.                 stringbuffer.setLength(0);
  1052.                 boolean flag2 = customanimation.updateCustomTexture(imageData, flag1, dynamicTexturesUpdated, stringbuffer);
  1053.  
  1054.                 if ((!flag2 || imageData.limit() > 0) && imageData.limit() > 0)
  1055.                 {
  1056.                     bindTexture(i1);
  1057.                     GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, customanimation.destX, customanimation.destY, customanimation.frameWidth, customanimation.frameHeight, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, imageData);
  1058.                 }
  1059.             }
  1060.         }
  1061.  
  1062.         dynamicTexturesUpdated = true;
  1063.     }
  1064.  
  1065.     private int averageColor(int i, int j)
  1066.     {
  1067.         int k = (i & 0xff000000) >> 24 & 0xff;
  1068.         int l = (j & 0xff000000) >> 24 & 0xff;
  1069.         return ((k + l >> 1) << 24) + ((i & 0xfefefe) + (j & 0xfefefe) >> 1);
  1070.     }
  1071.  
  1072.     private int alphaBlend(int i, int j, int k, int l)
  1073.     {
  1074.         int i1 = alphaBlend(i, j);
  1075.         int j1 = alphaBlend(k, l);
  1076.         int k1 = alphaBlend(i1, j1);
  1077.         return k1;
  1078.     }
  1079.  
  1080.     /**
  1081.      * Uses the alpha of the two colors passed in to determine the contributions of each color.  If either of them has
  1082.      * an alpha greater than 0 then the returned alpha is 255 otherwise its zero if they are both zero. Args: color1,
  1083.      * color2
  1084.      */
  1085.     private int alphaBlend(int par1, int par2)
  1086.     {
  1087.         int i = (par1 & 0xff000000) >> 24 & 0xff;
  1088.         int j = (par2 & 0xff000000) >> 24 & 0xff;
  1089.         int k = (i + j) / 2;
  1090.  
  1091.         if (i == 0 && j == 0)
  1092.         {
  1093.             i = 1;
  1094.             j = 1;
  1095.         }
  1096.         else
  1097.         {
  1098.             if (i == 0)
  1099.             {
  1100.                 par1 = par2;
  1101.                 k /= 2;
  1102.             }
  1103.  
  1104.             if (j == 0)
  1105.             {
  1106.                 par2 = par1;
  1107.                 k /= 2;
  1108.             }
  1109.         }
  1110.  
  1111.         int l = (par1 >> 16 & 0xff) * i;
  1112.         int i1 = (par1 >> 8 & 0xff) * i;
  1113.         int j1 = (par1 & 0xff) * i;
  1114.         int k1 = (par2 >> 16 & 0xff) * j;
  1115.         int l1 = (par2 >> 8 & 0xff) * j;
  1116.         int i2 = (par2 & 0xff) * j;
  1117.         int j2 = (l + k1) / (i + j);
  1118.         int k2 = (i1 + l1) / (i + j);
  1119.         int l2 = (j1 + i2) / (i + j);
  1120.         return k << 24 | j2 << 16 | k2 << 8 | l2;
  1121.     }
  1122.  
  1123.     /**
  1124.      * Call setupTexture on all currently-loaded textures again to account for changes in rendering options
  1125.      */
  1126.     public void refreshTextures()
  1127.     {
  1128.         textureDataMap.clear();
  1129.         textureFxMap.clear();
  1130.         dynamicTexturesUpdated = false;
  1131.         Config.setTextureUpdateTime(System.currentTimeMillis());
  1132.         RandomMobs.resetTextures();
  1133.         mipDataBufsMap.clear();
  1134.         customAnimationMap.clear();
  1135.         TexturePackBase texturepackbase = texturePack.selectedTexturePack;
  1136.         int i;
  1137.         BufferedImage bufferedimage;
  1138.  
  1139.         for (Iterator iterator = textureNameToImageMap.getKeySet().iterator(); iterator.hasNext(); setupTexture(bufferedimage, i))
  1140.         {
  1141.             i = ((Integer)iterator.next()).intValue();
  1142.             bufferedimage = (BufferedImage)textureNameToImageMap.lookup(i);
  1143.         }
  1144.  
  1145.         for (Iterator iterator1 = urlToImageDataMap.values().iterator(); iterator1.hasNext();)
  1146.         {
  1147.             ThreadDownloadImageData threaddownloadimagedata = (ThreadDownloadImageData)iterator1.next();
  1148.             threaddownloadimagedata.textureSetupComplete = false;
  1149.         }
  1150.  
  1151.         Iterator iterator2 = textureMap.keySet().iterator();
  1152.  
  1153.         do
  1154.         {
  1155.             if (!iterator2.hasNext())
  1156.             {
  1157.                 break;
  1158.             }
  1159.  
  1160.             String s = (String)iterator2.next();
  1161.  
  1162.             try
  1163.             {
  1164.                 BufferedImage bufferedimage1;
  1165.  
  1166.                 if (s.startsWith("##"))
  1167.                 {
  1168.                     bufferedimage1 = unwrapImageByColumns(readTextureImage(texturepackbase.getResourceAsStream(s.substring(2))));
  1169.                 }
  1170.                 else if (s.startsWith("%clamp%"))
  1171.                 {
  1172.                     clampTexture = true;
  1173.                     bufferedimage1 = readTextureImage(texturepackbase.getResourceAsStream(s.substring(7)));
  1174.                 }
  1175.                 else if (s.startsWith("%blur%"))
  1176.                 {
  1177.                     blurTexture = true;
  1178.                     bufferedimage1 = readTextureImage(texturepackbase.getResourceAsStream(s.substring(6)));
  1179.                 }
  1180.                 else if (s.startsWith("%blurclamp%"))
  1181.                 {
  1182.                     blurTexture = true;
  1183.                     clampTexture = true;
  1184.                     bufferedimage1 = readTextureImage(texturepackbase.getResourceAsStream(s.substring(11)));
  1185.                 }
  1186.                 else
  1187.                 {
  1188.                     bufferedimage1 = readTextureImage(texturepackbase.getResourceAsStream(s));
  1189.                 }
  1190.  
  1191.                 int j = ((Integer)textureMap.get(s)).intValue();
  1192.                 setupTexture(bufferedimage1, j);
  1193.                 blurTexture = false;
  1194.                 clampTexture = false;
  1195.             }
  1196.             catch (Exception exception)
  1197.             {
  1198.                 if (!"input == null!".equals(exception.getMessage()))
  1199.                 {
  1200.                     exception.printStackTrace();
  1201.                 }
  1202.             }
  1203.         }
  1204.         while (true);
  1205.  
  1206.         iterator2 = textureContentsMap.keySet().iterator();
  1207.  
  1208.         do
  1209.         {
  1210.             if (!iterator2.hasNext())
  1211.             {
  1212.                 break;
  1213.             }
  1214.  
  1215.             String s1 = (String)iterator2.next();
  1216.  
  1217.             try
  1218.             {
  1219.                 BufferedImage bufferedimage2;
  1220.  
  1221.                 if (s1.startsWith("##"))
  1222.                 {
  1223.                     bufferedimage2 = unwrapImageByColumns(readTextureImage(texturepackbase.getResourceAsStream(s1.substring(2))));
  1224.                 }
  1225.                 else if (s1.startsWith("%clamp%"))
  1226.                 {
  1227.                     clampTexture = true;
  1228.                     bufferedimage2 = readTextureImage(texturepackbase.getResourceAsStream(s1.substring(7)));
  1229.                 }
  1230.                 else if (s1.startsWith("%blur%"))
  1231.                 {
  1232.                     blurTexture = true;
  1233.                     bufferedimage2 = readTextureImage(texturepackbase.getResourceAsStream(s1.substring(6)));
  1234.                 }
  1235.                 else
  1236.                 {
  1237.                     bufferedimage2 = readTextureImage(texturepackbase.getResourceAsStream(s1));
  1238.                 }
  1239.  
  1240.                 getImageContents(bufferedimage2, (int[])textureContentsMap.get(s1));
  1241.                 blurTexture = false;
  1242.                 clampTexture = false;
  1243.             }
  1244.             catch (Exception exception1)
  1245.             {
  1246.                 if (!"input == null!".equals(exception1.getMessage()))
  1247.                 {
  1248.                     exception1.printStackTrace();
  1249.                 }
  1250.             }
  1251.         }
  1252.         while (true);
  1253.  
  1254.         registerCustomTexturesFX();
  1255.         CustomColorizer.update(this);
  1256.         updateDynamicTextures();
  1257.     }
  1258.  
  1259.     /**
  1260.      * Returns a BufferedImage read off the provided input stream.  Args: inputStream
  1261.      */
  1262.     private BufferedImage readTextureImage(InputStream par1InputStream) throws IOException
  1263.     {
  1264.         BufferedImage bufferedimage = ImageIO.read(par1InputStream);
  1265.         par1InputStream.close();
  1266.         return bufferedimage;
  1267.     }
  1268.  
  1269.     public void bindTexture(int par1)
  1270.     {
  1271.         if (par1 < 0)
  1272.         {
  1273.             return;
  1274.         }
  1275.         else
  1276.         {
  1277.             GL11.glBindTexture(GL11.GL_TEXTURE_2D, par1);
  1278.             return;
  1279.         }
  1280.     }
  1281.  
  1282.     private void setTextureDimension(int i, Dimension dimension)
  1283.     {
  1284.         textureDimensionsMap.put(new Integer(i), dimension);
  1285.  
  1286.         if (i == terrainTextureId)
  1287.         {
  1288.             Config.setIconWidthTerrain(dimension.width / 16);
  1289.         }
  1290.  
  1291.         if (i == guiItemsTextureId)
  1292.         {
  1293.             Config.setIconWidthItems(dimension.width / 16);
  1294.         }
  1295.  
  1296.         updateDinamicTextures(i, dimension);
  1297.     }
  1298.  
  1299.     private Dimension getTextureDimensions(int i)
  1300.     {
  1301.         Dimension dimension = (Dimension)textureDimensionsMap.get(new Integer(i));
  1302.         return dimension;
  1303.     }
  1304.  
  1305.     private void updateDinamicTextures(int i, Dimension dimension)
  1306.     {
  1307.         for (int j = 0; j < textureList.size(); j++)
  1308.         {
  1309.             TextureFX texturefx = (TextureFX)textureList.get(j);
  1310.             int k = getTextureId(texturefx);
  1311.  
  1312.             if (k == i && (texturefx instanceof TextureHDFX))
  1313.             {
  1314.                 TextureHDFX texturehdfx = (TextureHDFX)texturefx;
  1315.                 texturehdfx.setTexturePackBase(texturePack.selectedTexturePack);
  1316.                 texturehdfx.setTileWidth(dimension.width / 16);
  1317.                 texturehdfx.onTick();
  1318.             }
  1319.         }
  1320.     }
  1321.  
  1322.     public boolean updateCustomTexture(TextureFX texturefx, int i, ByteBuffer bytebuffer, int j, StringBuffer stringbuffer)
  1323.     {
  1324.         if (i == terrainTextureId)
  1325.         {
  1326.             if (texturefx.iconIndex == Block.waterStill.blockIndexInTexture)
  1327.             {
  1328.                 if (Config.isGeneratedWater())
  1329.                 {
  1330.                     return false;
  1331.                 }
  1332.                 else
  1333.                 {
  1334.                     return updateCustomTexture(texturefx, "/custom_water_still.png", bytebuffer, j, Config.isAnimatedWater(), 1, stringbuffer);
  1335.                 }
  1336.             }
  1337.  
  1338.             if (texturefx.iconIndex == Block.waterStill.blockIndexInTexture + 1)
  1339.             {
  1340.                 if (Config.isGeneratedWater())
  1341.                 {
  1342.                     return false;
  1343.                 }
  1344.                 else
  1345.                 {
  1346.                     return updateCustomTexture(texturefx, "/custom_water_flowing.png", bytebuffer, j, Config.isAnimatedWater(), 1, stringbuffer);
  1347.                 }
  1348.             }
  1349.  
  1350.             if (texturefx.iconIndex == Block.lavaStill.blockIndexInTexture)
  1351.             {
  1352.                 if (Config.isGeneratedLava())
  1353.                 {
  1354.                     return false;
  1355.                 }
  1356.                 else
  1357.                 {
  1358.                     return updateCustomTexture(texturefx, "/custom_lava_still.png", bytebuffer, j, Config.isAnimatedLava(), 1, stringbuffer);
  1359.                 }
  1360.             }
  1361.  
  1362.             if (texturefx.iconIndex == Block.lavaStill.blockIndexInTexture + 1)
  1363.             {
  1364.                 if (Config.isGeneratedLava())
  1365.                 {
  1366.                     return false;
  1367.                 }
  1368.                 else
  1369.                 {
  1370.                     return updateCustomTexture(texturefx, "/custom_lava_flowing.png", bytebuffer, j, Config.isAnimatedLava(), 1, stringbuffer);
  1371.                 }
  1372.             }
  1373.  
  1374.             if (texturefx.iconIndex == Block.portal.blockIndexInTexture)
  1375.             {
  1376.                 return updateCustomTexture(texturefx, "/custom_portal.png", bytebuffer, j, Config.isAnimatedPortal(), 1, stringbuffer);
  1377.             }
  1378.  
  1379.             if (texturefx.iconIndex == Block.fire.blockIndexInTexture)
  1380.             {
  1381.                 return updateCustomTexture(texturefx, "/custom_fire_n_s.png", bytebuffer, j, Config.isAnimatedFire(), 1, stringbuffer);
  1382.             }
  1383.  
  1384.             if (texturefx.iconIndex == Block.fire.blockIndexInTexture + 16)
  1385.             {
  1386.                 return updateCustomTexture(texturefx, "/custom_fire_e_w.png", bytebuffer, j, Config.isAnimatedFire(), 1, stringbuffer);
  1387.             }
  1388.  
  1389.             if (Config.isAnimatedTerrain())
  1390.             {
  1391.                 return updateCustomTexture(texturefx, (new StringBuilder()).append("/custom_terrain_").append(texturefx.iconIndex).append(".png").toString(), bytebuffer, j, Config.isAnimatedTerrain(), 1, stringbuffer);
  1392.             }
  1393.         }
  1394.  
  1395.         if (i == guiItemsTextureId && Config.isAnimatedItems())
  1396.         {
  1397.             return updateCustomTexture(texturefx, (new StringBuilder()).append("/custom_item_").append(texturefx.iconIndex).append(".png").toString(), bytebuffer, j, Config.isAnimatedTerrain(), 1, stringbuffer);
  1398.         }
  1399.         else
  1400.         {
  1401.             return false;
  1402.         }
  1403.     }
  1404.  
  1405.     private boolean updateDefaultTexture(TextureFX texturefx, int i, ByteBuffer bytebuffer, int j, StringBuffer stringbuffer)
  1406.     {
  1407.         if (i != terrainTextureId)
  1408.         {
  1409.             return false;
  1410.         }
  1411.  
  1412.         if (texturePack.selectedTexturePack instanceof TexturePackDefault)
  1413.         {
  1414.             return false;
  1415.         }
  1416.  
  1417.         if (texturefx.iconIndex == Block.waterStill.blockIndexInTexture)
  1418.         {
  1419.             if (Config.isGeneratedWater())
  1420.             {
  1421.                 return false;
  1422.             }
  1423.             else
  1424.             {
  1425.                 return updateDefaultTexture(texturefx, bytebuffer, j, false, 1, stringbuffer);
  1426.             }
  1427.         }
  1428.  
  1429.         if (texturefx.iconIndex == Block.waterStill.blockIndexInTexture + 1)
  1430.         {
  1431.             if (Config.isGeneratedWater())
  1432.             {
  1433.                 return false;
  1434.             }
  1435.             else
  1436.             {
  1437.                 return updateDefaultTexture(texturefx, bytebuffer, j, Config.isAnimatedWater(), 1, stringbuffer);
  1438.             }
  1439.         }
  1440.  
  1441.         if (texturefx.iconIndex == Block.lavaStill.blockIndexInTexture)
  1442.         {
  1443.             if (Config.isGeneratedLava())
  1444.             {
  1445.                 return false;
  1446.             }
  1447.             else
  1448.             {
  1449.                 return updateDefaultTexture(texturefx, bytebuffer, j, false, 1, stringbuffer);
  1450.             }
  1451.         }
  1452.  
  1453.         if (texturefx.iconIndex == Block.lavaStill.blockIndexInTexture + 1)
  1454.         {
  1455.             if (Config.isGeneratedLava())
  1456.             {
  1457.                 return false;
  1458.             }
  1459.             else
  1460.             {
  1461.                 return updateDefaultTexture(texturefx, bytebuffer, j, Config.isAnimatedLava(), 3, stringbuffer);
  1462.             }
  1463.         }
  1464.         else
  1465.         {
  1466.             return false;
  1467.         }
  1468.     }
  1469.  
  1470.     private boolean updateDefaultTexture(TextureFX texturefx, ByteBuffer bytebuffer, int i, boolean flag, int j, StringBuffer stringbuffer)
  1471.     {
  1472.         int k = texturefx.iconIndex;
  1473.  
  1474.         if (!flag && dynamicTexturesUpdated)
  1475.         {
  1476.             return true;
  1477.         }
  1478.  
  1479.         byte abyte0[] = getTerrainIconData(k, i, stringbuffer);
  1480.  
  1481.         if (abyte0 == null)
  1482.         {
  1483.             return false;
  1484.         }
  1485.  
  1486.         bytebuffer.clear();
  1487.         int l = abyte0.length;
  1488.  
  1489.         if (flag)
  1490.         {
  1491.             int i1 = i - (tickCounter / j) % i;
  1492.             int j1 = i1 * i * 4;
  1493.             bytebuffer.put(abyte0, j1, l - j1);
  1494.             bytebuffer.put(abyte0, 0, j1);
  1495.             stringbuffer.append(":");
  1496.             stringbuffer.append(i1);
  1497.         }
  1498.         else
  1499.         {
  1500.             bytebuffer.put(abyte0, 0, l);
  1501.         }
  1502.  
  1503.         bytebuffer.position(0).limit(l);
  1504.         return true;
  1505.     }
  1506.  
  1507.     private boolean updateCustomTexture(TextureFX texturefx, String s, ByteBuffer bytebuffer, int i, boolean flag, int j, StringBuffer stringbuffer)
  1508.     {
  1509.         int k = i;
  1510.         CustomAnimation customanimation = getCustomAnimation(s, i, k, j);
  1511.  
  1512.         if (customanimation == null)
  1513.         {
  1514.             return false;
  1515.         }
  1516.         else
  1517.         {
  1518.             return customanimation.updateCustomTexture(bytebuffer, flag, dynamicTexturesUpdated, stringbuffer);
  1519.         }
  1520.     }
  1521.  
  1522.     private CustomAnimation getCustomAnimation(String s, int i, int j, int k)
  1523.     {
  1524.         CustomAnimation customanimation = (CustomAnimation)customAnimationMap.get(s);
  1525.  
  1526.         if (customanimation == null)
  1527.         {
  1528.             if (customAnimationMap.containsKey(s))
  1529.             {
  1530.                 return null;
  1531.             }
  1532.  
  1533.             byte abyte0[] = getCustomTextureData(s, i);
  1534.  
  1535.             if (abyte0 == null)
  1536.             {
  1537.                 customAnimationMap.put(s, null);
  1538.                 return null;
  1539.             }
  1540.  
  1541.             Properties properties = new Properties();
  1542.             String s1 = makePropertiesName(s);
  1543.  
  1544.             if (s1 != null)
  1545.             {
  1546.                 try
  1547.                 {
  1548.                     InputStream inputstream = texturePack.selectedTexturePack.getResourceAsStream(s1);
  1549.  
  1550.                     if (inputstream == null)
  1551.                     {
  1552.                         inputstream = texturePack.selectedTexturePack.getResourceAsStream((new StringBuilder()).append("/anim").append(s1).toString());
  1553.                     }
  1554.  
  1555.                     if (inputstream != null)
  1556.                     {
  1557.                         properties.load(inputstream);
  1558.                     }
  1559.                 }
  1560.                 catch (IOException ioexception)
  1561.                 {
  1562.                     ioexception.printStackTrace();
  1563.                 }
  1564.             }
  1565.  
  1566.             customanimation = new CustomAnimation(s, abyte0, i, j, properties, k);
  1567.             customAnimationMap.put(s, customanimation);
  1568.         }
  1569.  
  1570.         return customanimation;
  1571.     }
  1572.  
  1573.     private String makePropertiesName(String s)
  1574.     {
  1575.         if (!s.endsWith(".png"))
  1576.         {
  1577.             return null;
  1578.         }
  1579.  
  1580.         int i = s.lastIndexOf(".png");
  1581.  
  1582.         if (i < 0)
  1583.         {
  1584.             return null;
  1585.         }
  1586.         else
  1587.         {
  1588.             String s1 = (new StringBuilder()).append(s.substring(0, i)).append(".properties").toString();
  1589.             return s1;
  1590.         }
  1591.     }
  1592.  
  1593.     private byte[] getTerrainIconData(int i, int j, StringBuffer stringbuffer)
  1594.     {
  1595.         String s = (new StringBuilder()).append("Tile-").append(i).toString();
  1596.         byte abyte0[] = getCustomTextureData(s, j);
  1597.  
  1598.         if (abyte0 != null)
  1599.         {
  1600.             stringbuffer.append(s);
  1601.             return abyte0;
  1602.         }
  1603.  
  1604.         byte abyte1[] = getCustomTextureData("/terrain.png", j * 16);
  1605.  
  1606.         if (abyte1 == null)
  1607.         {
  1608.             return null;
  1609.         }
  1610.  
  1611.         abyte0 = new byte[j * j * 4];
  1612.         int k = i % 16;
  1613.         int l = i / 16;
  1614.         int i1 = k * j;
  1615.         int j1 = l * j;
  1616.         int k1 = i1 + j;
  1617.         int l1 = j1 + j;
  1618.  
  1619.         for (int i2 = 0; i2 < j; i2++)
  1620.         {
  1621.             int j2 = j1 + i2;
  1622.  
  1623.             for (int k2 = 0; k2 < j; k2++)
  1624.             {
  1625.                 int l2 = i1 + k2;
  1626.                 int i3 = 4 * (l2 + j2 * j * 16);
  1627.                 int j3 = 4 * (k2 + i2 * j);
  1628.                 abyte0[j3 + 0] = abyte1[i3 + 0];
  1629.                 abyte0[j3 + 1] = abyte1[i3 + 1];
  1630.                 abyte0[j3 + 2] = abyte1[i3 + 2];
  1631.                 abyte0[j3 + 3] = abyte1[i3 + 3];
  1632.             }
  1633.         }
  1634.  
  1635.         setCustomTextureData(s, abyte0);
  1636.         stringbuffer.append(s);
  1637.         return abyte0;
  1638.     }
  1639.  
  1640.     public byte[] getCustomTextureData(String s, int i)
  1641.     {
  1642.         byte abyte0[] = (byte[])textureDataMap.get(s);
  1643.  
  1644.         if (abyte0 == null)
  1645.         {
  1646.             if (textureDataMap.containsKey(s))
  1647.             {
  1648.                 return null;
  1649.             }
  1650.  
  1651.             abyte0 = loadImage(s, i);
  1652.  
  1653.             if (abyte0 == null)
  1654.             {
  1655.                 abyte0 = loadImage((new StringBuilder()).append("/anim").append(s).toString(), i);
  1656.             }
  1657.  
  1658.             textureDataMap.put(s, abyte0);
  1659.         }
  1660.  
  1661.         return abyte0;
  1662.     }
  1663.  
  1664.     private void setCustomTextureData(String s, byte abyte0[])
  1665.     {
  1666.         textureDataMap.put(s, abyte0);
  1667.     }
  1668.  
  1669.     private byte[] loadImage(String s, int i)
  1670.     {
  1671.         try
  1672.         {
  1673.             TexturePackBase texturepackbase = texturePack.selectedTexturePack;
  1674.  
  1675.             if (texturepackbase == null)
  1676.             {
  1677.                 return null;
  1678.             }
  1679.  
  1680.             InputStream inputstream = texturepackbase.getResourceAsStream(s);
  1681.  
  1682.             if (inputstream == null)
  1683.             {
  1684.                 return null;
  1685.             }
  1686.  
  1687.             BufferedImage bufferedimage = readTextureImage(inputstream);
  1688.  
  1689.             if (bufferedimage == null)
  1690.             {
  1691.                 return null;
  1692.             }
  1693.  
  1694.             if (i > 0 && bufferedimage.getWidth() != i)
  1695.             {
  1696.                 double d = bufferedimage.getHeight() / bufferedimage.getWidth();
  1697.                 int l = (int)((double)i * d);
  1698.                 bufferedimage = scaleBufferedImage(bufferedimage, i, l);
  1699.             }
  1700.  
  1701.             int j = bufferedimage.getWidth();
  1702.             int k = bufferedimage.getHeight();
  1703.             int ai[] = new int[j * k];
  1704.             byte abyte0[] = new byte[j * k * 4];
  1705.             bufferedimage.getRGB(0, 0, j, k, ai, 0, j);
  1706.  
  1707.             for (int i1 = 0; i1 < ai.length; i1++)
  1708.             {
  1709.                 int j1 = ai[i1] >> 24 & 0xff;
  1710.                 int k1 = ai[i1] >> 16 & 0xff;
  1711.                 int l1 = ai[i1] >> 8 & 0xff;
  1712.                 int i2 = ai[i1] & 0xff;
  1713.  
  1714.                 if (options != null && options.anaglyph)
  1715.                 {
  1716.                     int j2 = (k1 * 30 + l1 * 59 + i2 * 11) / 100;
  1717.                     int k2 = (k1 * 30 + l1 * 70) / 100;
  1718.                     int l2 = (k1 * 30 + i2 * 70) / 100;
  1719.                     k1 = j2;
  1720.                     l1 = k2;
  1721.                     i2 = l2;
  1722.                 }
  1723.  
  1724.                 abyte0[i1 * 4 + 0] = (byte)k1;
  1725.                 abyte0[i1 * 4 + 1] = (byte)l1;
  1726.                 abyte0[i1 * 4 + 2] = (byte)i2;
  1727.                 abyte0[i1 * 4 + 3] = (byte)j1;
  1728.             }
  1729.  
  1730.             return abyte0;
  1731.         }
  1732.         catch (Exception exception)
  1733.         {
  1734.             exception.printStackTrace();
  1735.         }
  1736.  
  1737.         return null;
  1738.     }
  1739.  
  1740.     public static BufferedImage scaleBufferedImage(BufferedImage bufferedimage, int i, int j)
  1741.     {
  1742.         BufferedImage bufferedimage1 = new BufferedImage(i, j, 2);
  1743.         Graphics2D graphics2d = bufferedimage1.createGraphics();
  1744.         graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  1745.         graphics2d.drawImage(bufferedimage, 0, 0, i, j, null);
  1746.         return bufferedimage1;
  1747.     }
  1748.  
  1749.     private void checkImageDataSize(int i)
  1750.     {
  1751.         if (imageData != null)
  1752.         {
  1753.             int j = i * i * 4;
  1754.  
  1755.             if (imageData.capacity() >= j)
  1756.             {
  1757.                 return;
  1758.             }
  1759.         }
  1760.  
  1761.         allocateImageData(i);
  1762.     }
  1763.  
  1764.     private void allocateImageData(int i)
  1765.     {
  1766.         int j = i * i * 4;
  1767.         imageData = GLAllocation.createDirectByteBuffer(j);
  1768.         ArrayList arraylist = new ArrayList();
  1769.  
  1770.         for (int k = i / 2; k > 0; k /= 2)
  1771.         {
  1772.             int l = k * k * 4;
  1773.             ByteBuffer bytebuffer = GLAllocation.createDirectByteBuffer(l);
  1774.             arraylist.add(bytebuffer);
  1775.         }
  1776.  
  1777.         mipImageDatas = (ByteBuffer[])arraylist.toArray(new ByteBuffer[arraylist.size()]);
  1778.     }
  1779.  
  1780.     public void checkHdTextures()
  1781.     {
  1782.         if (hdTexturesInstalled)
  1783.         {
  1784.             return;
  1785.         }
  1786.  
  1787.         Minecraft minecraft = Config.getMinecraft();
  1788.  
  1789.         if (minecraft == null)
  1790.         {
  1791.             return;
  1792.         }
  1793.         else
  1794.         {
  1795.             hdTexturesInstalled = true;
  1796.             registerTextureFX(new TextureHDLavaFX());
  1797.             registerTextureFX(new TextureHDWaterFX());
  1798.             registerTextureFX(new TextureHDPortalFX());
  1799.             registerTextureFX(new TextureHDWaterFlowFX());
  1800.             registerTextureFX(new TextureHDLavaFlowFX());
  1801.             registerTextureFX(new TextureHDFlamesFX(0));
  1802.             registerTextureFX(new TextureHDFlamesFX(1));
  1803.             registerTextureFX(new TextureHDCompassFX(minecraft));
  1804.             registerTextureFX(new TextureHDWatchFX(minecraft));
  1805.             registerCustomTexturesFX();
  1806.             CustomColorizer.update(this);
  1807.             return;
  1808.         }
  1809.     }
  1810.  
  1811.     private void registerCustomTexturesFX()
  1812.     {
  1813.         TextureFX atexturefx[] = getRegisteredTexturesFX(net.minecraft.src.TextureHDCustomFX.class);
  1814.  
  1815.         for (int i = 0; i < atexturefx.length; i++)
  1816.         {
  1817.             TextureFX texturefx = atexturefx[i];
  1818.             unregisterTextureFX(texturefx);
  1819.         }
  1820.  
  1821.         if (Config.isAnimatedTerrain())
  1822.         {
  1823.             for (int j = 0; j < 256; j++)
  1824.             {
  1825.                 registerCustomTextureFX((new StringBuilder()).append("/custom_terrain_").append(j).append(".png").toString(), j, 0);
  1826.             }
  1827.         }
  1828.  
  1829.         if (Config.isAnimatedItems())
  1830.         {
  1831.             for (int k = 0; k < 256; k++)
  1832.             {
  1833.                 registerCustomTextureFX((new StringBuilder()).append("/custom_item_").append(k).append(".png").toString(), k, 1);
  1834.             }
  1835.         }
  1836.  
  1837.         textureAnimations = getTextureAnimations();
  1838.     }
  1839.  
  1840.     private CustomAnimation[] getTextureAnimations()
  1841.     {
  1842.         String s = texturePack.selectedTexturePack.texturePackFileName;
  1843.         File file = new File(Config.getMinecraft().mcDataDir, "texturepacks");
  1844.         File file1 = new File(file, s);
  1845.  
  1846.         if (!file1.exists())
  1847.         {
  1848.             return null;
  1849.         }
  1850.  
  1851.         Properties aproperties[] = null;
  1852.  
  1853.         if (file1.isFile())
  1854.         {
  1855.             aproperties = getAnimationPropertiesZip(file1);
  1856.         }
  1857.         else
  1858.         {
  1859.             aproperties = getAnimationPropertiesDir(file1);
  1860.         }
  1861.  
  1862.         if (aproperties == null)
  1863.         {
  1864.             return null;
  1865.         }
  1866.  
  1867.         ArrayList arraylist = new ArrayList();
  1868.  
  1869.         for (int i = 0; i < aproperties.length; i++)
  1870.         {
  1871.             Properties properties = aproperties[i];
  1872.             CustomAnimation customanimation = makeTextureAnimation(properties);
  1873.  
  1874.             if (customanimation != null)
  1875.             {
  1876.                 arraylist.add(customanimation);
  1877.             }
  1878.         }
  1879.  
  1880.         CustomAnimation acustomanimation[] = (CustomAnimation[])arraylist.toArray(new CustomAnimation[arraylist.size()]);
  1881.         return acustomanimation;
  1882.     }
  1883.  
  1884.     private CustomAnimation makeTextureAnimation(Properties properties)
  1885.     {
  1886.         String s = properties.getProperty("from");
  1887.         String s1 = properties.getProperty("to");
  1888.         int i = Config.parseInt(properties.getProperty("x"), -1);
  1889.         int j = Config.parseInt(properties.getProperty("y"), -1);
  1890.         int k = Config.parseInt(properties.getProperty("w"), -1);
  1891.         int l = Config.parseInt(properties.getProperty("h"), -1);
  1892.  
  1893.         if (s == null || s1 == null)
  1894.         {
  1895.             return null;
  1896.         }
  1897.  
  1898.         if (i < 0 || j < 0 || k < 0 || l < 0)
  1899.         {
  1900.             return null;
  1901.         }
  1902.  
  1903.         byte abyte0[] = getCustomTextureData(s, k);
  1904.  
  1905.         if (abyte0 == null)
  1906.         {
  1907.             return null;
  1908.         }
  1909.         else
  1910.         {
  1911.             CustomAnimation customanimation = new CustomAnimation(s, abyte0, k, l, properties, 1);
  1912.             customanimation.destTexture = s1;
  1913.             customanimation.destX = i;
  1914.             customanimation.destY = j;
  1915.             return customanimation;
  1916.         }
  1917.     }
  1918.  
  1919.     private Properties[] getAnimationPropertiesDir(File file)
  1920.     {
  1921.         File file1 = new File(file, "anim");
  1922.  
  1923.         if (!file1.exists())
  1924.         {
  1925.             return null;
  1926.         }
  1927.  
  1928.         if (!file1.isDirectory())
  1929.         {
  1930.             return null;
  1931.         }
  1932.  
  1933.         aaw._cls1 _lcls1 = new aaw._cls1(this);
  1934.         File afile[] = file1.listFiles(_lcls1);
  1935.  
  1936.         if (afile == null)
  1937.         {
  1938.             return null;
  1939.         }
  1940.  
  1941.         try
  1942.         {
  1943.             ArrayList arraylist = new ArrayList();
  1944.  
  1945.             for (int i = 0; i < afile.length; i++)
  1946.             {
  1947.                 File file2 = afile[i];
  1948.  
  1949.                 if (file2.isFile() && file2.canRead())
  1950.                 {
  1951.                     FileInputStream fileinputstream = new FileInputStream(file2);
  1952.                     Properties properties = new Properties();
  1953.                     properties.load(fileinputstream);
  1954.                     fileinputstream.close();
  1955.                     arraylist.add(properties);
  1956.                 }
  1957.             }
  1958.  
  1959.             Properties aproperties[] = (Properties[])arraylist.toArray(new Properties[arraylist.size()]);
  1960.             return aproperties;
  1961.         }
  1962.         catch (IOException ioexception)
  1963.         {
  1964.             ioexception.printStackTrace();
  1965.         }
  1966.  
  1967.         return null;
  1968.     }
  1969.  
  1970.     private Properties[] getAnimationPropertiesZip(File file)
  1971.     {
  1972.         try
  1973.         {
  1974.             ZipFile zipfile = new ZipFile(file);
  1975.             Enumeration enumeration = zipfile.entries();
  1976.             ArrayList arraylist = new ArrayList();
  1977.  
  1978.             do
  1979.             {
  1980.                 if (!enumeration.hasMoreElements())
  1981.                 {
  1982.                     break;
  1983.                 }
  1984.  
  1985.                 ZipEntry zipentry = (ZipEntry)enumeration.nextElement();
  1986.                 String s = zipentry.getName();
  1987.  
  1988.                 if (s.startsWith("anim/") && !s.startsWith("anim/custom_") && s.endsWith(".properties"))
  1989.                 {
  1990.                     InputStream inputstream = zipfile.getInputStream(zipentry);
  1991.                     Properties properties = new Properties();
  1992.                     properties.load(inputstream);
  1993.                     inputstream.close();
  1994.                     arraylist.add(properties);
  1995.                 }
  1996.             }
  1997.             while (true);
  1998.  
  1999.             Properties aproperties[] = (Properties[])arraylist.toArray(new Properties[arraylist.size()]);
  2000.             return aproperties;
  2001.         }
  2002.         catch (IOException ioexception)
  2003.         {
  2004.             ioexception.printStackTrace();
  2005.         }
  2006.  
  2007.         return null;
  2008.     }
  2009.  
  2010.     private void unregisterTextureFX(TextureFX texturefx)
  2011.     {
  2012.         for (int i = 0; i < textureList.size(); i++)
  2013.         {
  2014.             TextureFX texturefx1 = (TextureFX)textureList.get(i);
  2015.  
  2016.             if (texturefx1 == texturefx)
  2017.             {
  2018.                 textureList.remove(i);
  2019.                 i--;
  2020.             }
  2021.         }
  2022.     }
  2023.  
  2024.     private TextureFX[] getRegisteredTexturesFX(Class class1)
  2025.     {
  2026.         ArrayList arraylist = new ArrayList();
  2027.  
  2028.         for (int i = 0; i < textureList.size(); i++)
  2029.         {
  2030.             TextureFX texturefx = (TextureFX)textureList.get(i);
  2031.  
  2032.             if (class1.isAssignableFrom(texturefx.getClass()))
  2033.             {
  2034.                 arraylist.add(texturefx);
  2035.             }
  2036.         }
  2037.  
  2038.         TextureFX atexturefx[] = (TextureFX[])arraylist.toArray(new TextureFX[arraylist.size()]);
  2039.         return atexturefx;
  2040.     }
  2041.  
  2042.     private void registerCustomTextureFX(String s, int i, int j)
  2043.     {
  2044.         byte abyte0[] = null;
  2045.  
  2046.         if (j == 0)
  2047.         {
  2048.             abyte0 = getCustomTextureData(s, Config.getIconWidthTerrain());
  2049.         }
  2050.         else
  2051.         {
  2052.             abyte0 = getCustomTextureData(s, Config.getIconWidthItems());
  2053.         }
  2054.  
  2055.         if (abyte0 == null)
  2056.         {
  2057.             return;
  2058.         }
  2059.         else
  2060.         {
  2061.             registerTextureFX(new TextureHDCustomFX(i, j));
  2062.             return;
  2063.         }
  2064.     }
  2065.  
  2066.     private int getMaxMipmapLevel(int i)
  2067.     {
  2068.         int j;
  2069.  
  2070.         for (j = 0; i > 0; j++)
  2071.         {
  2072.             i /= 2;
  2073.         }
  2074.  
  2075.         return j - 1;
  2076.     }
  2077.  
  2078.     private void copyScaled(byte abyte0[], ByteBuffer bytebuffer, int i)
  2079.     {
  2080.         int j = (int)Math.sqrt(abyte0.length / 4);
  2081.         int k = i / j;
  2082.         byte abyte1[] = new byte[4];
  2083.         int l = i * i;
  2084.         bytebuffer.clear();
  2085.  
  2086.         if (k > 1)
  2087.         {
  2088.             for (int i1 = 0; i1 < j; i1++)
  2089.             {
  2090.                 int j1 = i1 * j;
  2091.                 int k1 = i1 * k;
  2092.                 int l1 = k1 * i;
  2093.  
  2094.                 for (int i2 = 0; i2 < j; i2++)
  2095.                 {
  2096.                     int j2 = (i2 + j1) * 4;
  2097.                     abyte1[0] = abyte0[j2];
  2098.                     abyte1[1] = abyte0[j2 + 1];
  2099.                     abyte1[2] = abyte0[j2 + 2];
  2100.                     abyte1[3] = abyte0[j2 + 3];
  2101.                     int k2 = i2 * k;
  2102.                     int l2 = k2 + l1;
  2103.  
  2104.                     for (int i3 = 0; i3 < k; i3++)
  2105.                     {
  2106.                         int j3 = l2 + i3 * i;
  2107.                         bytebuffer.position(j3 * 4);
  2108.  
  2109.                         for (int k3 = 0; k3 < k; k3++)
  2110.                         {
  2111.                             bytebuffer.put(abyte1);
  2112.                         }
  2113.                     }
  2114.                 }
  2115.             }
  2116.         }
  2117.  
  2118.         bytebuffer.position(0).limit(i * i * 4);
  2119.     }
  2120.  
  2121.     private boolean scalesWithFastColor(TextureFX texturefx)
  2122.     {
  2123.         return !texturefx.getClass().getName().equals("ModTextureStatic");
  2124.     }
  2125.  
  2126.     public TexturePackList getTexturePack()
  2127.     {
  2128.         return texturePack;
  2129.     }
  2130. }