diff --git a/build.gradle b/build.gradle index f016d63..28bb684 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' group = 'com.buuz135' -version = '1.20.1-1.2.0' +version = '1.20.1-1.2.1' java { diff --git a/src/main/java/com/buuz135/darkmodeeverywhere/ClassUtil.java b/src/main/java/com/buuz135/darkmodeeverywhere/ClassUtil.java index 703b15f..fd1ef6d 100644 --- a/src/main/java/com/buuz135/darkmodeeverywhere/ClassUtil.java +++ b/src/main/java/com/buuz135/darkmodeeverywhere/ClassUtil.java @@ -6,10 +6,13 @@ import net.minecraft.client.renderer.GameRenderer; import net.minecraftforge.fml.util.ObfuscationReflectionHelper; +import java.util.stream.Stream; + public class ClassUtil { private static final String SET_SHADER_METHOD_NAME = ObfuscationReflectionHelper.remapName(INameMappingService.Domain.METHOD, "m_157427_"); + /* public static StackTraceElement getCallerCallerClassName() { StackTraceElement[] stElements = Thread.currentThread().getStackTrace(); for (int i = 1; i stackFrameStream) { + return stackFrameStream + .filter(frame -> !( + frame.getClassName().equals(GameRenderer.class.getName()) + || frame.getClassName().equals(ClassUtil.class.getName()) + || frame.getClassName().equals(RenderSystem.class.getName()) + || frame.getClassName().startsWith("java.lang.Thread") + || frame.getMethodName().equals(SET_SHADER_METHOD_NAME) + || frame.getClassName().equals(GuiGraphics.class.getName()) + )) + .findFirst() + .map(f -> f.getClassName() + ":" + f.getMethodName()) + .orElse(null); + } + + public static String getCallerClassName() { + return StackWalker.getInstance() + .walk(ClassUtil::walkForCallerClassName); + } } diff --git a/src/main/java/com/buuz135/darkmodeeverywhere/mixins/GameRenderMixin.java b/src/main/java/com/buuz135/darkmodeeverywhere/mixins/GameRenderMixin.java index fa901c6..a037612 100644 --- a/src/main/java/com/buuz135/darkmodeeverywhere/mixins/GameRenderMixin.java +++ b/src/main/java/com/buuz135/darkmodeeverywhere/mixins/GameRenderMixin.java @@ -24,14 +24,13 @@ private static void replaceDefaultShaderWithSelectedShader(CallbackInfoReturnabl @Inject(method = "getPositionTexShader", at = @At("HEAD"), cancellable = true) private static void getPositionTexShader(CallbackInfoReturnable cir) { if (ClientProxy.SELECTED_SHADER != null){ - var element = ClassUtil.getCallerCallerClassName(); - if (element == null) { + var callerClassName = ClassUtil.getCallerClassName(); + if (callerClassName == null) { replaceDefaultShaderWithSelectedShader(cir); return; } - var elementName = element.getClassName() + ":" + element.getMethodName(); - boolean elementNameIsBlacklisted = ClientProxy.isElementNameBlacklisted(elementName); + boolean elementNameIsBlacklisted = ClientProxy.isElementNameBlacklisted(callerClassName); if (!elementNameIsBlacklisted) { replaceDefaultShaderWithSelectedShader(cir);