Skip to content

Commit

Permalink
Improved performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Buuz135 committed Jun 27, 2023
1 parent 1d497d3 commit f2f2f55
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/buuz135/darkmodeeverywhere/ClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<stElements.length; i++) {
Expand All @@ -26,4 +29,25 @@ public static StackTraceElement getCallerCallerClassName() {
}
return null;
}
*/

private static String walkForCallerClassName(Stream<StackWalker.StackFrame> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ private static void replaceDefaultShaderWithSelectedShader(CallbackInfoReturnabl
@Inject(method = "getPositionTexShader", at = @At("HEAD"), cancellable = true)
private static void getPositionTexShader(CallbackInfoReturnable<ShaderInstance> 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);
Expand Down

0 comments on commit f2f2f55

Please sign in to comment.