Advertisement
Guest User

Untitled

a guest
Aug 18th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 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 java.io.IOException;
  6. import java.util.Iterator;
  7. import java.util.List;
  8. import java.util.Map;
  9. import java.util.Map.Entry;
  10. import java.util.concurrent.Callable;
  11. import net.minecraft.client.resources.IResourceManager;
  12. import net.minecraft.client.resources.IResourceManagerReloadListener;
  13. import net.minecraft.crash.CrashReport;
  14. import net.minecraft.crash.CrashReportCategory;
  15. import net.minecraft.util.ReportedException;
  16. import net.minecraft.util.ResourceLocation;
  17. import optifine.Config;
  18. import optifine.RandomMobs;
  19.  
  20. import org.apache.logging.log4j.LogManager;
  21. import org.apache.logging.log4j.Logger;
  22. import shadersmod.client.ShadersTex;
  23.  
  24. public class TextureManager implements ITickable, IResourceManagerReloadListener
  25. {
  26. private static final Logger logger = LogManager.getLogger();
  27. private final Map mapTextureObjects = Maps.newHashMap();
  28. private final List listTickables = Lists.newArrayList();
  29. private final Map mapTextureCounters = Maps.newHashMap();
  30. private IResourceManager theResourceManager;
  31. private static final String __OBFID = "CL_00001064";
  32.  
  33. public TextureManager(IResourceManager resourceManager)
  34. {
  35. this.theResourceManager = resourceManager;
  36. }
  37.  
  38. public void bindTexture(ResourceLocation resource)
  39. {
  40. if (Config.isRandomMobs())
  41. {
  42. resource = RandomMobs.getTextureLocation(resource);
  43. }
  44.  
  45. Object object = (ITextureObject)this.mapTextureObjects.get(resource);
  46.  
  47. if (object == null)
  48. {
  49. object = new SimpleTexture(resource);
  50. this.loadTexture(resource, (ITextureObject)object);
  51. }
  52.  
  53. if (Config.isShaders())
  54. {
  55. ShadersTex.bindTexture((ITextureObject)object);
  56. }
  57. else
  58. {
  59. TextureUtil.bindTexture(((ITextureObject)object).getGlTextureId());
  60. }
  61. }
  62.  
  63. public boolean loadTickableTexture(ResourceLocation textureLocation, ITickableTextureObject textureObj)
  64. {
  65. if (this.loadTexture(textureLocation, textureObj))
  66. {
  67. this.listTickables.add(textureObj);
  68. return true;
  69. }
  70. else
  71. {
  72. return false;
  73. }
  74. }
  75.  
  76. public boolean loadTexture(ResourceLocation textureLocation, ITextureObject textureObj)
  77. {
  78. boolean flag = true;
  79. ITextureObject itextureobject = textureObj;
  80.  
  81. try
  82. {
  83. textureObj.loadTexture(this.theResourceManager);
  84. }
  85. catch (IOException ioexception)
  86. {
  87. logger.warn((String)("Failed to load texture: " + textureLocation), (Throwable)ioexception);
  88. itextureobject = TextureUtil.missingTexture;
  89. this.mapTextureObjects.put(textureLocation, itextureobject);
  90. flag = false;
  91. }
  92. catch (Throwable throwable)
  93. {
  94. CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Registering texture");
  95. CrashReportCategory crashreportcategory = crashreport.makeCategory("Resource location being registered");
  96. crashreportcategory.addCrashSection("Resource location", textureLocation);
  97. crashreportcategory.addCrashSectionCallable("Texture object class", new Callable()
  98. {
  99. private static final String __OBFID = "CL_00001065";
  100. public String call() throws Exception
  101. {
  102. return textureObj.getClass().getName();
  103. }
  104. });
  105. throw new ReportedException(crashreport);
  106. }
  107.  
  108. this.mapTextureObjects.put(textureLocation, itextureobject);
  109. return flag;
  110. }
  111.  
  112. public ITextureObject getTexture(ResourceLocation textureLocation)
  113. {
  114. return (ITextureObject)this.mapTextureObjects.get(textureLocation);
  115. }
  116.  
  117. public ResourceLocation getDynamicTextureLocation(String name, DynamicTexture texture)
  118. {
  119. if (name.equals("logo"))
  120. {
  121. texture = Config.getMojangLogoTexture(texture);
  122. }
  123.  
  124. Integer integer = (Integer)this.mapTextureCounters.get(name);
  125.  
  126. if (integer == null)
  127. {
  128. integer = Integer.valueOf(1);
  129. }
  130. else
  131. {
  132. integer = Integer.valueOf(integer.intValue() + 1);
  133. }
  134.  
  135. this.mapTextureCounters.put(name, integer);
  136. ResourceLocation resourcelocation = new ResourceLocation(String.format("dynamic/%s_%d", new Object[] {name, integer}));
  137. this.loadTexture(resourcelocation, texture);
  138. return resourcelocation;
  139. }
  140.  
  141. public void tick()
  142. {
  143. for (Object itickable : this.listTickables)
  144. {
  145. ((ITickable) itickable).tick();
  146. }
  147. }
  148.  
  149. public void deleteTexture(ResourceLocation textureLocation)
  150. {
  151. ITextureObject itextureobject = this.getTexture(textureLocation);
  152.  
  153. if (itextureobject != null)
  154. {
  155. this.mapTextureObjects.remove(textureLocation);
  156. TextureUtil.deleteTexture(itextureobject.getGlTextureId());
  157. }
  158. }
  159.  
  160. public void onResourceManagerReload(IResourceManager resourceManager)
  161. {
  162. Config.dbg("*** Reloading textures ***");
  163. Config.log("Resource packs: " + Config.getResourcePackNames());
  164. Iterator iterator = this.mapTextureObjects.keySet().iterator();
  165.  
  166. while (iterator.hasNext())
  167. {
  168. ResourceLocation resourcelocation = (ResourceLocation)iterator.next();
  169. String s = resourcelocation.getResourcePath();
  170.  
  171. if (s.startsWith("mcpatcher/") || s.startsWith("optifine/"))
  172. {
  173. ITextureObject itextureobject = (ITextureObject)this.mapTextureObjects.get(resourcelocation);
  174.  
  175. if (itextureobject instanceof AbstractTexture)
  176. {
  177. AbstractTexture abstracttexture = (AbstractTexture)itextureobject;
  178. abstracttexture.deleteGlTexture();
  179. }
  180.  
  181. iterator.remove();
  182. }
  183. }
  184.  
  185. for (Object entry : this.mapTextureObjects.entrySet())
  186. {
  187. this.loadTexture((ResourceLocation)((Entry) entry).getKey(), (ITextureObject)((Entry) entry).getValue());
  188. }
  189. }
  190.  
  191. public void reloadBannerTextures()
  192. {
  193. for (Object entry : this.mapTextureObjects.entrySet())
  194. {
  195. ResourceLocation resourcelocation = (ResourceLocation)((Entry) entry).getKey();
  196. ITextureObject itextureobject = (ITextureObject)((Entry) entry).getValue();
  197.  
  198. if (itextureobject instanceof LayeredColorMaskTexture)
  199. {
  200. this.loadTexture(resourcelocation, itextureobject);
  201. }
  202. }
  203. }
  204. }
  205.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement