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.BufferedReader; 007import java.io.IOException; 008import java.io.InputStream; 009import java.io.InputStreamReader; 010import java.util.ArrayList; 011import java.util.Arrays; 012import java.util.HashMap; 013import java.util.Iterator; 014import java.util.List; 015import java.util.Map; 016import net.minecraft.block.Block; 017import net.minecraft.client.Minecraft; 018import net.minecraft.client.renderer.StitcherException; 019import net.minecraft.client.renderer.entity.RenderManager; 020import net.minecraft.client.texturepacks.ITexturePack; 021import net.minecraft.item.Item; 022import net.minecraft.util.Icon; 023 024@SideOnly(Side.CLIENT) 025public class TextureMap implements IconRegister 026{ 027 private final int field_94255_a; 028 private final String field_94253_b; 029 private final String field_94254_c; 030 private final String field_94251_d; 031 private final HashMap field_94252_e = new HashMap(); 032 private BufferedImage field_94249_f = new BufferedImage(64, 64, 2); 033 private TextureStitched field_94250_g; 034 private Texture field_94257_h; 035 private final List field_94258_i = new ArrayList(); 036 private final Map field_94256_j = new HashMap(); 037 038 public TextureMap(int par1, String par2, String par3Str, BufferedImage par4BufferedImage) 039 { 040 this.field_94255_a = par1; 041 this.field_94253_b = par2; 042 this.field_94254_c = par3Str; 043 this.field_94251_d = ".png"; 044 this.field_94249_f = par4BufferedImage; 045 } 046 047 public void func_94247_b() 048 { 049 this.field_94256_j.clear(); 050 int i; 051 int j; 052 053 if (this.field_94255_a == 0) 054 { 055 Block[] ablock = Block.blocksList; 056 i = ablock.length; 057 058 for (j = 0; j < i; ++j) 059 { 060 Block block = ablock[j]; 061 062 if (block != null) 063 { 064 block.func_94332_a(this); 065 } 066 } 067 068 Minecraft.getMinecraft().renderGlobal.func_94140_a(this); 069 RenderManager.instance.func_94178_a(this); 070 } 071 072 Item[] aitem = Item.itemsList; 073 i = aitem.length; 074 075 for (j = 0; j < i; ++j) 076 { 077 Item item = aitem[j]; 078 079 if (item != null && item.func_94901_k() == this.field_94255_a) 080 { 081 item.func_94581_a(this); 082 } 083 } 084 085 HashMap hashmap = new HashMap(); 086 Stitcher stitcher = TextureManager.func_94267_b().func_94262_d(this.field_94253_b); 087 this.field_94252_e.clear(); 088 this.field_94258_i.clear(); 089 Texture texture = TextureManager.func_94267_b().func_94261_a("missingno", 2, this.field_94249_f.getWidth(), this.field_94249_f.getHeight(), 10496, 6408, 9728, 9728, false, this.field_94249_f); 090 StitchHolder stitchholder = new StitchHolder(texture); 091 stitcher.func_94312_a(stitchholder); 092 hashmap.put(stitchholder, Arrays.asList(new Texture[] {texture})); 093 094 for (Map.Entry<String, TextureStitched> entry : ((Map<String, TextureStitched>)field_94256_j).entrySet()) 095 { 096 String name = entry.getKey(); 097 String path; 098 if (name.indexOf(':') == -1) 099 { 100 path = this.field_94254_c + name + this.field_94251_d; 101 } 102 else 103 { 104 String domain = name.substring(0,name.indexOf(':')); 105 String file = name.substring(name.indexOf(':')+1); 106 path = "mods/" + domain +"/" + field_94254_c + file + field_94251_d; 107 } 108 List list = TextureManager.func_94267_b().createNewTexture(name, path, entry.getValue()); 109 110 if (!list.isEmpty()) 111 { 112 StitchHolder stitchholder1 = new StitchHolder((Texture)list.get(0)); 113 stitcher.func_94312_a(stitchholder1); 114 hashmap.put(stitchholder1, list); 115 } 116 } 117 118 try 119 { 120 stitcher.func_94305_f(); 121 } 122 catch (StitcherException stitcherexception) 123 { 124 throw stitcherexception; 125 } 126 127 this.field_94257_h = stitcher.func_94306_e(); 128 Iterator iterator = stitcher.func_94309_g().iterator(); 129 130 while (iterator.hasNext()) 131 { 132 StitchSlot stitchslot = (StitchSlot)iterator.next(); 133 StitchHolder stitchholder2 = stitchslot.func_94183_a(); 134 Texture texture1 = stitchholder2.func_98150_a(); 135 String s2 = texture1.func_94280_f(); 136 List list1 = (List)hashmap.get(stitchholder2); 137 TextureStitched texturestitched = (TextureStitched)this.field_94256_j.get(s2); 138 boolean flag = false; 139 140 if (texturestitched == null) 141 { 142 flag = true; 143 texturestitched = TextureStitched.func_94220_a(s2); 144 145 if (!s2.equals("missingno")) 146 { 147 Minecraft.getMinecraft().func_98033_al().func_98236_b("Couldn\'t find premade icon for " + s2 + " doing " + this.field_94253_b); 148 } 149 } 150 151 texturestitched.func_94218_a(this.field_94257_h, list1, stitchslot.func_94186_b(), stitchslot.func_94185_c(), stitchholder2.func_98150_a().func_94275_d(), stitchholder2.func_98150_a().func_94276_e(), stitchholder2.func_94195_e()); 152 this.field_94252_e.put(s2, texturestitched); 153 154 if (!flag) 155 { 156 this.field_94256_j.remove(s2); 157 } 158 159 if (list1.size() > 1) 160 { 161 this.field_94258_i.add(texturestitched); 162 String s3; 163 if (s2.indexOf(':') == -1) 164 { 165 s3 = field_94254_c + s2 + ".txt"; 166 } 167 else 168 { 169 String domain = s2.substring(0, s2.indexOf(':')); 170 String file = s2.substring(s2.indexOf(':') + 1); 171 s3 = "mods/" + domain + "/" + field_94254_c + file + ".txt"; 172 } 173 ITexturePack itexturepack = Minecraft.getMinecraft().texturePackList.getSelectedTexturePack(); 174 boolean flag1 = !itexturepack.func_98138_b("/" + this.field_94254_c + s2 + ".png", false); 175 176 try 177 { 178 InputStream inputstream = itexturepack.func_98137_a("/" + s3, flag1); 179 Minecraft.getMinecraft().func_98033_al().func_98233_a("Found animation info for: " + s3); 180 texturestitched.func_94221_a(new BufferedReader(new InputStreamReader(inputstream))); 181 } 182 catch (IOException ioexception) 183 { 184 ; 185 } 186 } 187 } 188 189 this.field_94250_g = (TextureStitched)this.field_94252_e.get("missingno"); 190 iterator = this.field_94256_j.values().iterator(); 191 192 while (iterator.hasNext()) 193 { 194 TextureStitched texturestitched1 = (TextureStitched)iterator.next(); 195 texturestitched1.func_94217_a(this.field_94250_g); 196 } 197 198 this.field_94257_h.func_94279_c("debug.stitched_" + this.field_94253_b + ".png"); 199 this.field_94257_h.func_94285_g(); 200 } 201 202 public void func_94248_c() 203 { 204 Iterator iterator = this.field_94258_i.iterator(); 205 206 while (iterator.hasNext()) 207 { 208 TextureStitched texturestitched = (TextureStitched)iterator.next(); 209 texturestitched.func_94219_l(); 210 } 211 } 212 213 public Texture func_94246_d() 214 { 215 return this.field_94257_h; 216 } 217 218 public Icon func_94245_a(String par1Str) 219 { 220 if (par1Str == null) 221 { 222 (new RuntimeException("Don\'t register null!")).printStackTrace(); 223 } 224 225 TextureStitched texturestitched = (TextureStitched)this.field_94256_j.get(par1Str); 226 227 if (texturestitched == null) 228 { 229 texturestitched = TextureStitched.func_94220_a(par1Str); 230 this.field_94256_j.put(par1Str, texturestitched); 231 } 232 233 return texturestitched; 234 } 235 236 public Icon func_96455_e() 237 { 238 return this.field_94250_g; 239 } 240 241 //=================================================================================================== 242 // Forge Start 243 //=================================================================================================== 244 /** 245 * Grabs the registered entry for the specified name, returning null if there was not a entry. 246 * Opposed to func_94245_a, this will not instantiate the entry, useful to test if a maping exists. 247 * 248 * @param name The name of the entry to find 249 * @return The registered entry, null if nothing was registered. 250 */ 251 public TextureStitched getTextureExtry(String name) 252 { 253 return (TextureStitched)field_94256_j.get(name); 254 } 255 256 /** 257 * Adds a texture registry entry to this map for the specified name if one does not already exist. 258 * Returns false if the map already contains a entry for the specified name. 259 * 260 * @param name Entry name 261 * @param entry Entry instance 262 * @return True if the entry was added to the map, false otherwise. 263 */ 264 public boolean setTextureEntry(String name, TextureStitched entry) 265 { 266 if (!field_94256_j.containsKey(name)) 267 { 268 field_94256_j.put(name, entry); 269 return true; 270 } 271 return false; 272 } 273}