ForgePatch/patches/minecraft/net/minecraft/client/renderer/texture/TextureMap.java.patch

175 lines
7.9 KiB
Diff

--- a/net/minecraft/client/renderer/texture/TextureMap.java
+++ b/net/minecraft/client/renderer/texture/TextureMap.java
@@ -44,6 +44,7 @@
public void func_195426_a(IResourceManager p_195426_1_, Iterable<ResourceLocation> p_195426_2_) {
this.field_195427_i.clear();
+ net.minecraftforge.client.ForgeHooksClient.onTextureStitchedPre(this);
p_195426_2_.forEach((p_195423_2_) -> {
this.func_199362_a(p_195426_1_, p_195423_2_);
});
@@ -57,8 +58,14 @@
int j = Integer.MAX_VALUE;
int k = 1 << this.field_147636_j;
- for(ResourceLocation resourcelocation : this.field_195427_i) {
+ field_147635_d.info("Max texture size: {}", i);
+ try (net.minecraftforge.fml.common.progress.ProgressBar textureLoadingBar = net.minecraftforge.fml.common.progress.StartupProgressManager.start("Texture loading", this.field_195427_i.size())) {
+ loadedSprites.clear();
+ for(ResourceLocation resourcelocation : Sets.newHashSet(this.field_195427_i)) {
+ textureLoadingBar.step(this.func_195420_b(resourcelocation).toString());
if (!this.field_94249_f.func_195668_m().equals(resourcelocation)) {
+ j = loadTexture(stitcher, p_195421_1_, resourcelocation, j, k);
+ if (true) continue; // Forge: skip the rest of this if statement, we're using loadTexture instead
ResourceLocation resourcelocation1 = this.func_195420_b(resourcelocation);
TextureAtlasSprite textureatlassprite;
@@ -84,9 +91,11 @@
stitcher.func_110934_a(textureatlassprite);
}
}
+ } // Forge: end progress bar
int l = Math.min(j, k);
int i1 = MathHelper.func_151239_c(l);
+ if (false) // FORGE: do not lower the mipmap level
if (i1 < this.field_147636_j) {
field_147635_d.warn("{}: dropping miplevel from {} to {}, because of minimum power of two: {}", this.field_94254_c, this.field_147636_j, i1, l);
this.field_147636_j = i1;
@@ -94,18 +103,25 @@
this.field_94249_f.func_147963_d(this.field_147636_j);
stitcher.func_110934_a(this.field_94249_f);
+ try (net.minecraftforge.fml.common.progress.ProgressBar bar = net.minecraftforge.fml.common.progress.StartupProgressManager.start("Texture creation", 2)) {
try {
+ bar.step("Stitching");
stitcher.func_94305_f();
} catch (StitcherException stitcherexception) {
throw stitcherexception;
}
field_147635_d.info("Created: {}x{} {}-atlas", stitcher.func_110935_a(), stitcher.func_110936_b(), this.field_94254_c);
+ bar.step("Allocating GL texture");
TextureUtil.func_180600_a(this.func_110552_b(), this.field_147636_j, stitcher.func_110935_a(), stitcher.func_110936_b());
+ }; // Forge: end progress bar
+ try (net.minecraftforge.fml.common.progress.ProgressBar bar = net.minecraftforge.fml.common.progress.StartupProgressManager.start("Texture mipmap and upload", stitcher.func_94309_g().size())) {
for(TextureAtlasSprite textureatlassprite1 : stitcher.func_94309_g()) {
- if (textureatlassprite1 == this.field_94249_f || this.func_195422_a(p_195421_1_, textureatlassprite1)) {
+ bar.step(textureatlassprite1.func_195668_m().toString());
+ // FORGE: Sprite loading is now done during stitching, short-circuit this check
+ if (true || textureatlassprite1 == this.field_94249_f || this.func_195422_a(p_195421_1_, textureatlassprite1)) {
this.field_94252_e.put(textureatlassprite1.func_195668_m(), textureatlassprite1);
try {
@@ -124,6 +140,8 @@
}
}
+ net.minecraftforge.client.ForgeHooksClient.onTextureStitchedPost(this);
+ }; // Forge: end progress bar
}
private boolean func_195422_a(IResourceManager p_195422_1_, TextureAtlasSprite p_195422_2_) {
@@ -132,6 +150,7 @@
label62: {
boolean flag;
+ if (p_195422_2_.hasCustomLoader(p_195422_1_, resourcelocation)) break label62;
try {
iresource = p_195422_1_.func_199002_a(resourcelocation);
p_195422_2_.func_195664_a(iresource, this.field_147636_j + 1);
@@ -216,4 +235,91 @@
this.field_94252_e.clear();
this.field_94258_i.clear();
}
+
+ //===================================================================================================
+ // Forge Start
+ //===================================================================================================
+
+ private final java.util.Deque<ResourceLocation> loadingSprites = new java.util.ArrayDeque<>();
+ private final java.util.Set<ResourceLocation> loadedSprites = new java.util.HashSet<>();
+
+ public String getBasePath()
+ {
+ return field_94254_c;
+ }
+
+ public int getMipmapLevels()
+ {
+ return field_147636_j;
+ }
+
+ private int loadTexture(Stitcher stitcher, IResourceManager manager, ResourceLocation resourcelocation, int j, int k)
+ {
+ if (loadedSprites.contains(resourcelocation))
+ {
+ return j;
+ }
+ TextureAtlasSprite textureatlassprite;
+ ResourceLocation resourcelocation1 = this.func_195420_b(resourcelocation);
+ for (ResourceLocation loading : loadingSprites)
+ {
+ if (resourcelocation1.equals(loading))
+ {
+ final String error = "circular model dependencies, stack: [" + com.google.common.base.Joiner.on(", ").join(loadingSprites) + "]";
+ net.minecraftforge.fml.client.ClientHooks.trackBrokenTexture(resourcelocation, error);
+ }
+ }
+ loadingSprites.addLast(resourcelocation1);
+ try (IResource iresource = manager.func_199002_a(resourcelocation1))
+ {
+ PngSizeInfo pngsizeinfo = new PngSizeInfo(iresource);
+ AnimationMetadataSection animationmetadatasection = iresource.func_199028_a(AnimationMetadataSection.field_195817_a);
+ textureatlassprite = new TextureAtlasSprite(resourcelocation, pngsizeinfo, animationmetadatasection);
+
+ for (ResourceLocation dependency : textureatlassprite.getDependencies())
+ {
+ if (!field_195427_i.contains(dependency))
+ {
+ func_199362_a(manager, dependency);
+ }
+ j = loadTexture(stitcher, manager, dependency, j, k);
+ }
+ if (textureatlassprite.hasCustomLoader(manager, resourcelocation))
+ {
+ if (textureatlassprite.load(manager, resourcelocation, field_94252_e::get))
+ {
+ return j;
+ }
+ }
+ j = Math.min(j, Math.min(textureatlassprite.func_94211_a(), textureatlassprite.func_94216_b()));
+ int j1 = Math.min(Integer.lowestOneBit(textureatlassprite.func_94211_a()), Integer.lowestOneBit(textureatlassprite.func_94216_b()));
+ if (j1 < k)
+ {
+ // FORGE: do not lower the mipmap level, just log the problematic textures
+ field_147635_d.warn("Texture {} with size {}x{} will have visual artifacts at mip level {}, it can only support level {}." +
+ "Please report to the mod author that the texture should be some multiple of 16x16.",
+ resourcelocation1, textureatlassprite.func_94211_a(), textureatlassprite.func_94216_b(), MathHelper.func_151239_c(k), MathHelper.func_151239_c(j1));
+ }
+ if (func_195422_a(manager, textureatlassprite))
+ {
+ stitcher.func_110934_a(textureatlassprite);
+ }
+ return j;
+ }
+ catch (RuntimeException runtimeexception)
+ {
+ net.minecraftforge.fml.client.ClientHooks.trackBrokenTexture(resourcelocation, runtimeexception.getMessage());
+ return j;
+ }
+ catch (IOException ioexception)
+ {
+ net.minecraftforge.fml.client.ClientHooks.trackMissingTexture(resourcelocation);
+ return j;
+ }
+ finally
+ {
+ loadingSprites.removeLast();
+ field_195427_i.add(resourcelocation1);
+ }
+ }
}