diff options
author | hannibal002 <lo.scherf@gmail.com> | 2022-10-07 20:56:43 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-10-07 20:56:43 +0200 |
commit | 298a1bcf079e10b85dcadeabf7efcb1168dec982 (patch) | |
tree | 683528c49ec2c995043b784ba51c5297f3196c0a | |
parent | 98ec7b09eec00e57632a92a0f9245dc755d386ae (diff) | |
download | NotEnoughUpdates-298a1bcf079e10b85dcadeabf7efcb1168dec982.tar.gz NotEnoughUpdates-298a1bcf079e10b85dcadeabf7efcb1168dec982.tar.bz2 NotEnoughUpdates-298a1bcf079e10b85dcadeabf7efcb1168dec982.zip |
Squashed utility changed from the minion helper branchsquashed_utility_changes_from_minion_helper_2
Original code by hannibal002
Squashed by nea89
56 files changed, 680 insertions, 433 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 598ecc2e..6e6eb824 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -132,6 +132,8 @@ public class NEUManager { private final HashMap<String, Set<NeuRecipe>> recipesMap = new HashMap<>(); private final HashMap<String, Set<NeuRecipe>> usagesMap = new HashMap<>(); + private final Map<String, String> displayNameCache = new HashMap<>(); + public String latestRepoCommit = null; public File configLocation; @@ -157,10 +159,6 @@ public class NEUManager { repoLocation.mkdir(); } - public void setCurrentProfile(String currentProfile) { - SBInfo.getInstance().currentProfile = currentProfile; - } - public String getCurrentProfile() { return SBInfo.getInstance().currentProfile; } @@ -1577,6 +1575,7 @@ public class NEUManager { new RepositoryReloadEvent(repoLocation, !hasBeenLoadedBefore).post(); hasBeenLoadedBefore = true; comp.complete(null); + displayNameCache.clear(); } catch (Exception e) { comp.completeExceptionally(e); } @@ -1593,4 +1592,30 @@ public class NEUManager { public boolean isValidInternalName(String internalName) { return itemMap.containsKey(internalName); } + + public String getDisplayName(String internalName) { + if (displayNameCache.containsKey(internalName)) { + return displayNameCache.get(internalName); + } + + String displayName = null; + TreeMap<String, JsonObject> itemInformation = NotEnoughUpdates.INSTANCE.manager.getItemInformation(); + if (itemInformation.containsKey(internalName)) { + JsonObject jsonObject = itemInformation.get(internalName); + if (jsonObject.has("displayname")) { + displayName = jsonObject.get("displayname").getAsString(); + } + } + + if (displayName == null) { + displayName = internalName; + Utils.showOutdatedRepoNotification(); + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) { + Utils.addChatMessage("§c[NEU] Found no display name in repo for '" + internalName + "'!"); + } + } + + displayNameCache.put(internalName, displayName); + return displayName; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java index 972557c8..bad9afe8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java @@ -23,6 +23,7 @@ import io.github.moulberry.notenoughupdates.BuildFlags; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.core.config.GuiPositionEditor; +import io.github.moulberry.notenoughupdates.core.util.MiscUtils; import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent; @@ -30,6 +31,8 @@ import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.Specia import io.github.moulberry.notenoughupdates.miscgui.GuiPriceGraph; import io.github.moulberry.notenoughupdates.util.PronounDB; import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.TabListUtils; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.command.CommandException; @@ -56,6 +59,7 @@ public class DevTestCommand extends ClientCommandBase { "lrg89", "dediamondpro", "lulonaut", + "hannibal2", "craftyoldminer", "eisengolem", "whalker", @@ -110,8 +114,7 @@ public class DevTestCommand extends ClientCommandBase { Minecraft.getMinecraft().getNetHandler().getNetworkManager().closeChannel(component); return; } - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - DEV_FAIL_STRINGS[devFailIndex++])); + Utils.addChatMessage(EnumChatFormatting.RED + DEV_FAIL_STRINGS[devFailIndex++]); return; } if (args.length >= 1 && args[0].equalsIgnoreCase("profileinfo")) { @@ -163,7 +166,8 @@ public class DevTestCommand extends ClientCommandBase { return; } if (args.length == 1 && args[0].equalsIgnoreCase("dev")) { - NotEnoughUpdates.INSTANCE.config.hidden.dev = true; + NotEnoughUpdates.INSTANCE.config.hidden.dev = !NotEnoughUpdates.INSTANCE.config.hidden.dev; + Utils.addChatMessage("§e[NEU] Dev mode " + (NotEnoughUpdates.INSTANCE.config.hidden.dev ? "§aenabled": "§cdisabled")); return; } if (args.length == 1 && args[0].equalsIgnoreCase("saveconfig")) { @@ -172,8 +176,7 @@ public class DevTestCommand extends ClientCommandBase { } if (args.length == 1 && args[0].equalsIgnoreCase("searchmode")) { NotEnoughUpdates.INSTANCE.config.hidden.firstTimeSearchFocus = true; - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + - "I would never search")); + Utils.addChatMessage(EnumChatFormatting.AQUA + "I would never search"); return; } if (args.length == 1 && args[0].equalsIgnoreCase("bluehair")) { @@ -183,11 +186,10 @@ public class DevTestCommand extends ClientCommandBase { if (args.length == 2 && args[0].equalsIgnoreCase("openGui")) { try { NotEnoughUpdates.INSTANCE.openGui = (GuiScreen) Class.forName(args[1]).newInstance(); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "Opening gui: " + NotEnoughUpdates.INSTANCE.openGui)); + Utils.addChatMessage("Opening gui: " + NotEnoughUpdates.INSTANCE.openGui); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | ClassCastException e) { e.printStackTrace(); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Failed to open this gui.")); + Utils.addChatMessage("Failed to open this gui."); } } if (args.length == 1 && args[0].equalsIgnoreCase("center")) { @@ -195,5 +197,13 @@ public class DevTestCommand extends ClientCommandBase { double z = Math.floor(Minecraft.getMinecraft().thePlayer.posZ) + 0.5f; Minecraft.getMinecraft().thePlayer.setPosition(x, Minecraft.getMinecraft().thePlayer.posY, z); } + if (args.length == 1 && args[0].equalsIgnoreCase("copytablist")) { + StringBuilder builder = new StringBuilder(); + for (String name : TabListUtils.getTabList()) { + builder.append(name).append("\n"); + } + MiscUtils.copyToClipboard(builder.toString()); + Utils.addChatMessage("§e[NEU] Copied tablist to clipboard!"); + } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java index e1504472..1d30a15f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.commands.dev; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.core.util.MiscUtils; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.command.CommandException; @@ -290,11 +291,10 @@ public class PackDevCommand extends ClientCommandBase { } if ((single && closest == null) || (!single && result.length() == 0)) { - mc.thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "No " + typeFriendlyName + "s found within " + dist + " blocks.")); + Utils.addChatMessage(EnumChatFormatting.RED + "No " + typeFriendlyName + "s found within " + dist + " blocks."); } else { - mc.thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.GREEN + "Copied " + typeFriendlyName + " data to clipboard")); + Utils.addChatMessage( + EnumChatFormatting.GREEN + "Copied " + typeFriendlyName + " data to clipboard"); return single ? livingBaseDataBuilder(closest, clazz) : result; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java index 756afc88..b03e7f05 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java @@ -24,11 +24,11 @@ import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.util.DiscordMarkdownBuilder; import io.github.moulberry.notenoughupdates.util.HastebinUploader; import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.command.ICommandSender; import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.ForgeVersion; import net.minecraftforge.fml.common.Loader; @@ -118,10 +118,8 @@ public class StatsCommand extends ClientCommandBase { } private static void modPrefixedMessage(String message) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.GOLD + "[" + EnumChatFormatting.RED + "NotEnoughUpdates" + EnumChatFormatting.GOLD + "]: " + - message)); - + Utils.addChatMessage( + EnumChatFormatting.GOLD + "[" + EnumChatFormatting.RED + "NotEnoughUpdates" + EnumChatFormatting.GOLD + "]: " + message); } private static String createStats() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DnCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DnCommand.java index a5a7bcca..3b697905 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DnCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DnCommand.java @@ -20,10 +20,10 @@ package io.github.moulberry.notenoughupdates.commands.dungeon; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; public class DnCommand extends ClientCommandBase { @@ -35,7 +35,6 @@ public class DnCommand extends ClientCommandBase { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { Minecraft.getMinecraft().thePlayer.sendChatMessage("/warp dungeon_hub"); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.AQUA + "Warping to:" + EnumChatFormatting.YELLOW + " Deez Nuts lmao")); + Utils.addChatMessage(EnumChatFormatting.AQUA + "Warping to:" + EnumChatFormatting.YELLOW + " Deez Nuts lmao"); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/JoinDungeonCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/JoinDungeonCommand.java index d69f86f3..5916bb61 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/JoinDungeonCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/JoinDungeonCommand.java @@ -21,10 +21,10 @@ package io.github.moulberry.notenoughupdates.commands.dungeon; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import org.apache.commons.lang3.StringUtils; @@ -40,19 +40,16 @@ public class JoinDungeonCommand extends ClientCommandBase { Minecraft.getMinecraft().thePlayer.sendChatMessage("/join " + StringUtils.join(args, " ")); } else { if (args.length != 1) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "Example Usage: /join f7, /join m6 or /join 7")); + Utils.addChatMessage(EnumChatFormatting.RED + "Example Usage: /join f7, /join m6 or /join 7"); } else { String cataPrefix = "catacombs"; if (args[0].startsWith("m")) { cataPrefix = "master_catacombs"; } String cmd = "/joindungeon " + cataPrefix + " " + args[0].charAt(args[0].length() - 1); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + "Running command: " + cmd)); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + - "The dungeon should start soon. If it doesn't, make sure you have a party of 5 people")); + Utils.addChatMessage(EnumChatFormatting.YELLOW + "Running command: " + cmd); + Utils.addChatMessage(EnumChatFormatting.YELLOW + + "The dungeon should start soon. If it doesn't, make sure you have a party of 5 people"); Minecraft.getMinecraft().thePlayer.sendChatMessage(cmd); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/MapCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/MapCommand.java index f5381adb..3967edb4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/MapCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/MapCommand.java @@ -24,6 +24,7 @@ import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.dungeons.GuiDungeonMapEditor; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.block.material.MapColor; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandException; @@ -128,8 +129,7 @@ public class MapCommand extends ClientCommandBase { e.printStackTrace(); } - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + - "Saved to file.")); + Utils.addChatMessage(EnumChatFormatting.GREEN + "Saved to file."); } return; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java index 5f709c4f..bc389ad4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java @@ -41,18 +41,9 @@ public class FeaturesCommand extends ClientCommandBase { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); + Utils.addChatMessage(""); if (Constants.MISC == null || !Constants.MISC.has("featureslist")) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "" + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + "WARNING: " + EnumChatFormatting.RESET + - EnumChatFormatting.RED + "Could not load URL from repo.")); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "" + EnumChatFormatting.RED + "Please run " + EnumChatFormatting.BOLD + "/neuresetrepo" + - EnumChatFormatting.RESET + EnumChatFormatting.RED + " and " + EnumChatFormatting.BOLD + "restart your game" + - EnumChatFormatting.RESET + EnumChatFormatting.RED + " in order to fix. " + EnumChatFormatting.DARK_RED + - EnumChatFormatting.BOLD + "If that doesn't fix it" + EnumChatFormatting.RESET + EnumChatFormatting.RED + - ", please join discord.gg/moulberry and post in #neu-support")); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); + Utils.showOutdatedRepoNotification(); return; } String url = Constants.MISC.get("featureslist").getAsString(); @@ -60,9 +51,8 @@ public class FeaturesCommand extends ClientCommandBase { Desktop desk = Desktop.getDesktop(); try { desk.browse(new URI(url)); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.BOLD + "NEU" + EnumChatFormatting.RESET + - EnumChatFormatting.GOLD + "> Opening Feature List in browser.")); + Utils.addChatMessage( EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.BOLD + "NEU" + EnumChatFormatting.RESET + + EnumChatFormatting.GOLD + "> Opening Feature List in browser."); } catch (URISyntaxException | IOException ignored) { ChatComponentText clickTextFeatures = new ChatComponentText( @@ -72,6 +62,6 @@ public class FeaturesCommand extends ClientCommandBase { Minecraft.getMinecraft().thePlayer.addChatMessage(clickTextFeatures); } - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); + Utils.addChatMessage(""); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java index 7655f561..86699b79 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java @@ -22,9 +22,8 @@ package io.github.moulberry.notenoughupdates.commands.help; import com.google.common.collect.Lists; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import net.minecraft.client.Minecraft; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; import java.util.ArrayList; @@ -66,7 +65,7 @@ public class HelpCommand extends ClientCommandBase { "\u00a76/neupackdev \u00a7r\u00a77- pack creator command - getnpc, getmob(s), getarmorstand(s), getall. Optional radius argument for all." ); for (String neuHelpMessage : neuHelpMessages) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(neuHelpMessage)); + Utils.addChatMessage(neuHelpMessage); } if (NotEnoughUpdates.INSTANCE.config.hidden.dev) { ArrayList<String> neuDevHelpMessages = Lists.newArrayList( @@ -76,7 +75,7 @@ public class HelpCommand extends ClientCommandBase { ); for (String neuDevHelpMessage : neuDevHelpMessages) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(neuDevHelpMessage)); + Utils.addChatMessage(neuDevHelpMessage); } } String[] helpInfo = { @@ -89,8 +88,7 @@ public class HelpCommand extends ClientCommandBase { }; for (String message : helpInfo) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message)); + Utils.addChatMessage(message); } - } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java index 9938403c..793e652e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java @@ -22,10 +22,9 @@ package io.github.moulberry.notenoughupdates.commands.help; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import net.minecraft.client.Minecraft; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; import java.io.File; @@ -43,9 +42,9 @@ public class LinksCommand extends ClientCommandBase { try { JsonObject update = NotEnoughUpdates.INSTANCE.manager.getJsonFromFile(updateJson); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); + Utils.addChatMessage(""); NotEnoughUpdates.INSTANCE.displayLinks(update,0 ); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); + Utils.addChatMessage(""); } catch (Exception ignored) { } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java index bd8abf1d..27faa1ce 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java @@ -22,10 +22,9 @@ package io.github.moulberry.notenoughupdates.commands.misc; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.auction.CustomAHGui; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import net.minecraft.client.Minecraft; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import org.apache.commons.lang3.StringUtils; @@ -38,12 +37,11 @@ public class AhCommand extends ClientCommandBase { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "You must be on Skyblock to use this feature.")); + Utils.addChatMessage(EnumChatFormatting.RED + "You must be on Skyblock to use this feature."); } else if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey == null || NotEnoughUpdates.INSTANCE.config.apiData.apiKey.trim().isEmpty()) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "Can't open NeuAH, apikey is not set. Run /api new and put the result in settings.")); + Utils.addChatMessage( + EnumChatFormatting.RED + "Can't open NeuAH, apikey is not set. Run /api new and put the result in settings."); } else { NotEnoughUpdates.INSTANCE.openGui = new CustomAHGui(); NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.lastOpen = System.currentTimeMillis(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java index 2ba93585..b01f106b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java @@ -26,8 +26,8 @@ import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; -import java.text.DecimalFormat; import java.math.BigDecimal; +import java.text.DecimalFormat; import java.util.Arrays; import java.util.List; import java.util.Objects; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CosmeticsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CosmeticsCommand.java index f74b5813..762f18bd 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CosmeticsCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CosmeticsCommand.java @@ -22,11 +22,10 @@ package io.github.moulberry.notenoughupdates.commands.misc; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.cosmetics.GuiCosmetics; -import net.minecraft.client.Minecraft; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; public class CosmeticsCommand extends ClientCommandBase { @@ -38,8 +37,8 @@ public class CosmeticsCommand extends ClientCommandBase { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { if (!OpenGlHelper.isFramebufferEnabled() && NotEnoughUpdates.INSTANCE.config.notifications.doFastRenderNotif) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "NEU cosmetics do not work with OF Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it.")); + Utils.addChatMessage(EnumChatFormatting.RED + + "NEU cosmetics do not work with OF Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it."); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java index 75e779fc..a5f1d7f4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java @@ -77,8 +77,8 @@ public class PeekCommand extends ClientCommandBase { } if (peekScheduledFuture != null && !peekScheduledFuture.isDone()) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "[PEEK] New peek command run, cancelling old one.")); + Utils.addChatMessage( + EnumChatFormatting.RED + "[PEEK] New peek command run, cancelling old one."); peekScheduledFuture.cancel(true); } @@ -116,8 +116,7 @@ public class PeekCommand extends ClientCommandBase { EnumChatFormatting.STRIKETHROUGH + "-=-"), id); if (skyblockInfo == null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + "Skills API disabled!")); + Utils.addChatMessage(EnumChatFormatting.YELLOW + "Skills API disabled!"); } else { float totalSkillLVL = 0; float totalSkillCount = 0; @@ -188,20 +187,17 @@ public class PeekCommand extends ClientCommandBase { overallScore += cata * cata / 2000f; - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - g + "Combat: " + combatPrefix + (int) Math.floor(combat) + + Utils.addChatMessage(g + "Combat: " + combatPrefix + (int) Math.floor(combat) + (cata > 0 ? g + " - Cata: " + cataPrefix + cata : "") + - g + " - AVG: " + avgPrefix + (int) Math.floor(avgSkillLVL))); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - g + "Slayer: " + zombiePrefix + (int) Math.floor(zombie) + g + "-" + + g + " - AVG: " + avgPrefix + (int) Math.floor(avgSkillLVL)); + Utils.addChatMessage(g + "Slayer: " + zombiePrefix + (int) Math.floor(zombie) + g + "-" + spiderPrefix + (int) Math.floor(spider) + g + "-" + wolfPrefix + (int) Math.floor(wolf) + g+ "-" + endermanPrefix + (int) Math.floor(enderman) + g + "-" + - blazePrefix + (int) Math.floor(blaze))); + blazePrefix + (int) Math.floor(blaze)); } if (stats == null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + "Skills, collection and/or inventory apis disabled!")); + Utils.addChatMessage(EnumChatFormatting.YELLOW + "Skills, collection and/or inventory apis disabled!"); } else { int health = (int) stats.get("health"); int defence = (int) stats.get("defence"); @@ -229,11 +225,10 @@ public class PeekCommand extends ClientCommandBase { : EnumChatFormatting.YELLOW) : EnumChatFormatting.RED; - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - g + "Stats : " + healthPrefix + health + EnumChatFormatting.RED + "\u2764 " + - defencePrefix + defence + EnumChatFormatting.GREEN + "\u2748 " + - strengthPrefix + strength + EnumChatFormatting.RED + "\u2741 " + - intelligencePrefix + intelligence + EnumChatFormatting.AQUA + "\u270e ")); + Utils.addChatMessage( g + "Stats : " + healthPrefix + health + EnumChatFormatting.RED + "\u2764 " + + defencePrefix + defence + EnumChatFormatting.GREEN + "\u2748 " + + strengthPrefix + strength + EnumChatFormatting.RED + "\u2741 " + + intelligencePrefix + intelligence + EnumChatFormatting.AQUA + "\u270e "); } float bankBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "banking.balance"), -1); float purseBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "coin_purse"), 0); @@ -244,11 +239,10 @@ public class PeekCommand extends ClientCommandBase { (money > 200 * 1000 * 1000 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) : EnumChatFormatting.RED; - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - g + "Purse: " + moneyPrefix + Utils.shortNumberFormat(purseBalance, 0) + g + " - Bank: " + - (bankBalance == -1 ? EnumChatFormatting.YELLOW + "N/A" : moneyPrefix + - (isMe ? "4.8b" : Utils.shortNumberFormat(bankBalance, 0))) + - (networth > 0 ? g + " - Net: " + moneyPrefix + Utils.shortNumberFormat(networth, 0) : ""))); + Utils.addChatMessage( g + "Purse: " + moneyPrefix + Utils.shortNumberFormat(purseBalance, 0) + g + " - Bank: " + + (bankBalance == -1 ? EnumChatFormatting.YELLOW + "N/A" : moneyPrefix + + (isMe ? "4.8b" : Utils.shortNumberFormat(bankBalance, 0))) + + (networth > 0 ? g + " - Net: " + moneyPrefix + Utils.shortNumberFormat(networth, 0) : "")); overallScore += Math.min(2, money / (100f * 1000 * 1000)); @@ -264,8 +258,7 @@ public class PeekCommand extends ClientCommandBase { String col = NotEnoughUpdates.petRarityToColourMap.get(activePetTier); if (col == null) col = EnumChatFormatting.LIGHT_PURPLE.toString(); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(g + "Pet : " + - col + WordUtils.capitalizeFully(activePet.replace("_", " ")))); + Utils.addChatMessage(g + "Pet : " + col + WordUtils.capitalizeFully(activePet.replace("_", " "))); String overall = "Skywars Main"; if (isMe) { @@ -290,8 +283,7 @@ public class PeekCommand extends ClientCommandBase { overall = EnumChatFormatting.RED + "Played Skyblock"; } - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(g + "Overall score: " + - overall + g + " (" + Math.round(overallScore * 10) / 10f + ")")); + Utils.addChatMessage(g + "Overall score: " + overall + g + " (" + Math.round(overallScore * 10) / 10f + ")"); peekCommandExecutorService.shutdownNow(); } else { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java index e4ca497c..b5a3549c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.commands.profile; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.command.ICommandSender; @@ -38,32 +39,31 @@ public class ViewProfileCommand extends ClientCommandBase { public static final Consumer<String[]> RUNNABLE = (args) -> { if (!OpenGlHelper.isFramebufferEnabled()) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "Some parts of the profile viewer do not work with OF Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it.")); + Utils.addChatMessage(EnumChatFormatting.RED + + "Some parts of the profile viewer do not work with OF Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it."); } if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey == null || NotEnoughUpdates.INSTANCE.config.apiData.apiKey.trim().isEmpty()) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "Can't view profile, apikey is not set. Run /api new and put the result in settings.")); + Utils.addChatMessage(EnumChatFormatting.RED + + "Can't view profile, apikey is not set. Run /api new and put the result in settings."); } else if (args.length == 0) { NotEnoughUpdates.profileViewer.getProfileByName(Minecraft.getMinecraft().thePlayer.getName(), profile -> { if (profile == null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "Invalid player name/api key. Maybe api is down? Try /api new.")); + Utils.addChatMessage(EnumChatFormatting.RED + + "Invalid player name/api key. Maybe api is down? Try /api new."); } else { profile.resetCache(); NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile); } }); } else if (args.length > 1) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "Too many arguments. Usage: /neuprofile [name]")); + Utils.addChatMessage(EnumChatFormatting.RED + + "Too many arguments. Usage: /neuprofile [name]"); } else { NotEnoughUpdates.profileViewer.getProfileByName(args[0], profile -> { if (profile == null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "Invalid player name/api key. Maybe api is down? Try /api new.")); + Utils.addChatMessage(EnumChatFormatting.RED + "Invalid player name/api key. Maybe api is down? Try /api new."); } else { profile.resetCache(); NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java new file mode 100644 index 00000000..86430804 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.core.util; + +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.util.function.Consumer; + +public class ArrowPagesUtils { + + public static final int BUTTON_POSITION_RIGHT_OFFSET_X = 37; + public static final int PAGE_STRING_OFFSET_X = 22; + public static final int PAGE_STRING_OFFSET_Y = 6; + + public static final int BUTTON_WIDTH = 7; + public static final int BUTTON_HEIGHT = 11; + + public static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png"); + + public static void onDraw(int guiLeft, int guiTop, int[] topLeftButton, int currentPage, int totalPages) { + if (totalPages < 2) return; + + final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + final int scaledWidth = scaledresolution.getScaledWidth(); + final int scaledHeight = scaledresolution.getScaledHeight(); + int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; + int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; + + int buttonPositionLeftX = topLeftButton[0]; + int buttonPositionRightX = buttonPositionLeftX + BUTTON_POSITION_RIGHT_OFFSET_X; + int pageStringX = buttonPositionLeftX + PAGE_STRING_OFFSET_X; + int buttonPositionY = topLeftButton[1]; + int pageStringY = buttonPositionY + PAGE_STRING_OFFSET_Y; + + boolean leftSelected = isWithinRect( + mouseX - guiLeft, + mouseY - guiTop, + buttonPositionLeftX, + buttonPositionY, + BUTTON_WIDTH, + BUTTON_HEIGHT + ); + boolean rightSelected = isWithinRect( + mouseX - guiLeft, + mouseY - guiTop, + buttonPositionRightX, + buttonPositionY, + BUTTON_WIDTH, + BUTTON_HEIGHT + ); + Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture); + + if (currentPage != 0) + Utils.drawTexturedRect( + guiLeft + buttonPositionLeftX, guiTop + buttonPositionY, BUTTON_WIDTH, BUTTON_HEIGHT, + 34 / 256f, 48 / 256f, + leftSelected ? 37 / 256f : 5 / 256f, leftSelected ? 59 / 256f : 27 / 256f + ); + if (currentPage != totalPages - 1) + Utils.drawTexturedRect( + guiLeft + buttonPositionRightX, guiTop + buttonPositionY, BUTTON_WIDTH, BUTTON_HEIGHT, + 10 / 256f, 24 / 256f, + rightSelected ? 37 / 256f : 5 / 256f, rightSelected ? 59 / 256f : 27 / 256f + ); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + + String selectedPage = (currentPage + 1) + "/" + totalPages; + + FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; + Utils.drawStringCenteredScaledMaxWidth(selectedPage, fontRendererObj, + guiLeft + pageStringX, guiTop + pageStringY, false, 28, Color.BLACK.getRGB() + ); + } + + public static boolean onPageSwitchKey( + int currentPage, + int totalPages, + Consumer<Integer> pageChange + ) { + + int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey(); + if (Keyboard.getEventKeyState() && keyPressed == Keyboard.KEY_LEFT) { + int newPage = currentPage - 1; + pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1)); + return true; + } + if (Keyboard.getEventKeyState() && keyPressed == Keyboard.KEY_RIGHT) { + int newPage = currentPage + 1; + pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1)); + return true; + } + + return false; + } + + public static boolean onPageSwitchMouse( + int guiLeft, + int guiTop, + int[] topLeft, + int currentPage, + int totalPages, + Consumer<Integer> pageChange + ) { + + int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey(); + if (Keyboard.getEventKeyState() && keyPressed == Keyboard.KEY_LEFT) { + int newPage = currentPage - 1; + pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1)); + return true; + } + if (Keyboard.getEventKeyState() && keyPressed == Keyboard.KEY_RIGHT) { + int newPage = currentPage + 1; + pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1)); + return true; + } + + final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + final int scaledWidth = scaledresolution.getScaledWidth(); + final int scaledHeight = scaledresolution.getScaledHeight(); + int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; + int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; + + int buttonPositionLeftX = topLeft[0]; + int buttonPositionRightX = buttonPositionLeftX + BUTTON_POSITION_RIGHT_OFFSET_X; + int buttonPositionY = topLeft[1]; + + if (isWithinRect( + mouseX - guiLeft, + mouseY - guiTop, + buttonPositionLeftX, + buttonPositionY, + BUTTON_WIDTH, + BUTTON_HEIGHT + ) && + currentPage > 0) { + int newPage = currentPage - 1; + pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1)); + Utils.playPressSound(); + return true; + } + + if (isWithinRect( + mouseX - guiLeft, + mouseY - guiTop, + buttonPositionRightX, + buttonPositionY, + BUTTON_WIDTH, + BUTTON_HEIGHT + ) && + currentPage < totalPages) { + int newPage = currentPage + 1; + pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1)); + Utils.playPressSound(); + return true; + } + + return false; + } + + private static boolean isWithinRect(int x, int y, int topLeftX, int topLeftY, int width, int height) { + return topLeftX <= x && x < topLeftX + width + && topLeftY <= y && y < topLeftY + height; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java index a4f814d1..7ea9cd00 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java @@ -102,4 +102,20 @@ public class StringUtils { int start = string.lastIndexOf(toReplace); return string.substring(0, start) + replacement + string.substring(start + toReplace.length()); } + + public static String removeLastWord(String string, String splitString) { + try { + String[] split = string.split(splitString); + String rawTier = split[split.length - 1]; + return string.substring(0, string.length() - rawTier.length() - 1); + } catch (StringIndexOutOfBoundsException e) { + throw new RuntimeException("removeLastWord: '" + string + "'", e); + } + } + + public static String firstUpperLetter(String text) { + if (text.isEmpty()) return text; + String firstLetter = ("" + text.charAt(0)).toUpperCase(); + return firstLetter + text.substring(1); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.java b/src/main/java/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.java new file mode 100644 index 00000000..956acfe0 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.events; + +import com.google.gson.JsonObject; + +import javax.annotation.Nullable; + +//TODO extend the usage of this event (accessory bag and storage data) +public class ProfileDataLoadedEvent extends NEUEvent { + + @Nullable + private final JsonObject data; + + public ProfileDataLoadedEvent(@Nullable JsonObject entireApiResponse) { + this.data = entireApiResponse; + } + + @Nullable + public JsonObject getData() { + return data; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java index 0b1963d6..98ac76a3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java @@ -25,7 +25,6 @@ import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; @@ -33,7 +32,6 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapelessRecipes; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import net.minecraftforge.oredict.ShapedOreRecipe; @@ -689,7 +687,7 @@ public class DevInfoPane extends TextInfoPane { json.addProperty("modver", NotEnoughUpdates.VERSION); try { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Added: " + internalname)); + Utils.addChatMessage("Added: " + internalname); manager.writeJsonDefaultDir(json, internalname + ".json"); manager.loadItem(internalname); } catch (IOException ignored) { @@ -919,7 +917,7 @@ public class DevInfoPane extends TextInfoPane { json.addProperty("clickcommand", ""); try { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Added: " + internalname)); + Utils.addChatMessage("Added: " + internalname); manager.writeJsonDefaultDir(json, internalname + ".json"); manager.loadItem(internalname); } catch (IOException ignored) { @@ -952,7 +950,7 @@ public class DevInfoPane extends TextInfoPane { json.addProperty("clickcommand", "viewrecipe"); json.add("recipe", entry.getValue()); try { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Added: " + internalname)); + Utils.addChatMessage("Added: " + internalname); if (entry.getKey() != 0 && entry.getKey() < 32000) { manager.writeJsonDefaultDir(json, internalname + "-" + entry.getKey() + ".json"); } else { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java index de37b976..3b1382f2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java @@ -160,11 +160,11 @@ public class ChatListener { String unformatted = Utils.cleanColour(e.message.getUnformattedText()); Matcher matcher = SLAYER_XP.matcher(unformatted); if (unformatted.startsWith("You are playing on profile: ")) { - neu.manager.setCurrentProfile(unformatted + SBInfo.getInstance().setCurrentProfile(unformatted .substring("You are playing on profile: ".length()) .split(" ")[0].trim()); } else if (unformatted.startsWith("Your profile was changed to: ")) {//Your profile was changed to: - neu.manager.setCurrentProfile(unformatted + SBInfo.getInstance().setCurrentProfile(unformatted .substring("Your profile was changed to: ".length()) .split(" ")[0].trim()); } else if (unformatted.startsWith("Your new API key is ")) { @@ -173,8 +173,7 @@ public class ChatListener { 0, 36 ); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + "[NEU] API Key automatically configured")); + Utils.addChatMessage(EnumChatFormatting.YELLOW + "[NEU] API Key automatically configured"); NotEnoughUpdates.INSTANCE.saveConfig(); } else if (unformatted.startsWith("Player List Info is now disabled!")) { SBInfo.getInstance().hasNewTab = false; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java index e202b828..43a1daf9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java @@ -235,35 +235,24 @@ public class NEUEventListener { if (!NotEnoughUpdates.INSTANCE.config.hidden.loadedModBefore) { NotEnoughUpdates.INSTANCE.config.hidden.loadedModBefore = true; if (Constants.MISC == null || !Constants.MISC.has("featureslist")) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "" + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + "WARNING: " + EnumChatFormatting.RESET + - EnumChatFormatting.RED + "Could not load Feature List URL from repo.")); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "" + EnumChatFormatting.RED + "Please run " + EnumChatFormatting.BOLD + "/neuresetrepo" + - EnumChatFormatting.RESET + EnumChatFormatting.RED + " and " + EnumChatFormatting.BOLD + - "restart your game" + EnumChatFormatting.RESET + EnumChatFormatting.RED + " in order to fix. " + - EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + "If that doesn't fix it" + - EnumChatFormatting.RESET + EnumChatFormatting.RED + - ", please join discord.gg/moulberry and post in #neu-support")); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "" + EnumChatFormatting.GOLD + "To view the feature list after restarting type /neufeatures")); + Utils.showOutdatedRepoNotification(); + Utils.addChatMessage( + "" + EnumChatFormatting.GOLD + "To view the feature list after restarting type /neufeatures"); } else { String url = Constants.MISC.get("featureslist").getAsString(); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.BLUE + "It seems this is your first time using NotEnoughUpdates.")); + Utils.addChatMessage(""); + Utils.addChatMessage(EnumChatFormatting.BLUE + "It seems this is your first time using NotEnoughUpdates."); ChatComponentText clickTextFeatures = new ChatComponentText(EnumChatFormatting.YELLOW + "Click this message if you would like to view a list of NotEnoughUpdate's Features."); clickTextFeatures.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, url)); Minecraft.getMinecraft().thePlayer.addChatMessage(clickTextFeatures); } - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); + Utils.addChatMessage(""); ChatComponentText clickTextHelp = new ChatComponentText(EnumChatFormatting.YELLOW + "Click this message if you would like to view a list of NotEnoughUpdate's commands."); clickTextHelp.setChatStyle(Utils.createClickStyle(ClickEvent.Action.RUN_COMMAND, "/neuhelp")); Minecraft.getMinecraft().thePlayer.addChatMessage(clickTextHelp); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); + Utils.addChatMessage(""); } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index 6460e1ed..3ddb05f6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -83,7 +83,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StringUtils; @@ -327,8 +326,7 @@ public class RenderListener { JsonObject json = neu.manager.getItemInformation().get(resInternalname); json.addProperty("crafttext", "Requires: " + col); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "Added: " + resInternalname)); + Utils.addChatMessage("Added: " + resInternalname); neu.manager.writeJsonDefaultDir(json, resInternalname + ".json"); neu.manager.loadItem(resInternalname); } @@ -1304,17 +1302,15 @@ public class RenderListener { )) ) { writer.write(gson.toJson(jsonObject)); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + id)); + Utils.addChatMessage(EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + id); } } catch (IOException ignored) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "Error while writing file.")); + Utils.addChatMessage(EnumChatFormatting.RED + "Error while writing file."); } } catch (Exception e) { e.printStackTrace(); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details.")); + Utils.addChatMessage( + EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details."); } } } else if (Keyboard.isKeyDown(Keyboard.KEY_RETURN) && NotEnoughUpdates.INSTANCE.config.hidden.dev) { @@ -1409,8 +1405,7 @@ public class RenderListener { } else if (cachedDefinitions.containsKey(item)) { costArray.add(new JsonPrimitive(cachedDefinitions.get(item) + ":" + amountString)); } else { - mc.thePlayer.addChatMessage(new ChatComponentText( - "Change the item ID of " + item + " to the correct one and press Enter.")); + Utils.addChatMessage("Change the item ID of " + item + " to the correct one and press Enter."); NEUOverlay.getTextField().setText(item); event.setCanceled(true); typing = true; @@ -1439,17 +1434,16 @@ public class RenderListener { )) ) { writer.write(gson.toJson(newNPC)); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + displayName)); + Utils.addChatMessage( + EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + displayName); } } catch (IOException ignored) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "Error while writing file.")); + Utils.addChatMessage(EnumChatFormatting.RED + "Error while writing file."); } } catch (Exception e) { e.printStackTrace(); - mc.thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details")); + Utils.addChatMessage( + EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details"); } } } else if (NotEnoughUpdates.INSTANCE.config.hidden.dev && Keyboard.isKeyDown(Keyboard.KEY_B) && @@ -1469,9 +1463,9 @@ public class RenderListener { if (stack.getDisplayName().isEmpty() || stack.getDisplayName().equals(" ")) continue; String internalName = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); if (internalName == null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( + Utils.addChatMessage( EnumChatFormatting.RED + "ERROR: Could not get internal name for: " + EnumChatFormatting.AQUA + - stack.getDisplayName())); + stack.getDisplayName()); continue; } JsonObject itemObject = NotEnoughUpdates.INSTANCE.manager.getJsonForItem(stack); @@ -1491,13 +1485,11 @@ public class RenderListener { itemObject.add("lore", newLore); if (!NEUItemEditor.saveOnly(internalName, itemObject)) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "ERROR: Failed to save item: " + EnumChatFormatting.AQUA + - stack.getDisplayName())); + Utils.addChatMessage( + EnumChatFormatting.RED + "ERROR: Failed to save item: " + EnumChatFormatting.AQUA + stack.getDisplayName()); } } - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.AQUA + "Parsed page: " + lower.getDisplayName().getUnformattedText())); + Utils.addChatMessage(EnumChatFormatting.AQUA + "Parsed page: " + lower.getDisplayName().getUnformattedText()); event.setCanceled(true); return; } @@ -1701,7 +1693,7 @@ public class RenderListener { json.addProperty("clickcommand", "viewrecipe"); json.addProperty("modver", NotEnoughUpdates.VERSION); try { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Added: " + resInternalname)); + Utils.addChatMessage("Added: " + resInternalname); neu.manager.writeJsonDefaultDir(json, resInternalname + ".json"); neu.manager.loadItem(resInternalname); } catch (IOException ignored) { @@ -1715,4 +1707,24 @@ public class RenderListener { public void onRenderLast(RenderWorldLastEvent event) { CrystalMetalDetectorSolver.render(event.partialTicks); } + + /** + * Support for switching between different pages in the RecipeView gui via right and left arrow key + * @param event + */ + //Because GuiScreen.keyTyped does not fire the KEY_LEFT and KEY_RIGHT keys. Maybe some event cancelled it? + @SubscribeEvent + public void onMouseClick(GuiScreenEvent.KeyboardInputEvent.Post event) { + + if (!NotEnoughUpdates.INSTANCE.isOnSkyblock()) return; + + Minecraft minecraft = Minecraft.getMinecraft(); + if (minecraft == null || minecraft.thePlayer == null) return; + + GuiScreen screen = minecraft.currentScreen; + if (screen instanceof GuiItemRecipe) { + GuiItemRecipe itemRecipe = (GuiItemRecipe) screen; + itemRecipe.arrowKeyboardInput(); + } + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ScoreboardLocationChangeListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ScoreboardLocationChangeListener.java index 622b2088..3727a441 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ScoreboardLocationChangeListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ScoreboardLocationChangeListener.java @@ -31,10 +31,10 @@ public class ScoreboardLocationChangeListener { try { Thread.sleep(3000); TimersOverlay.afterPearls = TimersOverlay.heavyPearlCount(); - //Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW+"You exited the beast with ["+EnumChatFormatting.AQUA+(TimersOverlay.afterPearls-TimersOverlay.beforePearls)+EnumChatFormatting.YELLOW+"/"+EnumChatFormatting.AQUA+TimersOverlay.availablePearls+EnumChatFormatting.YELLOW+"] Heavy Pearls!")); + //Utils.sendMessageToPlayer(EnumChatFormatting.YELLOW+"You exited the beast with ["+EnumChatFormatting.AQUA+(TimersOverlay.afterPearls-TimersOverlay.beforePearls)+EnumChatFormatting.YELLOW+"/"+EnumChatFormatting.AQUA+TimersOverlay.availablePearls+EnumChatFormatting.YELLOW+"] Heavy Pearls!"); if (TimersOverlay.afterPearls - TimersOverlay.beforePearls == TimersOverlay.availablePearls) { NotEnoughUpdates.INSTANCE.config.getProfileSpecific().dailyHeavyPearlCompleted = System.currentTimeMillis(); - //Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN+"Daily "+EnumChatFormatting.DARK_AQUA+"Heavy Pearls"+EnumChatFormatting.GREEN+" Complete!")); + //Utils.sendMessageToPlayer(EnumChatFormatting.GREEN+"Daily "+EnumChatFormatting.DARK_AQUA+"Heavy Pearls"+EnumChatFormatting.GREEN+" Complete!"); } } catch (InterruptedException e) { e.printStackTrace(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java index f21d0c50..fede9bdf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java @@ -23,8 +23,8 @@ import com.google.common.collect.Lists; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiPlayerTabOverlay; import io.github.moulberry.notenoughupdates.util.NotificationHandler; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; public class CookieWarning { @@ -94,9 +94,8 @@ public class CookieWarning { } } catch (NumberFormatException e) { e.printStackTrace(); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + - "NEU ran into an issue when retrieving the Booster Cookie Timer. Check the logs for details.")); + Utils.addChatMessage(EnumChatFormatting.RED + + "NEU ran into an issue when retrieving the Booster Cookie Timer. Check the logs for details."); hasNotified = true; } if (minutes < NotEnoughUpdates.INSTANCE.config.notifications.boosterCookieWarningMins && !hasNotified) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java index ab9345cb..23115c36 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -25,10 +25,10 @@ import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag; import io.github.moulberry.notenoughupdates.util.NEUDebugLogger; import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; import net.minecraft.util.Vec3i; @@ -169,7 +169,7 @@ public class CrystalMetalDetectorSolver { NEUDebugLogger.log(NEUDebugFlag.METAL, "Known location identified."); // falls through case FOUND: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Found solution.")); + Utils.addChatMessage(EnumChatFormatting.YELLOW + "[NEU] Found solution."); if (NEUDebugFlag.METAL.isSet() && (previousState == SolutionState.INVALID || previousState == SolutionState.FAILED)) { NEUDebugLogger.log( @@ -180,14 +180,12 @@ public class CrystalMetalDetectorSolver { } break; case INVALID: - mc.thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "[NEU] Previous solution is invalid.")); + Utils.addChatMessage(EnumChatFormatting.RED + "[NEU] Previous solution is invalid."); logDiagnosticData(false); resetSolution(false); break; case FAILED: - mc.thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "[NEU] Failed to find a solution.")); + Utils.addChatMessage(EnumChatFormatting.RED + "[NEU] Failed to find a solution."); logDiagnosticData(false); resetSolution(false); break; @@ -195,8 +193,9 @@ public class CrystalMetalDetectorSolver { NEUDebugLogger.log(NEUDebugFlag.METAL, "Multiple known locations identified:"); // falls through case MULTIPLE: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + - "[NEU] Need another position to find solution. Possible blocks: " + possibleBlocks.size())); + Utils.addChatMessage( + EnumChatFormatting.YELLOW + "[NEU] Need another position to find solution. Possible blocks: " + + possibleBlocks.size()); break; default: throw new IllegalStateException("Metal detector is in invalid state"); @@ -372,8 +371,8 @@ public class CrystalMetalDetectorSolver { if (keeperEntities.size() == 0) { if (!visitKeeperMessagePrinted) { - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + - "[NEU] Approach a Keeper while holding the metal detector to enable faster treasure hunting.")); + Utils.addChatMessage(EnumChatFormatting.YELLOW + + "[NEU] Approach a Keeper while holding the metal detector to enable faster treasure hunting."); visitKeeperMessagePrinted = true; } return false; @@ -387,8 +386,8 @@ public class CrystalMetalDetectorSolver { minesCenter = keeperEntity.getPosition().add(keeperOffsets.get(keeperType.toLowerCase())); NEUDebugLogger.log(NEUDebugFlag.METAL, "Mines center: " + EnumChatFormatting.WHITE + minesCenter.toString()); - mc.thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + "[NEU] Faster treasure hunting is now enabled based on Keeper location.")); + Utils.addChatMessage( + EnumChatFormatting.YELLOW + "[NEU] Faster treasure hunting is now enabled based on Keeper location."); return true; } @@ -560,8 +559,7 @@ public class CrystalMetalDetectorSolver { } if (!NotEnoughUpdates.INSTANCE.config.mining.metalDetectorEnabled) { - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "[NEU] Metal Detector Solver is not enabled.")); + Utils.addChatMessage(EnumChatFormatting.RED + "[NEU] Metal Detector Solver is not enabled."); return; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java index 0ee29b4f..f378fdca 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java @@ -233,35 +233,35 @@ public class CrystalWishingCompassSolver { case SUCCESS: return; case STILL_PROCESSING_PRIOR_USE: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + - "[NEU] Wait a little longer before using the wishing compass again.")); + Utils.addChatMessage( + EnumChatFormatting.YELLOW + "[NEU] Wait a little longer before using the wishing compass again."); event.setCanceled(true); break; case LOCATION_TOO_CLOSE: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + - "[NEU] Move a little further before using the wishing compass again.")); + Utils.addChatMessage( + EnumChatFormatting.YELLOW + "[NEU] Move a little further before using the wishing compass again."); event.setCanceled(true); break; case POSSIBLE_TARGETS_CHANGED: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + - "[NEU] Possible wishing compass targets have changed. Solver has been reset.")); + Utils.addChatMessage( + EnumChatFormatting.YELLOW + "[NEU] Possible wishing compass targets have changed. Solver has been reset."); event.setCanceled(true); break; case NO_PARTICLES_FOR_PREVIOUS_COMPASS: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + - "[NEU] No particles detected for prior compass use. Need another position to solve.")); + Utils.addChatMessage(EnumChatFormatting.YELLOW + + "[NEU] No particles detected for prior compass use. Need another position to solve."); break; case PLAYER_IN_NUCLEUS: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + - "[NEU] Wishing compass must be used outside the nucleus for accurate results.")); + Utils.addChatMessage( + EnumChatFormatting.YELLOW + "[NEU] Wishing compass must be used outside the nucleus for accurate results."); event.setCanceled(true); break; default: throw new IllegalStateException("Unexpected wishing compass solver state: \n" + getDiagnosticMessage()); } } catch (Exception e) { - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "[NEU] Error processing wishing compass action - see log for details")); + Utils.addChatMessage(EnumChatFormatting.RED + + "[NEU] Error processing wishing compass action - see log for details"); e.printStackTrace(); event.setCanceled(true); solverState = SolverState.FAILED_EXCEPTION; @@ -374,39 +374,36 @@ public class CrystalWishingCompassSolver { showSolution(); break; case FAILED_EXCEPTION: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "[NEU] Unable to determine wishing compass target.")); + Utils.addChatMessage(EnumChatFormatting.RED + "[NEU] Unable to determine wishing compass target."); logDiagnosticData(false); break; case FAILED_TIMEOUT_NO_REPEATING: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "[NEU] Timed out waiting for repeat set of compass particles.")); + Utils.addChatMessage( + EnumChatFormatting.RED + "[NEU] Timed out waiting for repeat set of compass particles."); logDiagnosticData(false); break; case FAILED_TIMEOUT_NO_PARTICLES: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "[NEU] Timed out waiting for compass particles.")); + Utils.addChatMessage(EnumChatFormatting.RED + "[NEU] Timed out waiting for compass particles."); logDiagnosticData(false); break; case FAILED_INTERSECTION_CALCULATION: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "[NEU] Unable to determine intersection of wishing compasses.")); + Utils.addChatMessage( + EnumChatFormatting.RED + "[NEU] Unable to determine intersection of wishing compasses."); logDiagnosticData(false); break; case FAILED_INVALID_SOLUTION: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "[NEU] Failed to find solution.")); + Utils.addChatMessage(EnumChatFormatting.RED + "[NEU] Failed to find solution."); logDiagnosticData(false); break; case NEED_SECOND_COMPASS: - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + - "[NEU] Need another position to determine wishing compass target.")); + Utils.addChatMessage( + EnumChatFormatting.YELLOW + "[NEU] Need another position to determine wishing compass target."); break; } } } catch (Exception e) { - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "[NEU] Exception while calculating wishing compass solution - see log for details")); + Utils.addChatMessage( + EnumChatFormatting.RED + "[NEU] Exception while calculating wishing compass solution - see log for details"); e.printStackTrace(); } } @@ -780,15 +777,14 @@ public class CrystalWishingCompassSolver { if (solution == null) return; if (NUCLEUS_BB.isVecInside(solution)) { - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] " + - EnumChatFormatting.AQUA + "Wishing compass target is the Crystal Nucleus")); + Utils.addChatMessage(EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.AQUA + "Wishing compass target is the Crystal Nucleus"); return; } String destinationMessage = getWishingCompassDestinationsMessage(); if (!isSkytilsPresent) { - mc.thePlayer.addChatMessage(new ChatComponentText(destinationMessage)); + Utils.addChatMessage(destinationMessage); return; } @@ -798,13 +794,13 @@ public class CrystalWishingCompassSolver { String skytilsCommand = String.format("/sthw add %s %s", getSolutionCoordsText(), targetNameForSkytils); if (NotEnoughUpdates.INSTANCE.config.mining.wishingCompassAutocreateKnownWaypoints && solutionPossibleTargets.size() == 1) { - mc.thePlayer.addChatMessage(new ChatComponentText(destinationMessage)); + Utils.addChatMessage(destinationMessage); int commandResult = ClientCommandHandler.instance.executeCommand(mc.thePlayer, skytilsCommand); if (commandResult == 1) { return; } - mc.thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "[NEU] Failed to automatically run /sthw")); + Utils.addChatMessage( + EnumChatFormatting.RED + "[NEU] Failed to automatically run /sthw"); } destinationMessage += EnumChatFormatting.YELLOW + " [Add Skytils Waypoint]"; @@ -919,8 +915,8 @@ public class CrystalWishingCompassSolver { } if (!NotEnoughUpdates.INSTANCE.config.mining.wishingCompassSolver) { - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "[NEU] Wishing Compass Solver is not enabled.")); + Utils.addChatMessage(EnumChatFormatting.RED + + "[NEU] Wishing Compass Solver is not enabled."); return; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java index 75f1b427..4cdb1557 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java @@ -29,11 +29,11 @@ import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.client.event.RenderWorldLastEvent; @@ -370,7 +370,7 @@ public class FairySouls { } private static void print(String s) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(s)); + Utils.addChatMessage(s); } private static void printHelp() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java index 6244c32c..89e95e25 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java @@ -38,7 +38,6 @@ import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.inventory.ContainerChest; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Vec3i; import net.minecraftforge.client.event.RenderWorldLastEvent; @@ -93,7 +92,7 @@ public class Navigation { } } - private NotEnoughUpdates neu; + private final NotEnoughUpdates neu; public Navigation(NotEnoughUpdates notEnoughUpdates) { neu = notEnoughUpdates; @@ -379,8 +378,7 @@ public class Navigation { private void showError(String message, boolean log) { EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; if (player != null) - player.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_RED + - "[NEU-Waypoint] " + message)); + Utils.addChatMessage(EnumChatFormatting.DARK_RED + "[NEU-Waypoint] " + message); if (log) new RuntimeException("[NEU-Waypoint] " + message).printStackTrace(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java index 776e3647..20fa553f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -1087,7 +1087,7 @@ public class PetInfoOverlay extends TextOverlay { PetInfoOverlay.config.selectedPet = -1; Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( EnumChatFormatting.RED + "[NEU] Can't find pet \u00a7" + petStringMatch + - EnumChatFormatting.RED + " try revisiting all pages of /pets.")); + EnumChatFormatting.RED + " try revisiting all pages of /pets.")); } } } else if ((chatMessage.toLowerCase().startsWith("you despawned your")) || (chatMessage.toLowerCase().contains( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java index e06c271f..0a1e5b81 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java @@ -21,6 +21,7 @@ package io.github.moulberry.notenoughupdates.miscgui; import com.google.common.collect.ImmutableList; import io.github.moulberry.notenoughupdates.NEUManager; +import io.github.moulberry.notenoughupdates.core.util.ArrowPagesUtils; import io.github.moulberry.notenoughupdates.recipes.NeuRecipe; import io.github.moulberry.notenoughupdates.recipes.RecipeSlot; import io.github.moulberry.notenoughupdates.recipes.RecipeType; @@ -38,9 +39,7 @@ import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import java.awt.*; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -49,13 +48,10 @@ import java.util.List; import java.util.Map; public class GuiItemRecipe extends GuiScreen { - public static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png"); public static final ResourceLocation tabsTexture = new ResourceLocation("notenoughupdates", "textures/gui/tab.png"); public static final int SLOT_SIZE = 16; public static final int SLOT_SPACING = SLOT_SIZE + 2; - public static final int BUTTON_WIDTH = 7; - public static final int BUTTON_HEIGHT = 11; public static final int TITLE_X = 28; public static final int TITLE_Y = 6; public static final int HOTBAR_SLOT_X = 8; @@ -145,7 +141,8 @@ public class GuiItemRecipe extends GuiScreen { Utils.drawItemStack(slot.getItemStack(), slot.getX(this), slot.getY(this), true); } - drawArrows(currentRecipe, mouseX, mouseY); + int[] topLeft = currentRecipe.getPageFlipPositionLeftTopCorner(); + ArrowPagesUtils.onDraw(guiLeft, guiTop, topLeft, currentIndex, getCurrentRecipeList().size()); Utils.drawStringScaledMaxWidth( currentRecipe.getTitle(), @@ -220,61 +217,6 @@ public class GuiItemRecipe extends GuiScreen { } } - public static final int BUTTON_POSITION_RIGHT_OFFSET_X = 37; - public static final int PAGE_STRING_OFFSET_X = 22; - public static final int PAGE_STRING_OFFSET_Y = 6; - - private void drawArrows( - NeuRecipe currentRecipe, - int mouseX, - int mouseY - ) { - int recipeCount = getCurrentRecipeList().size(); - if (recipeCount < 2) return; - int[] topLeft = currentRecipe.getPageFlipPositionLeftTopCorner(); - int buttonPositionLeftX = topLeft[0]; - int buttonPositionRightX = buttonPositionLeftX + BUTTON_POSITION_RIGHT_OFFSET_X; - int pageStringX = buttonPositionLeftX + PAGE_STRING_OFFSET_X; - int buttonPositionY = topLeft[1]; - int pageStringY = buttonPositionY + PAGE_STRING_OFFSET_Y; - - boolean leftSelected = isWithinRect( - mouseX - guiLeft, - mouseY - guiTop, - buttonPositionLeftX, - buttonPositionY, - BUTTON_WIDTH, - BUTTON_HEIGHT - ); - boolean rightSelected = isWithinRect( - mouseX - guiLeft, - mouseY - guiTop, - buttonPositionRightX, - buttonPositionY, - BUTTON_WIDTH, - BUTTON_HEIGHT - ); - Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture); - - if (currentIndex != 0) - Utils.drawTexturedRect(guiLeft + buttonPositionLeftX, guiTop + buttonPositionY, BUTTON_WIDTH, BUTTON_HEIGHT, - 34 / 256f, 48 / 256f, - leftSelected ? 37 / 256f : 5 / 256f, leftSelected ? 59 / 256f : 27 / 256f - ); - if (currentIndex != recipeCount - 1) - Utils.drawTexturedRect(guiLeft + buttonPositionRightX, guiTop + buttonPositionY, BUTTON_WIDTH, BUTTON_HEIGHT, - 10 / 256f, 24 / 256f, - rightSelected ? 37 / 256f : 5 / 256f, rightSelected ? 59 / 256f : 27 / 256f - ); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); - - String selectedPage = (currentIndex + 1) + "/" + recipeCount; - - Utils.drawStringCenteredScaledMaxWidth(selectedPage, fontRendererObj, - guiLeft + pageStringX, guiTop + pageStringY, false, 24, Color.BLACK.getRGB() - ); - } - public List<RecipeSlot> getPlayerInventory() { List<RecipeSlot> slots = new ArrayList<>(); ItemStack[] inventory = Minecraft.getMinecraft().thePlayer.inventory.mainInventory; @@ -327,7 +269,7 @@ public class GuiItemRecipe extends GuiScreen { } @Override - protected void actionPerformed(GuiButton p_actionPerformed_1_) throws IOException { + protected void actionPerformed(GuiButton p_actionPerformed_1_) { getCurrentRecipe().actionPerformed(p_actionPerformed_1_); } @@ -336,52 +278,15 @@ public class GuiItemRecipe extends GuiScreen { super.mouseClicked(mouseX, mouseY, mouseButton); NeuRecipe currentRecipe = getCurrentRecipe(); int[] topLeft = currentRecipe.getPageFlipPositionLeftTopCorner(); - int buttonPositionLeftX = topLeft[0]; - int buttonPositionRightX = buttonPositionLeftX + BUTTON_POSITION_RIGHT_OFFSET_X; - int buttonPositionY = topLeft[1]; - - if (isWithinRect( - mouseX - guiLeft, - mouseY - guiTop, - buttonPositionLeftX, - buttonPositionY, - BUTTON_WIDTH, - BUTTON_HEIGHT - ) && - currentIndex > 0) { - changeRecipe(currentTab, currentIndex - 1); - Utils.playPressSound(); - return; - } - - if (isWithinRect( - mouseX - guiLeft, - mouseY - guiTop, - buttonPositionRightX, - buttonPositionY, - BUTTON_WIDTH, - BUTTON_HEIGHT - ) && - currentIndex < getCurrentRecipeList().size()) { - changeRecipe(currentTab, currentIndex + 1); - Utils.playPressSound(); - return; - } - - for (int i = 0; i < tabs.size(); i++) { - if (isWithinRect( - mouseX - guiLeft, - mouseY - guiTop, - TAB_POS_X, - TAB_POS_Y + TAB_OFFSET_Y * i, - TAB_SIZE_X, - TAB_SIZE_Y - )) { - changeRecipe(i, currentIndex); - Utils.playPressSound(); - return; - } - } + ArrowPagesUtils.onPageSwitchMouse( + guiLeft, + guiTop, + topLeft, + currentIndex, + getCurrentRecipeList().size(), + pageChange -> + changeRecipe(currentTab, pageChange) + ); for (RecipeSlot slot : getAllRenderedSlots()) { if (isWithinRect(mouseX, mouseY, slot.getX(this), slot.getY(this), SLOT_SIZE, SLOT_SIZE)) { @@ -398,4 +303,9 @@ public class GuiItemRecipe extends GuiScreen { currentRecipe.mouseClicked(this, mouseX, mouseY, mouseButton); } + + public void arrowKeyboardInput() { + ArrowPagesUtils.onPageSwitchKey(currentIndex, getCurrentRecipeList().size(), pageChange -> + changeRecipe(currentTab, pageChange)); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java index e6c4dc74..828e50b1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java @@ -160,7 +160,7 @@ public class TrophyRewardOverlay { texts.add("Trophy Fish Exchange"); texts.add("Magma Fish: §e" + total); - for (Map.Entry<String, Integer> entry : sortByValue(totalExchange).entrySet()) { + for (Map.Entry<String, Integer> entry : sortByValueReverse(totalExchange).entrySet()) { String name = entry.getKey(); int amount = totalAmount.get(name); String[] split = name.split(" "); @@ -206,6 +206,19 @@ public class TrophyRewardOverlay { public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet()); list.sort(Map.Entry.comparingByValue()); + + Map<K, V> result = new LinkedHashMap<>(); + for (Map.Entry<K, V> entry : list) { + result.put(entry.getKey(), entry.getValue()); + } + + return result; + } + + //TODO move into utils class maybe? + public static <K, V extends Comparable<? super V>> Map<K, V> sortByValueReverse(Map<K, V> map) { + List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet()); + list.sort(Map.Entry.comparingByValue()); Collections.reverse(list); Map<K, V> result = new LinkedHashMap<>(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayerSP.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayerSP.java index 765ed372..581a2c17 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayerSP.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayerSP.java @@ -21,10 +21,10 @@ package io.github.moulberry.notenoughupdates.mixins; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.item.EntityItem; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -42,8 +42,7 @@ public class MixinEntityPlayerSP { int slot = Minecraft.getMinecraft().thePlayer.inventory.currentItem; if (SlotLocking.getInstance().isSlotIndexLocked(slot) || SlotLocking.getInstance().isSwapedSlotLocked()) { ci.cancel(); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "NotEnoughUpdates has prevented you from dropping that locked item!")); + Utils.addChatMessage(EnumChatFormatting.RED + "NotEnoughUpdates has prevented you from dropping that locked item!"); } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java index 03fe9eff..047f61c9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java @@ -19,8 +19,6 @@ package io.github.moulberry.notenoughupdates.overlays; -import com.google.common.collect.ComparisonChain; -import com.google.common.collect.Ordering; import com.google.gson.annotations.Expose; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; @@ -29,16 +27,15 @@ import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; import io.github.moulberry.notenoughupdates.miscfeatures.ItemCooldowns; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.TabListUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiChest; -import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.init.Items; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.WorldSettings; import net.minecraftforge.fml.relauncher.Side; @@ -47,7 +44,6 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.util.vector.Vector2f; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -263,11 +259,8 @@ public class MiningOverlay extends TextTabOverlay { int forgeInt = 0; boolean commissions = false; boolean forges = false; - List<NetworkPlayerInfo> players = - playerOrdering.sortedCopy(Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap()); - for (NetworkPlayerInfo info : players) { - String name = Minecraft.getMinecraft().ingameGUI.getTabList().getPlayerName(info); + for (String name : TabListUtils.getTabList()) { if (name.contains("Mithril Powder:")) { mithrilPowder = DARK_AQUA + Utils.trimWhitespaceAndFormatCodes(name).replaceAll("\u00a7[f|F|r]", ""); continue; @@ -578,27 +571,6 @@ public class MiningOverlay extends TextTabOverlay { } } - private static final Ordering<NetworkPlayerInfo> playerOrdering = Ordering.from(new PlayerComparator()); - - @SideOnly(Side.CLIENT) - static class PlayerComparator implements Comparator<NetworkPlayerInfo> { - private PlayerComparator() {} - - public int compare(NetworkPlayerInfo o1, NetworkPlayerInfo o2) { - ScorePlayerTeam team1 = o1.getPlayerTeam(); - ScorePlayerTeam team2 = o2.getPlayerTeam(); - return ComparisonChain.start().compareTrueFirst( - o1.getGameType() != WorldSettings.GameType.SPECTATOR, - o2.getGameType() != WorldSettings.GameType.SPECTATOR - ) - .compare( - team1 != null ? team1.getRegisteredName() : "", - team2 != null ? team2.getRegisteredName() : "" - ) - .compare(o1.getGameProfile().getName(), o2.getGameProfile().getName()).result(); - } - } - @Override protected Vector2f getSize(List<String> strings) { if (NotEnoughUpdates.INSTANCE.config.mining.dwarvenOverlayIcons) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java index 41217201..af904e1d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java @@ -21,8 +21,6 @@ package io.github.moulberry.notenoughupdates.profileviewer; import io.github.moulberry.notenoughupdates.util.TexLoc; import io.github.moulberry.notenoughupdates.util.Utils; -import java.io.IOException; -import java.util.HashMap; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -36,6 +34,9 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import org.lwjgl.util.glu.Project; +import java.io.IOException; +import java.util.HashMap; + public class Panorama { private static final TexLoc tl = new TexLoc(97, 19, Keyboard.KEY_P); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.java index 7df88964..6f541833 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.java @@ -20,14 +20,15 @@ package io.github.moulberry.notenoughupdates.profileviewer.bestiary; import io.github.moulberry.notenoughupdates.util.Utils; -import java.util.LinkedHashMap; -import java.util.List; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; +import java.util.LinkedHashMap; +import java.util.List; + public class BestiaryData { private static final LinkedHashMap<ItemStack, List<String>> bestiaryLocations = new LinkedHashMap<ItemStack, List<String>>() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java index e6c69649..2481b841 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java @@ -26,11 +26,6 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewerPage; import io.github.moulberry.notenoughupdates.util.Utils; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -43,6 +38,12 @@ import org.apache.commons.lang3.text.WordUtils; import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + public class TrophyFishPage extends GuiProfileViewerPage { public static final ResourceLocation pv_elements = new ResourceLocation("notenoughupdates:pv_elements.png"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilyDungeonsWeight.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilyDungeonsWeight.java index 3ceabaf5..819c16de 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilyDungeonsWeight.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilyDungeonsWeight.java @@ -26,6 +26,7 @@ import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Dungeons import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.WeightStruct; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; + import java.util.Map; public class LilyDungeonsWeight extends DungeonsWeight { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilySkillsWeight.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilySkillsWeight.java index 8ed43f6e..f47032a4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilySkillsWeight.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilySkillsWeight.java @@ -19,16 +19,17 @@ package io.github.moulberry.notenoughupdates.profileviewer.weight.lily; -import static io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Weight.SKILL_NAMES; - import com.google.gson.JsonArray; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.SkillsWeight; import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.WeightStruct; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; + import java.util.Map; +import static io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Weight.SKILL_NAMES; + public class LilySkillsWeight extends SkillsWeight { public LilySkillsWeight(Map<String, ProfileViewer.Level> player) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilySlayerWeight.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilySlayerWeight.java index d26597a1..12cb01e2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilySlayerWeight.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilySlayerWeight.java @@ -24,6 +24,7 @@ import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.SlayerWe import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.WeightStruct; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; + import java.util.Map; public class LilySlayerWeight extends SlayerWeight { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilyWeight.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilyWeight.java index 4ffc9fdd..03c5cfbf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilyWeight.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/lily/LilyWeight.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.profileviewer.weight.lily; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Weight; + import java.util.Map; public class LilyWeight extends Weight { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherDungeonsWeight.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherDungeonsWeight.java index 3b5adae5..e41b0ff4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherDungeonsWeight.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherDungeonsWeight.java @@ -24,6 +24,7 @@ import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Dungeons import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.WeightStruct; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; + import java.util.Map; public class SenitherDungeonsWeight extends DungeonsWeight { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherSkillsWeight.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherSkillsWeight.java index 2a4ee48c..7ac717f7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherSkillsWeight.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherSkillsWeight.java @@ -25,6 +25,7 @@ import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.SkillsWe import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.WeightStruct; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; + import java.util.Map; public class SenitherSkillsWeight extends SkillsWeight { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherSlayerWeight.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherSlayerWeight.java index 80853853..e9fd5b41 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherSlayerWeight.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherSlayerWeight.java @@ -25,6 +25,7 @@ import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.SlayerWe import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.WeightStruct; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; + import java.util.Map; public class SenitherSlayerWeight extends SlayerWeight { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherWeight.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherWeight.java index 2f813576..532db942 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherWeight.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/senither/SenitherWeight.java @@ -21,6 +21,7 @@ package io.github.moulberry.notenoughupdates.profileviewer.weight.senither; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Weight; + import java.util.Map; public class SenitherWeight extends Weight { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/DungeonsWeight.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/DungeonsWeight.java index 39e743aa..661c3c9f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/DungeonsWeight.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/DungeonsWeight.java @@ -20,6 +20,7 @@ package io.github.moulberry.notenoughupdates.profileviewer.weight.weight; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; + import java.util.Map; public abstract class DungeonsWeight { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/SkillsWeight.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/SkillsWeight.java index 55669f7b..b7fe27ac 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/SkillsWeight.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/SkillsWeight.java @@ -20,6 +20,7 @@ package io.github.moulberry.notenoughupdates.profileviewer.weight.weight; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; + import java.util.Map; public abstract class SkillsWeight { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/SlayerWeight.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/SlayerWeight.java index 20b2762d..bab8a154 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/SlayerWeight.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/weight/weight/SlayerWeight.java @@ -20,6 +20,7 @@ package io.github.moulberry.notenoughupdates.profileviewer.weight.weight; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; + import java.util.Map; public abstract class SlayerWeight { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java index d63ea42c..54daf42d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java @@ -33,7 +33,6 @@ import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; @@ -91,32 +90,30 @@ public class RecipeGenerator { if (uiTitle.equals("Confirm Process") && saveRecipe) { ForgeRecipe recipe = parseSingleForgeRecipe(menu); if (recipe == null) { - p.addChatMessage(new ChatComponentText( - "" + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + "Could not parse recipe for this UI")); + Utils.addChatMessage( + "" + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + "Could not parse recipe for this UI"); } else { - p.addChatMessage(new ChatComponentText( - "" + EnumChatFormatting.GREEN + EnumChatFormatting.BOLD + "Parsed recipe:")); - p.addChatMessage(new ChatComponentText("" + EnumChatFormatting.AQUA + " Inputs:")); + Utils.addChatMessage("" + EnumChatFormatting.GREEN + EnumChatFormatting.BOLD + "Parsed recipe:"); + Utils.addChatMessage("" + EnumChatFormatting.AQUA + " Inputs:"); for (Ingredient i : recipe.getInputs()) - p.addChatMessage(new ChatComponentText( - " - " + EnumChatFormatting.AQUA + i.getInternalItemId() + " x " + i.getCount())); - p.addChatMessage(new ChatComponentText("" + EnumChatFormatting.AQUA + " Output: " + EnumChatFormatting.GOLD + - recipe.getOutput().getInternalItemId() + " x " + recipe.getOutput().getCount())); - p.addChatMessage(new ChatComponentText( + Utils.addChatMessage(" - " + EnumChatFormatting.AQUA + i.getInternalItemId() + " x " + i.getCount()); + Utils.addChatMessage("" + EnumChatFormatting.AQUA + " Output: " + EnumChatFormatting.GOLD + + recipe.getOutput().getInternalItemId() + " x " + recipe.getOutput().getCount()); + Utils.addChatMessage( "" + EnumChatFormatting.AQUA + " Time: " + EnumChatFormatting.GRAY + recipe.getTimeInSeconds() + - " seconds (no QF) .")); + " seconds (no QF) ."); boolean saved = false; try { saved = saveRecipes(recipe.getOutput().getInternalItemId(), Collections.singletonList(recipe)); - } catch (IOException e) { + } catch (IOException ignored) { } if (!saved) - p.addChatMessage(new ChatComponentText("" + - EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + EnumChatFormatting.OBFUSCATED + "#" + - EnumChatFormatting.RESET + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + " ERROR " + - EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + EnumChatFormatting.OBFUSCATED + "#" + - EnumChatFormatting.RESET + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + - " Failed to save recipe. Does the item already exist?")); + Utils.addChatMessage( + "" + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + EnumChatFormatting.OBFUSCATED + "#" + + EnumChatFormatting.RESET + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + " ERROR " + + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + EnumChatFormatting.OBFUSCATED + "#" + + EnumChatFormatting.RESET + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + + " Failed to save recipe. Does the item already exist?"); } } if (saveRecipe) attemptToSaveBestiary(menu); @@ -171,8 +168,7 @@ public class RecipeGenerator { for (String loreLine : mobLore) { Matcher loreMatcher = LORE_PATTERN.matcher(loreLine); if (!loreMatcher.matches()) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "[WARNING] Unknown lore line: " + loreLine)); + Utils.addChatMessage("[WARNING] Unknown lore line: " + loreLine); continue; } if (loreMatcher.group("coins") != null) @@ -186,8 +182,7 @@ public class RecipeGenerator { List<JsonObject> possibleItems = neu.manager.getItemInformation().values().stream().filter(it -> it.get( "displayname").getAsString().equals(dropName)).collect(Collectors.toList()); if (possibleItems.size() != 1) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "[WARNING] Could not parse drop, ambiguous or missing item information: " + loreLine)); + Utils.addChatMessage("[WARNING] Could not parse drop, ambiguous or missing item information: " + loreLine); continue; } Ingredient item = new Ingredient(neu.manager, possibleItems.get(0).get("internalname").getAsString()); @@ -197,9 +192,7 @@ public class RecipeGenerator { drops.add(new MobLootRecipe.MobDrop(item, chance, new ArrayList<>())); } if (loreMatcher.group("missing") != null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "[WARNING] You are missing Bestiary levels for drop: " + loreLine)); - + Utils.addChatMessage("[WARNING] You are missing Bestiary levels for drop: " + loreLine); } } recipes.add(new MobLootRecipe( @@ -218,15 +211,15 @@ public class RecipeGenerator { boolean saved = false; try { saved = saveRecipes(internalMobName, recipes); - } catch (IOException e) { + } catch (IOException ignored) { } if (!saved) - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("" + - EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + EnumChatFormatting.OBFUSCATED + "#" + - EnumChatFormatting.RESET + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + " ERROR " + - EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + EnumChatFormatting.OBFUSCATED + "#" + - EnumChatFormatting.RESET + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + - " Failed to save recipe. Does the item already exist?")); // TODO: MERGE CODE OVER + Utils.addChatMessage( + "" + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + EnumChatFormatting.OBFUSCATED + "#" + + EnumChatFormatting.RESET + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + " ERROR " + + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + EnumChatFormatting.OBFUSCATED + "#" + + EnumChatFormatting.RESET + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + + " Failed to save recipe. Does the item already exist?"); // TODO: MERGE CODE OVER } private int parseIntIgnoringCommas(String text) { @@ -307,7 +300,7 @@ public class RecipeGenerator { ); } - private static Map<Character, Integer> durationSuffixLengthMap = new HashMap<Character, Integer>() {{ + private static final Map<Character, Integer> durationSuffixLengthMap = new HashMap<Character, Integer>() {{ put('d', 60 * 60 * 24); put('h', 60 * 60); put('m', 60); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java index 8c594911..32601e3e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java @@ -22,6 +22,8 @@ package io.github.moulberry.notenoughupdates.util; import com.google.gson.Gson; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent; +import net.minecraft.client.Minecraft; import org.apache.commons.io.IOUtils; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URIBuilder; @@ -47,7 +49,9 @@ import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -58,6 +62,7 @@ public class ApiUtil { private static final ExecutorService executorService = Executors.newFixedThreadPool(3); private static final String USER_AGENT = "NotEnoughUpdates/" + NotEnoughUpdates.VERSION; private static SSLContext ctx; + private final Map<String, CompletableFuture<Void>> updateTasks = new HashMap<>(); static { try { @@ -76,6 +81,23 @@ public class ApiUtil { } } + public void updateProfileData() { + updateProfileData(Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")); + } + + public void updateProfileData(String playerUuid) { + if (!updateTasks.getOrDefault(playerUuid, CompletableFuture.completedFuture(null)).isDone()) return; + + updateTasks.put(playerUuid, newHypixelApiRequest("skyblock/profiles") + .queryArgument("uuid", Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")) + .requestJson() + .handle((jsonObject, throwable) -> { + new ProfileDataLoadedEvent(jsonObject).post(); + return null; + })); + + } + public static class Request { private final List<NameValuePair> queryArguments = new ArrayList<>(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java index 1968b51e..57c4ae3b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java @@ -23,6 +23,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.inventory.ContainerChest; @@ -135,7 +136,7 @@ public class HotmInformation { public synchronized void onLobbyJoin(WorldEvent.Load event) { if (shouldReloadSoon) { shouldReloadSoon = false; - requestUpdate(false); + neu.manager.apiUtils.updateProfileData(); } } @@ -154,17 +155,7 @@ public class HotmInformation { @SubscribeEvent public synchronized void onChat(ClientChatReceivedEvent event) { if (event.message.getUnformattedText().equals("Welcome to Hypixel SkyBlock!")) - requestUpdate(false); - } - - public synchronized void requestUpdate(boolean force) { - if (updateTask.isDone() || force) { - updateTask = neu.manager.apiUtils - .newHypixelApiRequest("skyblock/profiles") - .queryArgument("uuid", Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")) - .requestJson() - .thenAccept(this::updateInformation); - } + neu.manager.apiUtils.updateProfileData(); } /* @@ -176,10 +167,13 @@ public class HotmInformation { if (level > 20) return -1; return QUICK_FORGE_MULTIPLIERS[level - 1]; } + @SubscribeEvent + public void onApiDataLoaded(ProfileDataLoadedEvent event) { + JsonObject data = event.getData(); + if (data == null) return; - public void updateInformation(JsonObject entireApiResponse) { - if (!entireApiResponse.has("success") || !entireApiResponse.get("success").getAsBoolean()) return; - JsonArray profiles = entireApiResponse.getAsJsonArray("profiles"); + if (!data.has("success") || !data.get("success").getAsBoolean()) return; + JsonArray profiles = data.getAsJsonArray("profiles"); for (JsonElement element : profiles) { JsonObject profile = element.getAsJsonObject(); String profileName = profile.get("cute_name").getAsString(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/NEUDebugLogger.java b/src/main/java/io/github/moulberry/notenoughupdates/util/NEUDebugLogger.java index 230b8ae5..e5d00a66 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/NEUDebugLogger.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/NEUDebugLogger.java @@ -34,7 +34,7 @@ public class NEUDebugLogger { public static boolean allFlagsEnabled = false; private static void chatLogger(String message) { - mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU DEBUG] " + message)); + Utils.addChatMessage(EnumChatFormatting.YELLOW + "[NEU DEBUG] " + message); } public static boolean isFlagEnabled(NEUDebugFlag flag) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java index f3a09fcc..58adb307 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java @@ -37,7 +37,6 @@ import net.minecraft.scoreboard.Score; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.scoreboard.Scoreboard; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; import net.minecraftforge.client.event.ClientChatReceivedEvent; @@ -157,8 +156,7 @@ public class SBInfo { public boolean checkForSkyblockLocation() { if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() || getLocation() == null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "[NEU] This command is not available outside SkyBlock")); + Utils.addChatMessage(EnumChatFormatting.RED + "[NEU] This command is not available outside SkyBlock"); return false; } @@ -308,7 +306,7 @@ public class SBInfo { for (NetworkPlayerInfo info : Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap()) { String name = Minecraft.getMinecraft().ingameGUI.getTabList().getPlayerName(info); if (name.startsWith(profilePrefix)) { - currentProfile = Utils.cleanColour(name.substring(profilePrefix.length())); + setCurrentProfile(Utils.cleanColour(name.substring(profilePrefix.length()))); hasNewTab = true; } else if (name.startsWith(skillsPrefix)) { String levelInfo = name.substring(skillsPrefix.length()).trim(); @@ -439,4 +437,10 @@ public class SBInfo { public JsonObject getMayorJson() { return mayorJson; } + + public void setCurrentProfile(String newProfile) { + if (!newProfile.equals(currentProfile)) { + currentProfile = newProfile; // TODO @hannibal2: maybe event + } + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java new file mode 100644 index 00000000..a0266122 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.util; + +import com.google.common.collect.ComparisonChain; +import com.google.common.collect.Ordering; +import net.minecraft.client.Minecraft; +import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.scoreboard.ScorePlayerTeam; +import net.minecraft.world.WorldSettings; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +public class TabListUtils { + + private static final Ordering<NetworkPlayerInfo> playerOrdering = Ordering.from(new PlayerComparator()); + + @SideOnly(Side.CLIENT) + static class PlayerComparator implements Comparator<NetworkPlayerInfo> { + private PlayerComparator() {} + + public int compare(NetworkPlayerInfo o1, NetworkPlayerInfo o2) { + ScorePlayerTeam team1 = o1.getPlayerTeam(); + ScorePlayerTeam team2 = o2.getPlayerTeam(); + return ComparisonChain.start().compareTrueFirst( + o1.getGameType() != WorldSettings.GameType.SPECTATOR, + o2.getGameType() != WorldSettings.GameType.SPECTATOR + ) + .compare( + team1 != null ? team1.getRegisteredName() : "", + team2 != null ? team2.getRegisteredName() : "" + ) + .compare(o1.getGameProfile().getName(), o2.getGameProfile().getName()).result(); + } + } + + public static List<String> getTabList() { + List<NetworkPlayerInfo> players = + playerOrdering.sortedCopy(Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap()); + + List<String> result = new ArrayList<>(); + + for (NetworkPlayerInfo info : players) { + String name = Minecraft.getMinecraft().ingameGUI.getTabList().getPlayerName(info); + result.add(name); + } + return result; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 2267cbea..a4da47f3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -77,6 +77,7 @@ import java.math.BigInteger; import java.nio.FloatBuffer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -146,6 +147,7 @@ public class Utils { public static Splitter PATH_SPLITTER = Splitter.on(".").omitEmptyStrings().limit(2); private static ScaledResolution lastScale = new ScaledResolution(Minecraft.getMinecraft()); private static long startTime = 0; + private static DecimalFormat simpleDoubleFormat = new DecimalFormat("0.0"); public static <T> ArrayList<T> createList(T... values) { ArrayList<T> list = new ArrayList<>(); @@ -328,6 +330,11 @@ public class Utils { } public static String shortNumberFormat(double n, int iteration) { + if (n < 3 && n > 0) { + return simpleDoubleFormat.format(n); + } + + if (n < 1000 && iteration == 0) return "" + (int) n; double d = ((long) n / 100) / 10.0; boolean isRound = (d * 10) % 10 == 0; return (d < 1000 ? @@ -1945,13 +1952,13 @@ public class Utils { if (NotEnoughUpdates.INSTANCE.config.notifications.outdatedRepo) { NotificationHandler.displayNotification(Lists.newArrayList( EnumChatFormatting.RED + EnumChatFormatting.BOLD.toString() + "Missing repo data", - EnumChatFormatting.RED + - "Data used for many NEU features is not up to date, this should normally not be the case.", - EnumChatFormatting.RED + "You can try " + EnumChatFormatting.BOLD + "/neuresetrepo" + EnumChatFormatting.RESET + - EnumChatFormatting.RED + " and restart your game" + - " to see if that fixes the issue.", - EnumChatFormatting.RED + "If the problem persists please join " + EnumChatFormatting.BOLD + - "discord.gg/moulberry" + + EnumChatFormatting.RED + + "Data used for many NEU features is not up to date, this should normally not be the case.", + EnumChatFormatting.RED + "You can try " + EnumChatFormatting.BOLD + "/neuresetrepo" + EnumChatFormatting.RESET + + EnumChatFormatting.RED + " and restart your game" + + " to see if that fixes the issue.", + EnumChatFormatting.RED + "If the problem persists please join " + EnumChatFormatting.BOLD + + "discord.gg/moulberry" + EnumChatFormatting.RESET + EnumChatFormatting.RED + " and message in " + EnumChatFormatting.BOLD + "#neu-support" + EnumChatFormatting.RESET + EnumChatFormatting.RED + " to get support" ), @@ -1999,4 +2006,13 @@ public class Utils { public static String getLastOpenChestName() { return SBInfo.getInstance().lastOpenChestName; } + + public static void addChatMessage(String message) { + EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; + if (thePlayer != null) { + thePlayer.addChatMessage(new ChatComponentText(message)); + } else { + System.out.println(message); + } + } } diff --git a/src/main/resources/assets/notenoughupdates/minion_overlay.png b/src/main/resources/assets/notenoughupdates/minion_overlay.png Binary files differnew file mode 100644 index 00000000..47fe386c --- /dev/null +++ b/src/main/resources/assets/notenoughupdates/minion_overlay.png |