001package net.minecraft.client.renderer.texture; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import java.awt.image.BufferedImage; 006import java.io.File; 007import java.io.FileNotFoundException; 008import java.io.IOException; 009import java.util.ArrayList; 010import java.util.HashMap; 011import java.util.List; 012import javax.imageio.ImageIO; 013import net.minecraft.client.Minecraft; 014import net.minecraft.client.texturepacks.ITexturePack; 015 016@SideOnly(Side.CLIENT) 017public class TextureManager 018{ 019 private static TextureManager field_94271_a; 020 private int field_94269_b = 0; 021 private final HashMap field_94270_c = new HashMap(); 022 private final HashMap field_94268_d = new HashMap(); 023 024 public static void func_94263_a() 025 { 026 field_94271_a = new TextureManager(); 027 } 028 029 public static TextureManager func_94267_b() 030 { 031 return field_94271_a; 032 } 033 034 public int func_94265_c() 035 { 036 return this.field_94269_b++; 037 } 038 039 public void func_94264_a(String par1Str, Texture par2Texture) 040 { 041 this.field_94268_d.put(par1Str, Integer.valueOf(par2Texture.func_94284_b())); 042 043 if (!this.field_94270_c.containsKey(Integer.valueOf(par2Texture.func_94284_b()))) 044 { 045 this.field_94270_c.put(Integer.valueOf(par2Texture.func_94284_b()), par2Texture); 046 } 047 } 048 049 public void func_94259_a(Texture par1Texture) 050 { 051 if (this.field_94270_c.containsValue(par1Texture)) 052 { 053 Minecraft.getMinecraft().func_98033_al().func_98236_b("TextureManager.registerTexture called, but this texture has already been registered. ignoring."); 054 } 055 else 056 { 057 this.field_94270_c.put(Integer.valueOf(par1Texture.func_94284_b()), par1Texture); 058 } 059 } 060 061 public Stitcher func_94262_d(String par1Str) 062 { 063 int i = Minecraft.getGLMaximumTextureSize(); 064 return new Stitcher(par1Str, i, i, true); 065 } 066 067 public List func_94266_e(String par1Str) 068 { 069 return createNewTexture(par1Str, par1Str, null); 070 } 071 072 public List createNewTexture(String textureName, String textureFile, TextureStitched stitched) 073 { 074 String par1Str = textureFile; 075 ArrayList arraylist = new ArrayList(); 076 ITexturePack itexturepack = Minecraft.getMinecraft().texturePackList.getSelectedTexturePack(); 077 078 try 079 { 080 BufferedImage bufferedimage = null; 081 int i = 0; 082 int j = 0; 083 FileNotFoundException fnfe = null; 084 try 085 { 086 bufferedimage = ImageIO.read(itexturepack.getResourceAsStream("/" + textureFile)); 087 i = bufferedimage.getHeight(); 088 j = bufferedimage.getWidth(); 089 } 090 catch (FileNotFoundException e) 091 { 092 fnfe = e; 093 } 094 String s1 = textureName; 095 096 if (stitched != null && stitched.loadTexture(this, itexturepack, textureName, textureFile, bufferedimage, arraylist)) 097 { 098 ; 099 } 100 else if (fnfe != null) 101 { 102 throw fnfe; 103 } 104 else if (this.func_98147_a(par1Str, itexturepack)) 105 { 106 int k = j; 107 int l = j; 108 int i1 = i / j; 109 110 for (int j1 = 0; j1 < i1; ++j1) 111 { 112 Texture texture = this.func_94261_a(s1, 2, k, l, 10496, 6408, 9728, 9728, false, bufferedimage.getSubimage(0, l * j1, k, l)); 113 arraylist.add(texture); 114 } 115 } 116 else if (j == i) 117 { 118 arraylist.add(this.func_94261_a(s1, 2, j, i, 10496, 6408, 9728, 9728, false, bufferedimage)); 119 } 120 else 121 { 122 Minecraft.getMinecraft().func_98033_al().func_98236_b("TextureManager.createTexture: Skipping " + par1Str + " because of broken aspect ratio and not animation"); 123 } 124 125 return arraylist; 126 } 127 catch (FileNotFoundException filenotfoundexception) 128 { 129 Minecraft.getMinecraft().func_98033_al().func_98236_b("TextureManager.createTexture called for file " + par1Str + ", but that file does not exist. Ignoring."); 130 } 131 catch (IOException ioexception) 132 { 133 Minecraft.getMinecraft().func_98033_al().func_98236_b("TextureManager.createTexture encountered an IOException when trying to read file " + par1Str + ". Ignoring."); 134 } 135 136 return arraylist; 137 } 138 139 private String func_98146_d(String par1Str) 140 { 141 File file1 = new File(par1Str); 142 return file1.getName().substring(0, file1.getName().lastIndexOf(46)); 143 } 144 145 private boolean func_98147_a(String par1Str, ITexturePack par2ITexturePack) 146 { 147 String s1 = "/" + par1Str.substring(0, par1Str.lastIndexOf(46)) + ".txt"; 148 boolean flag = par2ITexturePack.func_98138_b("/" + par1Str, false); 149 return Minecraft.getMinecraft().texturePackList.getSelectedTexturePack().func_98138_b(s1, !flag); 150 } 151 152 public Texture func_94261_a(String par1Str, int par2, int par3, int par4, int par5, int par6, int par7, int par8, boolean par9, BufferedImage par10BufferedImage) 153 { 154 Texture texture = new Texture(par1Str, par2, par3, par4, par5, par6, par7, par8, par10BufferedImage); 155 this.func_94259_a(texture); 156 return texture; 157 } 158 159 public Texture func_98145_a(String par1Str, int par2, int par3, int par4, int par5) 160 { 161 return this.func_94261_a(par1Str, par2, par3, par4, 10496, par5, 9728, 9728, false, (BufferedImage)null); 162 } 163}