From 5deb6aca33b086dd2a97dbe072c60712dcdc2608 Mon Sep 17 00:00:00 2001 From: tildejustin Date: Wed, 19 Feb 2025 13:51:04 -0500 Subject: [PATCH] fix: do optifine texture loading as optifine does and visibility of overwrite being too low after optifine's patches --- .../rift/mixin/optifine/MixinVanillaPack.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/dimdev/rift/mixin/optifine/MixinVanillaPack.java b/src/main/java/org/dimdev/rift/mixin/optifine/MixinVanillaPack.java index 0d062da..03a19bd 100644 --- a/src/main/java/org/dimdev/rift/mixin/optifine/MixinVanillaPack.java +++ b/src/main/java/org/dimdev/rift/mixin/optifine/MixinVanillaPack.java @@ -4,19 +4,15 @@ import net.minecraft.resources.VanillaPack; import net.minecraft.util.ResourceLocation; -import org.dimdev.riftloader.OptifineLoader; -import org.dimdev.utils.ReflectionUtils; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; -import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URL; import java.nio.file.Files; @@ -34,7 +30,7 @@ public class MixinVanillaPack { */ @Nullable @Overwrite(constraints = "OPTIFINE(1+)") - protected InputStream getInputStreamVanilla(ResourcePackType type, ResourceLocation location) { + public InputStream getInputStreamVanilla(ResourcePackType type, ResourceLocation location) { String pathString = type.getDirectoryName() + "/" + location.getNamespace() + "/" + location.getPath(); InputStream in = optifineResourceFisher.apply(pathString); @@ -64,18 +60,13 @@ protected InputStream getInputStreamVanilla(ResourcePackType type, ResourceLocat //Ironically Optifine does all this via reflection too, so we're actually no slower than how it otherwise works try { //Fish for the type - Class transformer = Class.forName(OptifineLoader.OPTIFINE_TRANSFORMER); - //Then the instance field Optifine helpfully hangs onto - Field instanceField = ReflectionUtils.findField(transformer, transformer); - Object instance = instanceField.get(null); - if (instance == null) throw new IllegalStateException("Transformer hasn't loaded yet?"); + Class transformer = Class.forName("net.optifine.reflect.ReflectorForge"); //Now fish for the method - Method method = transformer.getDeclaredMethod("getOptiFineResource", String.class); + Method method = transformer.getDeclaredMethod("getOptiFineResourceStream", String.class); MethodHandle handle = MethodHandles.lookup().unreflect(method); optifineResourceFisher = path -> { try { - byte[] resource = (byte[]) handle.invoke(instance, path); - return resource != null ? new ByteArrayInputStream(resource) : null; + return (InputStream) handle.invoke(path); } catch (Throwable t) { throw new RuntimeException("Error getting resource from Optifine", t); }