From e3ad4353c545837f77f8192b724127e735b53554 Mon Sep 17 00:00:00 2001 From: makamys Date: Sun, 16 Apr 2023 02:52:50 +0200 Subject: Disable Advanced OpenGL when warning is clicked (fixes #18) --- .../neodymium/command/NeodymiumCommand.java | 43 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'src/main/java/makamys/neodymium/command') 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 text = Neodymium.renderer.getDebugText(true); addChatMessages(sender, text); } - Pair, List> allWarns = Neodymium.checkCompat(); - List warns = allWarns.getLeft(); - List criticalWarns = allWarns.getRight(); - for(String line : warns) { - addColoredChatMessage(sender, "* " + line, HELP_WARNING_COLOR); + Pair, List> allWarns = Neodymium.showCompatStatus(true); + List warns = allWarns.getLeft(); + List 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 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(); + } + } + + } + } -- cgit