Improve perf of TextureHelper.textureExists (#292)

This commit is contained in:
tiffit authored and GitHub committed 2026-06-01 23:46:17 +02:00
1 parent 5cb66f400b
commit c422066a0f
2 files changed
+22 -1

No files matched your search

@@ -1,6 +1,10 @@
package tconstruct.library.util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.FallbackResourceManager;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourcePack;
import net.minecraft.client.resources.SimpleReloadableResourceManager;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.relauncher.Side;
@@ -13,9 +17,22 @@ public final class TextureHelper {
@SideOnly(Side.CLIENT)
public static boolean textureExists(ResourceLocation texture) {
final IResourceManager resMan = Minecraft.getMinecraft().getResourceManager();
if (resMan instanceof SimpleReloadableResourceManager simple) {
FallbackResourceManager fallback = simple.domainResourceManagers.get(texture.getResourceDomain());
if (fallback != null) {
for (IResourcePack rp : fallback.resourcePacks) {
if (rp != null && rp.resourceExists(texture)) {
return true;
}
}
return false;
}
}
// Fallback
try {
Minecraft.getMinecraft().getResourceManager().getAllResources(texture);
resMan.getAllResources(texture);
return true;
} catch (Throwable t) { // pokemon!
return false;
@@ -40,4 +40,8 @@ public net.minecraft.server.management.ItemInWorldManager field_73087_g
public net.minecraft.server.management.ItemInWorldManager field_73099_h
# EntitySlime
public net.minecraft.entity.monster.EntitySlime func_70799_a(I)V #setSlimeSize
# SimpleReloadableResourceManager
public net.minecraft.client.resources.SimpleReloadableResourceManager field_110548_a # domainResourceManagers
# FallbackResourceManager
public net.minecraft.client.resources.FallbackResourceManager field_110540_a # resourcePacks
# needs to have a space at the end of every line or SS will derp