aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/neodymium/util/OFUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/makamys/neodymium/util/OFUtil.java')
-rw-r--r--src/main/java/makamys/neodymium/util/OFUtil.java34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/main/java/makamys/neodymium/util/OFUtil.java b/src/main/java/makamys/neodymium/util/OFUtil.java
index c98a651..6c007ca 100644
--- a/src/main/java/makamys/neodymium/util/OFUtil.java
+++ b/src/main/java/makamys/neodymium/util/OFUtil.java
@@ -1,13 +1,19 @@
package makamys.neodymium.util;
-import makamys.neodymium.MixinConfigPlugin;
+import static makamys.neodymium.Constants.LOGGER;
+
+import java.lang.reflect.Field;
+
import makamys.neodymium.ducks.IMixinGameSettings_OptiFine;
import net.minecraft.client.Minecraft;
public class OFUtil {
- private static boolean isOptiFinePresent = MixinConfigPlugin.class.getResource("/optifine/OptiFineTweaker.class") != null;
+ private static boolean isOptiFinePresent, hasCheckedIsOptiFinePresent;
public static boolean isOptiFinePresent() {
+ if(!hasCheckedIsOptiFinePresent) {
+ checkIfOptiFineIsPresent();
+ }
return isOptiFinePresent;
}
@@ -15,6 +21,30 @@ public class OFUtil {
return isOptiFinePresent && getIsFogOff();
}
+ private static void checkIfOptiFineIsPresent() {
+ try {
+ Class<?> optiFineClassTransformerClass = Class.forName("optifine.OptiFineClassTransformer");
+ Field instanceField = optiFineClassTransformerClass.getField("instance");
+ Object optiFineClassTransformer = instanceField.get(null);
+ Field ofZipFileField = optiFineClassTransformerClass.getDeclaredField("ofZipFile");
+ ofZipFileField.setAccessible(true);
+ Object ofZipFile = ofZipFileField.get(optiFineClassTransformer);
+
+ if(ofZipFile != null) {
+ LOGGER.debug("OptiFineClassTransformer#ofZipFile is initialized, assuming OptiFine is present");
+ isOptiFinePresent = true;
+ } else {
+ LOGGER.debug("OptiFineClassTransformer#ofZipFile is null, assuming OptiFine is not present");
+ }
+ } catch (ClassNotFoundException e) {
+ LOGGER.debug("Couldn't load OptiFineClassTransformer class, assuming OptiFine is not present");
+ // no OF
+ } catch(Exception e) {
+ LOGGER.error("Failed to check if OptiFine is loaded, assuming it isn't. Exception: " + e);
+ }
+ hasCheckedIsOptiFinePresent = true;
+ }
+
private static boolean getIsFogOff() {
return ((IMixinGameSettings_OptiFine)Minecraft.getMinecraft().gameSettings).getOfFogType() == 3;
}