From 98703a11bee67b68eb131d8425864f6c64fc2bc1 Mon Sep 17 00:00:00 2001 From: VortexSo4 Date: Thu, 22 Oct 2026 02:32:34 +0200 Subject: [PATCH] Read only the mcmeta in the interpolated icon check (#2284) Co-authored-by: VortexSo4 --- src/main/resources/META-INF/notfine_at.cfg | 1 + .../MixinTextureMap.java | 66 +++++++++++++++---- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/main/resources/META-INF/notfine_at.cfg b/src/main/resources/META-INF/notfine_at.cfg index beeffbabb..7ce216cc5 100644 --- a/src/main/resources/META-INF/notfine_at.cfg +++ b/src/main/resources/META-INF/notfine_at.cfg @@ -14,5 +14,6 @@ public net.minecraft.block.BlockLeaves field_150129_M public net.minecraft.client.renderer.texture.TextureAtlasSprite field_110982_k #animationMetadata #For interpolated icon mixin public net.minecraft.client.resources.SimpleResource field_110530_g #mcmetaJson +public net.minecraft.client.resources.FallbackResourceManager field_110539_b #frmMetadataSerializer #To prevent mods from un-disabling FOV changes public-f net.minecraftforge.client.event.FOVUpdateEvent fov # fov \ No newline at end of file diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/notfine/interpolatedtexturemap/MixinTextureMap.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/notfine/interpolatedtexturemap/MixinTextureMap.java index 1a78a16ab..ad988a870 100644 --- a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/notfine/interpolatedtexturemap/MixinTextureMap.java +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/notfine/interpolatedtexturemap/MixinTextureMap.java @@ -1,6 +1,12 @@ package com.gtnewhorizons.angelica.mixins.early.notfine.interpolatedtexturemap; import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.List; import jss.notfine.render.InterpolatedIcon; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.AbstractTexture; @@ -8,8 +14,9 @@ import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.ITickableTextureObject; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.client.resources.IResource; -import net.minecraft.client.resources.SimpleResource; +import net.minecraft.client.resources.FallbackResourceManager; +import net.minecraft.client.resources.IResourcePack; +import net.minecraft.client.resources.SimpleReloadableResourceManager; import net.minecraft.util.ResourceLocation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -35,21 +42,56 @@ public abstract class MixinTextureMap extends AbstractTexture implements ITickab @Unique private Object createInterpolatedIcon(Object original){ + // Icons registered while Forge skips the first atlas load are thrown away again + if (((TextureMap) (Object) this).skipFirst) { + return original; + } TextureAtlasSprite tas = (TextureAtlasSprite) original; String textureName = tas.getIconName(); try { - IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(completeResourceLocation(new ResourceLocation(textureName), 0)); - if (resource instanceof SimpleResource) { - //This returns IMetadataSections, which seems to already remove unused mcmeta fields in 1.7.10 - //I'm just running this to populate the mcmetaJson field more easily; this does it for us - if (resource.getMetadata("animation") != null) { - JsonObject mcmetaJson = ((SimpleResource) resource).mcmetaJson; - if (mcmetaJson.getAsJsonObject("animation").getAsJsonPrimitive("interpolate").getAsBoolean()) { - return new InterpolatedIcon(textureName); - } - } + if (wantsInterpolation(completeResourceLocation(new ResourceLocation(textureName), 0))) { + return new InterpolatedIcon(textureName); } } catch (Exception ignored) {/*Should quietly fail, no need to fail hard*/} return original; } + + /** + * Reads only the mcmeta, taken from the same pack {@link FallbackResourceManager#getResource} would take it from. + * Fetching the resource itself opens the image too, which for generated textures means generating them. + */ + @Unique + private static boolean wantsInterpolation(ResourceLocation texture) throws IOException { + if (!(Minecraft.getMinecraft().getResourceManager() instanceof SimpleReloadableResourceManager manager)) { + return false; + } + if (!(manager.domainResourceManagers.get(texture.getResourceDomain()) instanceof FallbackResourceManager domain)) { + return false; + } + ResourceLocation mcmeta = new ResourceLocation(texture.getResourceDomain(), texture.getResourcePath() + ".mcmeta"); + List packs = domain.resourcePacks; + IResourcePack mcmetaPack = null; + for (int i = packs.size() - 1; i >= 0; i--) { + IResourcePack pack = packs.get(i); + if (mcmetaPack == null && pack.resourceExists(mcmeta)) { + mcmetaPack = pack; + } + if (!pack.resourceExists(texture)) { + continue; + } + if (mcmetaPack == null) { + return false; + } + JsonObject mcmetaJson; + try (InputStream in = mcmetaPack.getInputStream(mcmeta)) { + mcmetaJson = new JsonParser().parse(new InputStreamReader(in, StandardCharsets.UTF_8)).getAsJsonObject(); + } + // Same validation the animation section gets when Minecraft reads it + if (domain.frmMetadataSerializer.parseMetadataSection("animation", mcmetaJson) == null) { + return false; + } + return mcmetaJson.getAsJsonObject("animation").getAsJsonPrimitive("interpolate").getAsBoolean(); + } + return false; + } }