diff options
author | makamys <makamys@outlook.com> | 2023-04-16 02:52:50 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2023-04-16 02:53:34 +0200 |
commit | e3ad4353c545837f77f8192b724127e735b53554 (patch) | |
tree | b38050a960c42fcd8a0b1187179c67fa827e4f2b /src | |
parent | 2485f023bba9dc1cdaa82fd4b330c2f93f5dda26 (diff) | |
download | Neodymium-e3ad4353c545837f77f8192b724127e735b53554.tar.gz Neodymium-e3ad4353c545837f77f8192b724127e735b53554.tar.bz2 Neodymium-e3ad4353c545837f77f8192b724127e735b53554.zip |
Disable Advanced OpenGL when warning is clicked (fixes #18)
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/makamys/neodymium/Compat.java | 36 | ||||
-rw-r--r-- | src/main/java/makamys/neodymium/Neodymium.java | 31 | ||||
-rw-r--r-- | src/main/java/makamys/neodymium/command/NeodymiumCommand.java | 43 |
3 files changed, 83 insertions, 27 deletions
diff --git a/src/main/java/makamys/neodymium/Compat.java b/src/main/java/makamys/neodymium/Compat.java index f37c1f4..b8aa0b1 100644 --- a/src/main/java/makamys/neodymium/Compat.java +++ b/src/main/java/makamys/neodymium/Compat.java @@ -16,6 +16,7 @@ import makamys.neodymium.util.virtualjar.IVirtualJar; import makamys.neodymium.util.virtualjar.VirtualJar; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.settings.GameSettings; public class Compat { @@ -33,9 +34,9 @@ public class Compat { ((ToggleableTessellator)Tessellator.instance).disableTriangulator(); } - public static void getCompatibilityWarnings(List<String> warns, List<String> criticalWarns){ + public static void getCompatibilityWarnings(List<Warning> warns, List<Warning> criticalWarns, boolean statusCommand){ if(Minecraft.getMinecraft().gameSettings.advancedOpengl) { - warns.add("Advanced OpenGL is enabled, performance may be poor."); + warns.add(new Warning("Advanced OpenGL is enabled, performance may be poor." + (statusCommand ? " Click here to disable it." : "")).action(Compat::disableAdvancedOpenGL)); } try { @@ -43,7 +44,7 @@ public class Compat { try { String shaderPack = (String)shaders.getMethod("getShaderPackName").invoke(null); if(shaderPack != null) { - criticalWarns.add("A shader pack is enabled, this is not supported."); + criticalWarns.add(new Warning("A shader pack is enabled, this is not supported.")); } } catch(Exception e) { LOGGER.warn("Failed to get shader pack name"); @@ -54,10 +55,10 @@ public class Compat { } if(!GLContext.getCapabilities().OpenGL33) { - criticalWarns.add("OpenGL 3.3 is not supported."); + criticalWarns.add(new Warning("OpenGL 3.3 is not supported.")); } if(detectedNotEnoughVRAM()) { - criticalWarns.add("Not enough VRAM"); + criticalWarns.add(new Warning("Not enough VRAM")); } } @@ -93,6 +94,17 @@ public class Compat { } } + public static boolean disableAdvancedOpenGL() { + GameSettings gameSettings = Minecraft.getMinecraft().gameSettings; + + if(gameSettings.advancedOpengl) { + gameSettings.advancedOpengl = false; + gameSettings.saveOptions(); + return true; + } + return false; + } + private static class OptiFineStubVirtualJar implements IVirtualJar { @Override @@ -112,4 +124,18 @@ public class Compat { } } + + public static class Warning { + public String text; + public Runnable action; + + public Warning(String text) { + this.text = text; + } + + public Warning action(Runnable action) { + this.action = action; + return this; + } + } } diff --git a/src/main/java/makamys/neodymium/Neodymium.java b/src/main/java/makamys/neodymium/Neodymium.java index 1b718e6..cab2e54 100644 --- a/src/main/java/makamys/neodymium/Neodymium.java +++ b/src/main/java/makamys/neodymium/Neodymium.java @@ -25,6 +25,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import makamys.mclib.core.MCLib; import makamys.mclib.core.MCLibModules; +import makamys.neodymium.Compat.Warning; import makamys.neodymium.command.NeodymiumCommand; import makamys.neodymium.config.Config; import makamys.neodymium.renderer.NeoRenderer; @@ -97,11 +98,11 @@ public class Neodymium destroyRenderer(); } if(Config.enabled && newWorld != null) { - Pair<List<String>, List<String>> warnsAndCriticalWarns = checkCompat(); - List<String> warns = warnsAndCriticalWarns.getLeft(); - List<String> criticalWarns = warnsAndCriticalWarns.getRight(); + Pair<List<Warning>, List<Warning>> warnsAndCriticalWarns = showCompatStatus(false); + List<Warning> warns = warnsAndCriticalWarns.getLeft(); + List<Warning> criticalWarns = warnsAndCriticalWarns.getRight(); - if(criticalWarns.isEmpty() || Config.ignoreIncompatibilities) { + if(criticalWarns.isEmpty()) { renderer = new NeoRenderer(newWorld); renderer.hasIncompatibilities = !warns.isEmpty() || !criticalWarns.isEmpty(); } @@ -145,7 +146,7 @@ public class Neodymium if(event.phase == TickEvent.Phase.START) { if(Compat.hasChanged()) { - Pair<List<String>, List<String>> warns = checkCompat(); + Pair<List<Warning>, List<Warning>> warns = showCompatStatus(false); if(renderer != null) { renderer.hasIncompatibilities = !warns.getLeft().isEmpty() || !warns.getRight().isEmpty(); } @@ -215,21 +216,21 @@ public class Neodymium rendererWorld = null; } - public static Pair<List<String>, List<String>> checkCompat() { - List<String> warns = new ArrayList<>(); - List<String> criticalWarns = new ArrayList<>(); + public static Pair<List<Warning>, List<Warning>> showCompatStatus(boolean statusCommand) { + List<Warning> warns = new ArrayList<>(); + List<Warning> criticalWarns = new ArrayList<>(); - Compat.getCompatibilityWarnings(warns, criticalWarns); + Compat.getCompatibilityWarnings(warns, criticalWarns, statusCommand); - if(!criticalWarns.isEmpty()) { - criticalWarns.add("Neodymium has been disabled due to a critical incompatibility."); + if(!criticalWarns.isEmpty() && !Config.ignoreIncompatibilities) { + criticalWarns.add(new Warning("Neodymium has been disabled due to a critical incompatibility.")); } - for(String warn : warns) { - LOGGER.warn(warn); + for(Warning warn : warns) { + LOGGER.warn(warn.text); } - for(String criticalWarn : criticalWarns) { - LOGGER.warn("Critical: " + criticalWarn); + for(Warning criticalWarn : criticalWarns) { + LOGGER.warn("Critical: " + criticalWarn.text); } return Pair.of(warns, criticalWarns); diff --git a/src/main/java/makamys/neodymium/command/NeodymiumCommand.java b/src/main/java/makamys/neodymium/command/NeodymiumCommand.java index b4d51a9..122e934 100644 --- a/src/main/java/makamys/neodymium/command/NeodymiumCommand.java +++ b/src/main/java/makamys/neodymium/command/NeodymiumCommand.java @@ -8,12 +8,20 @@ import java.util.function.Consumer; import org.apache.commons.lang3.tuple.Pair; +import makamys.neodymium.Compat; +import makamys.neodymium.Compat.Warning; import makamys.neodymium.Neodymium; +import makamys.neodymium.util.ChatUtil; +import makamys.neodymium.util.ChatUtil.MessageVerbosity; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.command.WrongUsageException; +import net.minecraft.event.ClickEvent; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.ClientCommandHandler; public class NeodymiumCommand extends CommandBase { @@ -29,6 +37,7 @@ public class NeodymiumCommand extends CommandBase { public static void init() { ClientCommandHandler.instance.registerCommand(new NeodymiumCommand()); registerSubCommand("status", new StatusCommand()); + registerSubCommand("disable_advanced_opengl", new DisableAdvancedOpenGLCommand()); } public static void registerSubCommand(String key, ISubCommand command) { @@ -91,17 +100,24 @@ public class NeodymiumCommand extends CommandBase { List<String> text = Neodymium.renderer.getDebugText(true); addChatMessages(sender, text); } - Pair<List<String>, List<String>> allWarns = Neodymium.checkCompat(); - List<String> warns = allWarns.getLeft(); - List<String> criticalWarns = allWarns.getRight(); - for(String line : warns) { - addColoredChatMessage(sender, "* " + line, HELP_WARNING_COLOR); + Pair<List<Warning>, List<Warning>> allWarns = Neodymium.showCompatStatus(true); + List<Warning> warns = allWarns.getLeft(); + List<Warning> criticalWarns = allWarns.getRight(); + for(Warning line : warns) { + addColoredChatMessageWithAction(sender, "* " + line.text, HELP_WARNING_COLOR, line.action); } - for(String line : criticalWarns) { - addColoredChatMessage(sender, "* " + line, ERROR_COLOR); + for(Warning line : criticalWarns) { + addColoredChatMessageWithAction(sender, "* " + line.text, ERROR_COLOR, line.action); } } + private void addColoredChatMessageWithAction(ICommandSender sender, String text, EnumChatFormatting color, Runnable action) { + ChatComponentText msg = new ChatComponentText(text); + msg.getChatStyle().setColor(color); + msg.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "neodymium disable_advanced_opengl")); + sender.addChatMessage(msg); + } + private static void addChatMessages(ICommandSender sender, Collection<String> messages) { for(String line : messages) { sender.addChatMessage(new ChatComponentText(line)); @@ -110,4 +126,17 @@ public class NeodymiumCommand extends CommandBase { } + public static class DisableAdvancedOpenGLCommand implements ISubCommand { + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if(Compat.disableAdvancedOpenGL()) { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); + ChatUtil.showNeoChatMessage(EnumChatFormatting.AQUA + "Disabled Advanced OpenGL.", MessageVerbosity.INFO); + Minecraft.getMinecraft().renderGlobal.loadRenderers(); + } + } + + } + } |