From 5b3e721fc91aaba4aeb6025593f76447b90d01f3 Mon Sep 17 00:00:00 2001 From: kirillsaint Date: Thu, 31 Aug 2023 14:52:49 +0600 Subject: [PATCH] Fix --- .../java/net/silentclient/client/Client.java | 4 --- .../client/mods/render/NewMotionBlurMod.java | 15 ++++++--- .../client/utils/OptifinePatch.java | 32 +++++++++++-------- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/silentclient/client/Client.java b/src/main/java/net/silentclient/client/Client.java index 87ab869..323bc90 100644 --- a/src/main/java/net/silentclient/client/Client.java +++ b/src/main/java/net/silentclient/client/Client.java @@ -339,10 +339,6 @@ public class Client { logger.info("STARTING > ERROR: " + err.getMessage()); throw err; } - if(SilentClientTweaker.hasOptifine) { - logger.info("STARTING > optifine-patch"); - OptifinePatch.start(); - } logger.info("-------------------------------------------------"); memoryDebug("CLIENT_POST_INIT"); } diff --git a/src/main/java/net/silentclient/client/mods/render/NewMotionBlurMod.java b/src/main/java/net/silentclient/client/mods/render/NewMotionBlurMod.java index 319f2f3..5471894 100644 --- a/src/main/java/net/silentclient/client/mods/render/NewMotionBlurMod.java +++ b/src/main/java/net/silentclient/client/mods/render/NewMotionBlurMod.java @@ -1,12 +1,11 @@ package net.silentclient.client.mods.render; -import java.lang.reflect.Field; - import net.minecraft.client.settings.GameSettings; -import net.silentclient.client.Client; import net.silentclient.client.mods.Mod; import net.silentclient.client.mods.ModCategory; -import net.silentclient.client.utils.NotificationUtils; +import net.silentclient.client.utils.OptifinePatch; + +import java.lang.reflect.Field; public class NewMotionBlurMod extends Mod { private Field cachedFastRender; @@ -37,4 +36,12 @@ public class NewMotionBlurMod extends Mod { public boolean isForceDisabled() { return isFastRenderEnabled(); } + + @Override + public void onEnable() { + super.onEnable(); + if(!isFastRenderEnabled() && OptifinePatch.needPatch()) { + OptifinePatch.patch(); + } + } } diff --git a/src/main/java/net/silentclient/client/utils/OptifinePatch.java b/src/main/java/net/silentclient/client/utils/OptifinePatch.java index 1aaf412..0590f2d 100644 --- a/src/main/java/net/silentclient/client/utils/OptifinePatch.java +++ b/src/main/java/net/silentclient/client/utils/OptifinePatch.java @@ -4,32 +4,36 @@ import net.minecraft.client.Minecraft; import net.silentclient.client.Client; import java.io.File; -import java.io.FileOutputStream; +import java.io.FileInputStream; public class OptifinePatch { public static final File optifineConfig = new File(Minecraft.getMinecraft().mcDataDir, "optionsof.txt"); - public static final File optifineConfigOriginal = new File(Minecraft.getMinecraft().mcDataDir, "optionsof.txt.original"); + public static boolean fastRenderEnabled = false; + public static boolean fastRenderPatched = false; public static void init() { try { if(optifineConfig.exists()) { - optifineConfig.renameTo(optifineConfigOriginal); - } - optifineConfig.createNewFile(); - FileOutputStream outputStream = new FileOutputStream(optifineConfig); - String str = "ofFastRender:false"; - byte[] strToBytes = str.getBytes(); - outputStream.write(strToBytes); + String ofConfig = FileUtils.readInputStream(new FileInputStream(optifineConfig)); - outputStream.close(); + if(ofConfig.contains("ofFastRender:true")) { + fastRenderEnabled = true; + } + } else { + fastRenderEnabled = true; + } } catch (Exception err) { Client.logger.catching(err); } } - public static void start() { - optifineConfig.delete(); - optifineConfigOriginal.renameTo(optifineConfig); - Minecraft.getMinecraft().gameSettings.loadOptions(); + public static boolean needPatch() { + return fastRenderEnabled && !fastRenderPatched; + } + + public static void patch() { + Minecraft.getMinecraft().toggleFullscreen(); + Minecraft.getMinecraft().toggleFullscreen(); + fastRenderPatched = true; } }