Skip to content

Commit

Permalink
Fix all warnings turning off advanced opengl when clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
makamys committed May 16, 2023
1 parent e09b4ea commit 41ee830
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/main/java/makamys/neodymium/Compat.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static void disableTriangulator() {

public static void getCompatibilityWarnings(List<Warning> warns, List<Warning> criticalWarns, boolean statusCommand){
if(Minecraft.getMinecraft().gameSettings.advancedOpengl) {
warns.add(new Warning("Advanced OpenGL is enabled, performance may be poor." + (statusCommand ? " Click here to disable it." : "")).action(Compat::disableAdvancedOpenGL));
warns.add(new Warning("Advanced OpenGL is enabled, performance may be poor." + (statusCommand ? " Click here to disable it." : "")).chatAction("neodymium disable_advanced_opengl"));
}

try {
Expand Down Expand Up @@ -131,14 +131,14 @@ public InputStream getInputStream(String path) {

public static class Warning {
public String text;
public Runnable action;
public String chatAction;

public Warning(String text) {
this.text = text;
}

public Warning action(Runnable action) {
this.action = action;
public Warning chatAction(String command) {
this.chatAction = command;
return this;
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/makamys/neodymium/command/NeodymiumCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,19 @@ public void processCommand(ICommandSender sender, String[] args) {
List<Warning> warns = allWarns.getLeft();
List<Warning> criticalWarns = allWarns.getRight();
for(Warning line : warns) {
addColoredChatMessageWithAction(sender, "* " + line.text, HELP_WARNING_COLOR, line.action);
addColoredChatMessageWithAction(sender, "* " + line.text, HELP_WARNING_COLOR, line.chatAction);
}
for(Warning line : criticalWarns) {
addColoredChatMessageWithAction(sender, "* " + line.text, ERROR_COLOR, line.action);
addColoredChatMessageWithAction(sender, "* " + line.text, ERROR_COLOR, line.chatAction);
}
}

private void addColoredChatMessageWithAction(ICommandSender sender, String text, EnumChatFormatting color, Runnable action) {
private void addColoredChatMessageWithAction(ICommandSender sender, String text, EnumChatFormatting color, String command) {
ChatComponentText msg = new ChatComponentText(text);
msg.getChatStyle().setColor(color);
msg.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "neodymium disable_advanced_opengl"));
if(command != null) {
msg.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
}
sender.addChatMessage(msg);
}

Expand Down

0 comments on commit 41ee830

Please sign in to comment.