Skip to content

Commit

Permalink
Add ReflectionUtils.isOptifineShadowPass() (thanks to NyaNLI)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Jul 30, 2021
1 parent dc064ec commit be5b253
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions src/main/java/mchorse/mclib/utils/ReflectionUtils.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package mchorse.mclib.utils;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;

import mchorse.mclib.utils.files.GlobalTree;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
Expand All @@ -18,6 +11,11 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;

public class ReflectionUtils
{
/**
Expand All @@ -27,6 +25,16 @@ public class ReflectionUtils
*/
public static Field TEXTURE_MAP;

/**
* Whether isShadowPass field was checked
*/
private static boolean SHADOW_PASS_CHECK;

/**
* Optifine's shadow pass field
*/
private static Field SHADOW_PASS;

/**
* Get texture map from texture manager using reflection API
*/
Expand Down Expand Up @@ -108,4 +116,37 @@ public static boolean registerResourcePack(IResourcePack pack)

return false;
}

/**
* Checks whether Optifine is currently rendering shadow map. Thanks to
* NyaNLI for suggesting how to do it!
*/
public static boolean isOptifineShadowPass()
{
if (!SHADOW_PASS_CHECK)
{
try
{
Class clazz = Class.forName("net.optifine.shaders.Shaders");

SHADOW_PASS = clazz.getDeclaredField("isShadowPass");
}
catch (Exception e)
{}

SHADOW_PASS_CHECK = true;
}

if (SHADOW_PASS != null)
{
try
{
return (boolean) SHADOW_PASS.get(null);
}
catch (Exception e)
{}
}

return false;
}
}

0 comments on commit be5b253

Please sign in to comment.