Advertisement
robin4002

Untitled

Nov 28th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.34 KB | None | 0 0
  1. package net.minecraft.client.renderer.texture;
  2.  
  3. import com.google.common.collect.Lists;
  4. import com.google.common.collect.Maps;
  5. import cpw.mods.fml.relauncher.Side;
  6. import cpw.mods.fml.relauncher.SideOnly;
  7. import java.io.IOException;
  8. import java.util.Iterator;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.Map.Entry;
  12. import net.minecraft.client.Minecraft;
  13. import net.minecraft.client.resources.ResourceManager;
  14. import net.minecraft.client.resources.ResourceManagerReloadListener;
  15. import net.minecraft.crash.CrashReport;
  16. import net.minecraft.crash.CrashReportCategory;
  17. import net.minecraft.util.ReportedException;
  18. import net.minecraft.util.ResourceLocation;
  19.  
  20. @SideOnly(Side.CLIENT)
  21. public class TextureManager implements Tickable, ResourceManagerReloadListener
  22. {
  23.     private final Map mapTextureObjects = Maps.newHashMap();
  24.     private final Map mapResourceLocations = Maps.newHashMap();
  25.     private final List listTickables = Lists.newArrayList();
  26.     private final Map mapTextureCounters = Maps.newHashMap();
  27.     private ResourceManager theResourceManager;
  28.  
  29.     public TextureManager(ResourceManager par1ResourceManager)
  30.     {
  31.         this.theResourceManager = par1ResourceManager;
  32.     }
  33.  
  34.     public void bindTexture(ResourceLocation par1ResourceLocation)
  35.     {
  36.         Object object = (TextureObject)this.mapTextureObjects.get(par1ResourceLocation);
  37.  
  38.         if (object == null)
  39.         {
  40.             object = new SimpleTexture(par1ResourceLocation);
  41.             this.loadTexture(par1ResourceLocation, (TextureObject)object);
  42.         }
  43.  
  44.         TextureUtil.bindTexture(((TextureObject)object).getGlTextureId());
  45.     }
  46.  
  47.     public ResourceLocation getResourceLocation(int par1)
  48.     {
  49.         return (ResourceLocation)this.mapResourceLocations.get(Integer.valueOf(par1));
  50.     }
  51.  
  52.     public boolean loadTextureMap(ResourceLocation par1ResourceLocation, TextureMap par2TextureMap)
  53.     {
  54.         if (this.loadTickableTexture(par1ResourceLocation, par2TextureMap))
  55.         {
  56.             this.mapResourceLocations.put(Integer.valueOf(par2TextureMap.getTextureType()), par1ResourceLocation);
  57.             return true;
  58.         }
  59.         else
  60.         {
  61.             return false;
  62.         }
  63.     }
  64.  
  65.     public boolean loadTickableTexture(ResourceLocation par1ResourceLocation, TickableTextureObject par2TickableTextureObject)
  66.     {
  67.         if (this.loadTexture(par1ResourceLocation, par2TickableTextureObject))
  68.         {
  69.             this.listTickables.add(par2TickableTextureObject);
  70.             return true;
  71.         }
  72.         else
  73.         {
  74.             return false;
  75.         }
  76.     }
  77.  
  78.     public boolean loadTexture(ResourceLocation par1ResourceLocation, TextureObject par2TextureObject)
  79.     {
  80.         boolean flag = true;
  81.  
  82.         try
  83.         {
  84.             ((TextureObject)par2TextureObject).loadTexture(this.theResourceManager);
  85.         }
  86.         catch (IOException ioexception)
  87.         {
  88.             Minecraft.getMinecraft().getLogAgent().logWarningException("Failed to load texture: " + par1ResourceLocation, ioexception);
  89.             par2TextureObject = TextureUtil.missingTexture;
  90.             this.mapTextureObjects.put(par1ResourceLocation, par2TextureObject);
  91.             flag = false;
  92.         }
  93.         catch (Throwable throwable)
  94.         {
  95.             CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Registering texture");
  96.             CrashReportCategory crashreportcategory = crashreport.makeCategory("Resource location being registered");
  97.             crashreportcategory.addCrashSection("Resource location", par1ResourceLocation);
  98.             crashreportcategory.addCrashSectionCallable("Texture object class", new TextureManagerINNER1(this, (TextureObject)par2TextureObject));
  99.             throw new ReportedException(crashreport);
  100.         }
  101.  
  102.         this.mapTextureObjects.put(par1ResourceLocation, par2TextureObject);
  103.         return flag;
  104.     }
  105.  
  106.     public TextureObject getTexture(ResourceLocation par1ResourceLocation)
  107.     {
  108.         return (TextureObject)this.mapTextureObjects.get(par1ResourceLocation);
  109.     }
  110.  
  111.     public ResourceLocation getDynamicTextureLocation(String par1Str, DynamicTexture par2DynamicTexture)
  112.     {
  113.         Integer integer = (Integer)this.mapTextureCounters.get(par1Str);
  114.  
  115.         if (integer == null)
  116.         {
  117.             integer = Integer.valueOf(1);
  118.         }
  119.         else
  120.         {
  121.             integer = Integer.valueOf(integer.intValue() + 1);
  122.         }
  123.  
  124.         this.mapTextureCounters.put(par1Str, integer);
  125.         ResourceLocation resourcelocation = new ResourceLocation(String.format("dynamic/%s_%d", new Object[] {par1Str, integer}));
  126.         this.loadTexture(resourcelocation, par2DynamicTexture);
  127.         return resourcelocation;
  128.     }
  129.  
  130.     public void tick()
  131.     {
  132.         Iterator iterator = this.listTickables.iterator();
  133.  
  134.         while (iterator.hasNext())
  135.         {
  136.             Tickable tickable = (Tickable)iterator.next();
  137.             tickable.tick();
  138.         }
  139.     }
  140.  
  141.     public void onResourceManagerReload(ResourceManager par1ResourceManager)
  142.     {
  143.         Iterator iterator = this.mapTextureObjects.entrySet().iterator();
  144.  
  145.         while (iterator.hasNext())
  146.         {
  147.             Entry entry = (Entry)iterator.next();
  148.             this.loadTexture((ResourceLocation)entry.getKey(), (TextureObject)entry.getValue());
  149.         }
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement