mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-25 22:54:28 +00:00
Read only the mcmeta in the interpolated icon check (#2284)
Co-authored-by: VortexSo4 <[email protected]>
This commit is contained in:
1 parent
67ca46a220
commit
98703a11be
2 files changed
+55
-12
No files matched your search
@@ -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
|
||||
+54
-12
@@ -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<IResourcePack> 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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user