From 6e21cc416324bf326c4ddb4554cd74bd61c78ed2 Mon Sep 17 00:00:00 2001 From: ACGaming <4818419+ACGaming@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:13:22 +0200 Subject: [PATCH] Improve 3D Anaglyph tweak Closes #536 --- .../config/UTConfigTweaks.java | 6 +++++- .../universaltweaks/core/UTLoadingPlugin.java | 21 ++++++++++++------- .../anaglyph/mixin/UT3DAnaglyphMixin.java | 17 +++++++++++---- .../autosave/UTAutoSaveOFCompat.java | 2 +- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java index 8ae24130..82283612 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java @@ -1545,7 +1545,11 @@ public static class MiscCategory @Config.RequiresMcRestart @Config.Name("Remove 3D Anaglyph Button") - @Config.Comment("Removes the 3D Anaglyph button from the video settings menu") + @Config.Comment + ({ + "Removes the 3D Anaglyph button from the video settings menu", + "Incompatible with OptiFine" + }) public boolean ut3DAnaglyphButtonToggle = true; @Config.RequiresMcRestart diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java index 0388875d..12f9cb1d 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java @@ -24,6 +24,17 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader { public static final boolean isClient = FMLLaunchHandler.side().isClient(); public static final boolean isDev = FMLLaunchHandler.isDeobfuscatedEnvironment(); + + public static boolean emojicordLoaded; + public static boolean openModsLoaded; + public static boolean optiFineLoaded; + public static boolean randomPatchesLoaded; + public static boolean renderLibLoaded; + public static boolean spongeForgeLoaded; + public static boolean surgeLoaded; + + public static long launchTime; + private static final Map> serversideMixinConfigs = ImmutableMap.copyOf(new HashMap>() { { @@ -31,9 +42,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader put("mixins.tweaks.misc.difficulty.server.json", () -> true); } }); - public static boolean randomPatchesLoaded; - public static boolean renderLibLoaded; - public static boolean spongeForgeLoaded; + private static final Map> commonMixinConfigs = ImmutableMap.copyOf(new HashMap>() { { @@ -153,9 +162,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader put("mixins.tweaks.world.village.json", () -> UTConfigTweaks.WORLD.utVillageDistance != 32); } }); - public static boolean emojicordLoaded; - public static boolean openModsLoaded; - public static boolean surgeLoaded; + private static final Map> clientsideMixinConfigs = ImmutableMap.copyOf(new HashMap>() { { @@ -224,7 +231,6 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader put("mixins.tweaks.world.voidfog.json", () -> UTConfigTweaks.WORLD.VOID_FOG.utVoidFogToggle); } }); - public static long launchTime; static { @@ -237,6 +243,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader emojicordLoaded = UTReflectionUtil.isClassLoaded("net.teamfruit.emojicord.asm.EmojicordCorePlugin"); openModsLoaded = UTReflectionUtil.isClassLoaded("openmods.core.OpenModsClassTransformer"); + optiFineLoaded = UTReflectionUtil.isClassLoaded("optifine.OptiFineTweaker"); randomPatchesLoaded = UTReflectionUtil.isClassLoaded("com.therandomlabs.randompatches.core.RPCore"); renderLibLoaded = UTReflectionUtil.isClassLoaded("meldexun.renderlib.RenderLib"); spongeForgeLoaded = UTReflectionUtil.isClassLoaded("org.spongepowered.mod.util.CompatibilityException"); diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/buttons/anaglyph/mixin/UT3DAnaglyphMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/buttons/anaglyph/mixin/UT3DAnaglyphMixin.java index 9c2a6b54..cbb77266 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/buttons/anaglyph/mixin/UT3DAnaglyphMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/buttons/anaglyph/mixin/UT3DAnaglyphMixin.java @@ -1,9 +1,10 @@ package mod.acgaming.universaltweaks.tweaks.misc.buttons.anaglyph.mixin; -import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiVideoSettings; import net.minecraft.client.settings.GameSettings; +import com.llamalad7.mixinextras.lib.apache.commons.ArrayUtils; +import mod.acgaming.universaltweaks.core.UTLoadingPlugin; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -20,9 +21,17 @@ public class UT3DAnaglyphMixin @Final private static GameSettings.Options[] VIDEO_OPTIONS; - @Inject(method = "", at = @At("TAIL")) - public void ut3DAnaglyph(GuiScreen parentScreenIn, GameSettings gameSettingsIn, CallbackInfo ci) + @Inject(method = "initGui", at = @At(value = "HEAD")) + public void ut3DAnaglyph(CallbackInfo ci) { - VIDEO_OPTIONS = new GameSettings.Options[] {GameSettings.Options.GRAPHICS, GameSettings.Options.RENDER_DISTANCE, GameSettings.Options.AMBIENT_OCCLUSION, GameSettings.Options.FRAMERATE_LIMIT, GameSettings.Options.VIEW_BOBBING, GameSettings.Options.GUI_SCALE, GameSettings.Options.ATTACK_INDICATOR, GameSettings.Options.GAMMA, GameSettings.Options.RENDER_CLOUDS, GameSettings.Options.PARTICLES, GameSettings.Options.USE_FULLSCREEN, GameSettings.Options.ENABLE_VSYNC, GameSettings.Options.MIPMAP_LEVELS, GameSettings.Options.USE_VBO, GameSettings.Options.ENTITY_SHADOWS}; + if (UTLoadingPlugin.optiFineLoaded) return; + for (int i = 0; i < VIDEO_OPTIONS.length; i++) + { + if (VIDEO_OPTIONS[i] == GameSettings.Options.ANAGLYPH) + { + VIDEO_OPTIONS = ArrayUtils.remove(VIDEO_OPTIONS, i); + break; + } + } } } \ No newline at end of file diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/autosave/UTAutoSaveOFCompat.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/autosave/UTAutoSaveOFCompat.java index a03c9be7..7597c7ce 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/autosave/UTAutoSaveOFCompat.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/autosave/UTAutoSaveOFCompat.java @@ -21,7 +21,7 @@ public class UTAutoSaveOFCompat public static void updateOFConfig() { if (!UTLoadingPlugin.isClient) return; - if (!UTReflectionUtil.isClassLoaded("optifine.OptiFineTweaker")) return; + if (!UTLoadingPlugin.optiFineLoaded) return; try { UniversalTweaks.LOGGER.info("OptiFine detected, updating config file...");