From ba69e034794b7a5dc8d950ab4ba2d12370aa509f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 11 Aug 2022 13:03:30 +0200 Subject: display name (#219) --- .../moulberry/notenoughupdates/CustomItems.java | 4 +-- .../moulberry/notenoughupdates/NEUManager.java | 30 +++++++++++----------- .../notenoughupdates/itemeditor/NEUItemEditor.java | 4 +-- .../notenoughupdates/listener/RenderListener.java | 10 ++++---- .../miscfeatures/BazaarSacksProfit.java | 4 +-- .../notenoughupdates/mixins/MixinGuiContainer.java | 4 +-- .../moulberry/notenoughupdates/util/Utils.java | 22 ++++++++-------- 7 files changed, 39 insertions(+), 39 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/CustomItems.java b/src/main/java/io/github/moulberry/notenoughupdates/CustomItems.java index 06321b53..3911396f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/CustomItems.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/CustomItems.java @@ -110,11 +110,11 @@ public class CustomItems { * SHAAAAAAAAAAAAAAAAAAME */ - private static JsonObject create(String internalname, String itemid, String displayname, String... lore) { + private static JsonObject create(String internalname, String itemid, String displayName, String... lore) { JsonObject json = new JsonObject(); json.addProperty("itemid", itemid); json.addProperty("internalname", internalname); - json.addProperty("displayname", EnumChatFormatting.RED + displayname); + json.addProperty("displayname", EnumChatFormatting.RED + displayName); JsonArray jsonlore = new JsonArray(); for (String line : lore) { jsonlore.add(new JsonPrimitive(EnumChatFormatting.GRAY + line)); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index cd0d08b5..9140120a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -207,7 +207,7 @@ public class NEUManager { } public CompletableFuture fetchRepository() { - return CompletableFuture.supplyAsync(() -> { + return CompletableFuture.supplyAsync(() -> { try { JsonObject currentCommitJSON = getJsonFromFile(new File(configLocation, "currentCommit.json")); @@ -781,14 +781,14 @@ public class NEUManager { if (itemMc != null) { itemid = itemMc.getRegistryName(); } - String displayname = display.getString("Name"); + String displayName = display.getString("Name"); String[] info = new String[0]; String clickcommand = ""; JsonObject item = new JsonObject(); item.addProperty("internalname", internalname); item.addProperty("itemid", itemid); - item.addProperty("displayname", displayname); + item.addProperty("displayname", displayName); if (tag != null && tag.hasKey("ExtraAttributes", 10)) { NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); @@ -1110,7 +1110,7 @@ public class NEUManager { * json files representing skyblock item data. */ public JsonObject createItemJson( - String internalname, String itemid, String displayname, String[] lore, + String internalname, String itemid, String displayName, String[] lore, String crafttext, String infoType, String[] info, String clickcommand, int damage, NBTTagCompound nbttag ) { @@ -1118,7 +1118,7 @@ public class NEUManager { new JsonObject(), internalname, itemid, - displayname, + displayName, lore, crafttext, infoType, @@ -1130,7 +1130,7 @@ public class NEUManager { } public JsonObject createItemJson( - JsonObject base, String internalname, String itemid, String displayname, String[] lore, + JsonObject base, String internalname, String itemid, String displayName, String[] lore, String crafttext, String infoType, String[] info, String clickcommand, int damage, NBTTagCompound nbttag ) { @@ -1141,7 +1141,7 @@ public class NEUManager { JsonObject json = gson.fromJson(gson.toJson(base, JsonObject.class), JsonObject.class); json.addProperty("internalname", internalname); json.addProperty("itemid", itemid); - json.addProperty("displayname", displayname); + json.addProperty("displayname", displayName); json.addProperty("crafttext", crafttext); json.addProperty("clickcommand", clickcommand); json.addProperty("damage", damage); @@ -1167,14 +1167,14 @@ public class NEUManager { } public boolean writeItemJson( - String internalname, String itemid, String displayname, String[] lore, String crafttext, + String internalname, String itemid, String displayName, String[] lore, String crafttext, String infoType, String[] info, String clickcommand, int damage, NBTTagCompound nbttag ) { return writeItemJson( new JsonObject(), internalname, itemid, - displayname, + displayName, lore, crafttext, infoType, @@ -1186,14 +1186,14 @@ public class NEUManager { } public boolean writeItemJson( - JsonObject base, String internalname, String itemid, String displayname, String[] lore, + JsonObject base, String internalname, String itemid, String displayName, String[] lore, String crafttext, String infoType, String[] info, String clickcommand, int damage, NBTTagCompound nbttag ) { JsonObject json = createItemJson( base, internalname, itemid, - displayname, + displayName, lore, crafttext, infoType, @@ -1486,11 +1486,11 @@ public class NEUManager { if (useReplacements) { replacements = getLoreReplacements(stack.getTagCompound(), -1); - String displayname = json.get("displayname").getAsString(); + String displayName = json.get("displayname").getAsString(); for (Map.Entry entry : replacements.entrySet()) { - displayname = displayname.replace("{" + entry.getKey() + "}", entry.getValue()); + displayName = displayName.replace("{" + entry.getKey() + "}", entry.getValue()); } - stack.setStackDisplayName(displayname); + stack.setStackDisplayName(displayName); } if (json.has("lore")) { @@ -1519,7 +1519,7 @@ public class NEUManager { return NotEnoughUpdates.INSTANCE.manager .fetchRepository() .thenCompose(ignored -> NotEnoughUpdates.INSTANCE.manager.reloadRepository()) - .>thenApply(ignored -> { + .thenApply(ignored -> { String newCommitHash = NotEnoughUpdates.INSTANCE.manager.latestRepoCommit; String newCommitShortHash = (newCommitHash == null ? "MISSING" : newCommitHash.substring(0, 7)); return Arrays.asList( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java index ff0e5f13..3d18df36 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java @@ -103,8 +103,8 @@ public class NEUItemEditor extends GuiScreen { this.itemId = addTextFieldWithSupplier(itemid, NO_SPACE); options.add(new GuiElementText("Display name: ", Color.WHITE.getRGB())); - String displayname = item.has("displayname") ? item.get("displayname").getAsString() : ""; - this.displayName = addTextFieldWithSupplier(displayname, COLOUR); + String displayName = item.has("displayname") ? item.get("displayname").getAsString() : ""; + this.displayName = addTextFieldWithSupplier(displayName, COLOUR); options.add(new GuiElementText("Lore: ", Color.WHITE.getRGB())); JsonElement loreElement = getItemInfo("lore"); 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 72a385f1..31480016 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -1238,22 +1238,22 @@ public class RenderListener { try { JsonObject newNPC = new JsonObject(); - String displayname = lower.getDisplayName().getUnformattedText(); + String displayName = lower.getDisplayName().getUnformattedText(); File file = new File( Minecraft.getMinecraft().mcDataDir.getAbsolutePath(), "config" + File.separator + "notenoughupdates" + File.separator + "repo" + File.separator + "npc" + File.separator + - displayname.toUpperCase().replace(" ", "_") + ".json" + displayName.toUpperCase().replace(" ", "_") + ".json" ); newNPC.add("itemid", new JsonPrimitive("minecraft:skull")); - newNPC.add("displayname", new JsonPrimitive("§9" + displayname + " (NPC)")); + newNPC.add("displayname", new JsonPrimitive("§9" + displayName + " (NPC)")); newNPC.add("nbttag", new JsonPrimitive("TODO")); newNPC.add("damage", new JsonPrimitive(3)); JsonArray newArray = new JsonArray(); newArray.add(new JsonPrimitive("")); newNPC.add("lore", newArray); - newNPC.add("internalname", new JsonPrimitive(displayname.toUpperCase().replace(" ", "_") + "_NPC")); + newNPC.add("internalname", new JsonPrimitive(displayName.toUpperCase().replace(" ", "_") + "_NPC")); newNPC.add("clickcommand", new JsonPrimitive("viewrecipe")); newNPC.add("modver", new JsonPrimitive(NotEnoughUpdates.VERSION)); newNPC.add("infoType", new JsonPrimitive("WIKI_URL")); @@ -1345,7 +1345,7 @@ public class RenderListener { ) { writer.write(gson.toJson(newNPC)); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + displayname)); + EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + displayName)); } } catch (IOException ignored) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java index 51ec28dd..c323cd2e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java @@ -96,8 +96,8 @@ public class BazaarSacksProfit { String internalName = entry.getKey(); JsonObject object = entry.getValue(); if (object.has("displayname")) { - String displayname = object.get("displayname").getAsString(); - if (displayname.equals(bazaarName)) { + String name = object.get("displayname").getAsString(); + if (name.equals(bazaarName)) { prices.put(internalName, amount); names.put(internalName, bazaarName); continue out; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java index 3bc92a9c..06512fa8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -95,8 +95,8 @@ public abstract class MixinGuiContainer extends GuiScreen { NBTTagCompound tag = eventGui.inventorySlots.inventorySlots.get(22).getStack().getTagCompound(); if (tag.hasKey("SkullOwner") && tag.getCompoundTag("SkullOwner").hasKey("Name")) { String tagName = tag.getCompoundTag("SkullOwner").getString("Name"); - String displayname = Utils.cleanColour(cc.inventorySlots.get(22).getStack().getDisplayName()); - if (tagName.equals(displayname.substring(displayname.length() - tagName.length()))) { + String displayName = Utils.cleanColour(cc.inventorySlots.get(22).getStack().getDisplayName()); + if (tagName.equals(displayName.substring(displayName.length() - tagName.length()))) { ci.cancel(); this.zLevel = 100.0F; 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 4d546505..a99e4e7a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -841,15 +841,15 @@ public class Utils { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); } - public static ItemStack createItemStack(Item item, String displayname, String... lore) { - return createItemStack(item, displayname, 0, lore); + public static ItemStack createItemStack(Item item, String displayName, String... lore) { + return createItemStack(item, displayName, 0, lore); } - public static ItemStack createItemStack(Block item, String displayname, String... lore) { - return createItemStack(Item.getItemFromBlock(item), displayname, lore); + public static ItemStack createItemStack(Block item, String displayName, String... lore) { + return createItemStack(Item.getItemFromBlock(item), displayName, lore); } - public static ItemStack createItemStack(Item item, String displayname, int damage, String... lore) { + public static ItemStack createItemStack(Item item, String displayName, int damage, String... lore) { ItemStack stack = new ItemStack(item, 1, damage); NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound display = new NBTTagCompound(); @@ -859,7 +859,7 @@ public class Utils { Lore.appendTag(new NBTTagString(line)); } - display.setString("Name", displayname); + display.setString("Name", displayName); display.setTag("Lore", Lore); tag.setTag("display", display); @@ -1425,12 +1425,12 @@ public class Utils { file.delete(); } - public static char getPrimaryColourCode(String displayname) { + public static char getPrimaryColourCode(String displayName) { int lastColourCode = -99; int currentColour = 0; int[] mostCommon = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - for (int i = 0; i < displayname.length(); i++) { - char c = displayname.charAt(i); + for (int i = 0; i < displayName.length(); i++) { + char c = displayName.charAt(i); if (c == '\u00A7') { lastColourCode = i; } else if (lastColourCode == i - 1) { @@ -1457,8 +1457,8 @@ public class Utils { return "0123456789abcdef".charAt(currentColour); } - public static Color getPrimaryColour(String displayname) { - int colourInt = Minecraft.getMinecraft().fontRendererObj.getColorCode(getPrimaryColourCode(displayname)); + public static Color getPrimaryColour(String displayName) { + int colourInt = Minecraft.getMinecraft().fontRendererObj.getColorCode(getPrimaryColourCode(displayName)); return new Color(colourInt).darker(); } -- cgit From fde462b796ed7fbb22fdf7cf04c032389f3e8629 Mon Sep 17 00:00:00 2001 From: kr45732 <52721908+kr45732@users.noreply.github.com> Date: Thu, 11 Aug 2022 07:03:39 -0400 Subject: PV Refactoring (#212) --- .../commands/profile/PeekCommand.java | 48 +- .../miscfeatures/PetInfoOverlay.java | 5 +- .../notenoughupdates/profileviewer/BasicPage.java | 760 +++ .../notenoughupdates/profileviewer/BingoPage.java | 95 +- .../profileviewer/CollectionPage.java | 338 -- .../profileviewer/CollectionsPage.java | 493 ++ .../profileviewer/DungeonPage.java | 816 ++++ .../notenoughupdates/profileviewer/ExtraPage.java | 505 ++ .../profileviewer/GuiProfileViewer.java | 4894 ++------------------ .../profileviewer/GuiProfileViewerPage.java | 53 + .../profileviewer/InventoriesPage.java | 778 ++++ .../notenoughupdates/profileviewer/MiningPage.java | 1424 ++++++ .../notenoughupdates/profileviewer/Panorama.java | 43 +- .../notenoughupdates/profileviewer/PetsPage.java | 575 +++ .../profileviewer/PlayerStats.java | 351 +- .../profileviewer/ProfileViewer.java | 1081 ++--- .../profileviewer/bestiary/BestiaryData.java | 326 +- .../profileviewer/bestiary/BestiaryPage.java | 190 +- .../profileviewer/trophy/TrophyFish.java | 21 +- .../profileviewer/trophy/TrophyFishPage.java | 478 ++ .../profileviewer/trophy/TrophyFishingPage.java | 491 -- .../weight/lily/LilyDungeonsWeight.java | 21 +- .../weight/lily/LilySkillsWeight.java | 28 +- .../weight/lily/LilySlayerWeight.java | 7 +- .../profileviewer/weight/lily/LilyWeight.java | 4 +- .../weight/senither/SenitherDungeonsWeight.java | 36 +- .../weight/senither/SenitherSkillsWeight.java | 8 +- .../weight/senither/SenitherSlayerWeight.java | 7 +- .../weight/senither/SenitherWeight.java | 5 +- .../weight/weight/DungeonsWeight.java | 7 +- .../profileviewer/weight/weight/SkillsWeight.java | 9 +- .../profileviewer/weight/weight/SlayerWeight.java | 7 +- .../profileviewer/weight/weight/Weight.java | 9 +- .../notenoughupdates/util/XPInformation.java | 10 +- 34 files changed, 7511 insertions(+), 6412 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionPage.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/DungeonPage.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewerPage.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishingPage.java (limited to 'src/main/java') 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 21afff87..421f7c10 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 @@ -19,11 +19,11 @@ package io.github.moulberry.notenoughupdates.commands.profile; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; +import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandException; @@ -35,16 +35,19 @@ import net.minecraft.util.EnumChatFormatting; import org.apache.commons.lang3.text.WordUtils; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Random; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; public class PeekCommand extends ClientCommandBase { private ScheduledExecutorService peekCommandExecutorService = null; + private ScheduledFuture peekScheduledFuture = null; public PeekCommand() { super("peek"); @@ -69,23 +72,23 @@ public class PeekCommand extends ClientCommandBase { } else { profile.resetCache(); - if (peekCommandExecutorService == null || peekCommandExecutorService.isShutdown()) { + if (peekCommandExecutorService == null) { peekCommandExecutorService = Executors.newSingleThreadScheduledExecutor(); - } else { + } + + if (peekScheduledFuture != null && !peekScheduledFuture.isDone()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( EnumChatFormatting.RED + "[PEEK] New peek command run, cancelling old one.")); - peekCommandExecutorService.shutdownNow(); - peekCommandExecutorService = Executors.newSingleThreadScheduledExecutor(); + peekScheduledFuture.cancel(true); } Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( EnumChatFormatting.YELLOW + "[PEEK] Getting the player's Skyblock profile(s)..."), id); long startTime = System.currentTimeMillis(); - peekCommandExecutorService.schedule(new Runnable() { + peekScheduledFuture = peekCommandExecutorService.schedule(new Runnable() { public void run() { if (System.currentTimeMillis() - startTime > 10 * 1000) { - Minecraft.getMinecraft().ingameGUI .getChatGUI() .printChatMessageWithOptionalDeletion(new ChatComponentText( @@ -103,7 +106,7 @@ public class PeekCommand extends ClientCommandBase { PlayerStats.Stats stats = profile.getStats(null); if (stats == null) return; - JsonObject skill = profile.getSkillInfo(null); + Map skyblockInfo = profile.getSkyblockInfo(null); Minecraft.getMinecraft().ingameGUI .getChatGUI() @@ -112,27 +115,24 @@ public class PeekCommand extends ClientCommandBase { Utils.getElementAsString(profile.getHypixelProfile().get("displayname"), name) + "'s Info " + EnumChatFormatting.STRIKETHROUGH + "-=-"), id); - if (skill == null) { + if (skyblockInfo == null) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + "Skills api disabled!")); + EnumChatFormatting.YELLOW + "Skills API disabled!")); } else { float totalSkillLVL = 0; float totalSkillCount = 0; - for (Map.Entry entry : skill.entrySet()) { - if (entry.getKey().startsWith("level_skill")) { - if (entry.getKey().contains("runecrafting")) continue; - if (entry.getKey().contains("carpentry")) continue; - totalSkillLVL += entry.getValue().getAsFloat(); - totalSkillCount++; - } + List skills = Arrays.asList("taming", "mining", "foraging", "enchanting", "farming", "combat", "fishing", "alchemy"); + for (String skillName : skills) { + totalSkillLVL += skyblockInfo.get(skillName).level; + totalSkillCount++; } - float combat = Utils.getElementAsFloat(skill.get("level_skill_combat"), 0); - float zombie = Utils.getElementAsFloat(skill.get("level_slayer_zombie"), 0); - float spider = Utils.getElementAsFloat(skill.get("level_slayer_spider"), 0); - float wolf = Utils.getElementAsFloat(skill.get("level_slayer_wolf"), 0); - float enderman = Utils.getElementAsFloat(skill.get("level_slayer_enderman"), 0); + float combat = skyblockInfo.get("combat").level; + float zombie = skyblockInfo.get("zombie").level; + float spider = skyblockInfo.get("spider").level; + float wolf = skyblockInfo.get("wolf").level; + float enderman = skyblockInfo.get("enderman").level; float avgSkillLVL = totalSkillLVL / totalSkillCount; @@ -173,7 +173,7 @@ public class PeekCommand extends ClientCommandBase { overallScore += enderman * enderman / 81f; overallScore += avgSkillLVL / 20f; - int cata = (int) Utils.getElementAsFloat(skill.get("level_skill_catacombs"), 0); + int cata = (int) skyblockInfo.get("catacombs").level; EnumChatFormatting cataPrefix = cata > 15 ? (cata > 25 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) : EnumChatFormatting.RED; @@ -286,7 +286,7 @@ public class PeekCommand extends ClientCommandBase { peekCommandExecutorService.shutdownNow(); } else { - peekCommandExecutorService.schedule(this, 200, TimeUnit.MILLISECONDS); + peekScheduledFuture = peekCommandExecutorService.schedule(this, 200, TimeUnit.MILLISECONDS); } } }, 200, TimeUnit.MILLISECONDS); 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 fa20b48a..4a1dfc26 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -301,7 +301,7 @@ public class PetInfoOverlay extends TextOverlay { } private static void getAndSetPet(ProfileViewer.Profile profile) { - JsonObject skillInfo = profile.getSkillInfo(profile.getLatestProfile()); + Map skyblockInfo = profile.getSkyblockInfo(profile.getLatestProfile()); JsonObject invInfo = profile.getInventoryInfo(profile.getLatestProfile()); JsonObject profileInfo = profile.getProfileInformation(profile.getLatestProfile()); if (invInfo != null && profileInfo != null) { @@ -340,7 +340,8 @@ public class PetInfoOverlay extends TextOverlay { } } } - if (skillInfo != null) config.tamingLevel = skillInfo.get("level_skill_taming").getAsInt(); + if (skyblockInfo != null) config.tamingLevel = (int) skyblockInfo.get("taming").level; + //JsonObject petObject = profile.getPetsInfo(profile.getLatestProfile()); /*JsonObject petsJson = Constants.PETS; if(petsJson != null) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java new file mode 100644 index 00000000..30ffcdd9 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java @@ -0,0 +1,760 @@ +/* + * 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 . + */ + +package io.github.moulberry.notenoughupdates.profileviewer; + +import static io.github.moulberry.notenoughupdates.util.Utils.roundToNearestInt; + +import com.google.common.base.Splitter; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mojang.authlib.GameProfile; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.profileviewer.weight.lily.LilyWeight; +import io.github.moulberry.notenoughupdates.profileviewer.weight.senither.SenitherWeight; +import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.Utils; +import java.awt.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityOtherPlayerMP; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.resources.DefaultPlayerSkin; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EnumPlayerModelParts; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +public class BasicPage extends GuiProfileViewerPage { + + private static final ResourceLocation pv_basic = new ResourceLocation("notenoughupdates:pv_basic.png"); + private static final ExecutorService profileLoader = Executors.newFixedThreadPool(1); + public EntityOtherPlayerMP entityPlayer = null; + private ResourceLocation playerLocationSkin = null; + private ResourceLocation playerLocationCape = null; + private String skinType = null; + private boolean loadingProfile = false; + + private int backgroundClickedX = -1; + + public BasicPage(GuiProfileViewer instance) { + super(instance); + } + + @Override + public void drawPage(int mouseX, int mouseY, float partialTicks) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + ProfileViewer.Profile profile = GuiProfileViewer.getProfile(); + String profileId = GuiProfileViewer.getProfileId(); + int guiLeft = GuiProfileViewer.getGuiLeft(); + int guiTop = GuiProfileViewer.getGuiTop(); + + String location = null; + JsonObject status = profile.getPlayerStatus(); + if (status != null && status.has("mode")) { + location = status.get("mode").getAsString(); + } + + int extraRotation = 0; + if (Mouse.isButtonDown(0) || Mouse.isButtonDown(1)) { + if (backgroundClickedX == -1) { + if (mouseX > guiLeft + 23 && mouseX < guiLeft + 23 + 81) { + if (mouseY > guiTop + 44 && mouseY < guiTop + 44 + 108) { + backgroundClickedX = mouseX; + } + } + } + } else { + if (backgroundClickedX != -1) { + getInstance().backgroundRotation += mouseX - backgroundClickedX; + backgroundClickedX = -1; + } + } + if (backgroundClickedX == -1) { + getInstance().backgroundRotation += (getInstance().currentTime - getInstance().lastTime) / 400f; + } else { + extraRotation = mouseX - backgroundClickedX; + } + getInstance().backgroundRotation %= 360; + + String panoramaIdentifier = "day"; + if (SBInfo.getInstance().currentTimeDate != null) { + if (SBInfo.getInstance().currentTimeDate.getHours() <= 6 || SBInfo.getInstance().currentTimeDate.getHours() >= 20) { + panoramaIdentifier = "night"; + } + } + + Panorama.drawPanorama( + -getInstance().backgroundRotation - extraRotation, + guiLeft + 23, + guiTop + 44, + 81, + 108, + 0.37f, + 0.8f, + Panorama.getPanoramasForLocation(location == null ? "unknown" : location, panoramaIdentifier) + ); + + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_basic); + Utils.drawTexturedRect(guiLeft, guiTop, getInstance().sizeX, getInstance().sizeY, GL11.GL_NEAREST); + + if (entityPlayer != null && profile.getHypixelProfile() != null) { + String playerName = null; + if (profile.getHypixelProfile().has("prefix")) { + playerName = Utils.getElementAsString(profile.getHypixelProfile().get("prefix"), "") + " " + entityPlayer.getName(); + } else { + String rank = Utils.getElementAsString( + profile.getHypixelProfile().get("rank"), + Utils.getElementAsString(profile.getHypixelProfile().get("newPackageRank"), "NONE") + ); + String monthlyPackageRank = Utils.getElementAsString(profile.getHypixelProfile().get("monthlyPackageRank"), "NONE"); + if (!rank.equals("YOUTUBER") && !monthlyPackageRank.equals("NONE")) { + rank = monthlyPackageRank; + } + EnumChatFormatting rankPlusColorECF = EnumChatFormatting.getValueByName( + Utils.getElementAsString(profile.getHypixelProfile().get("rankPlusColor"), "GOLD") + ); + String rankPlusColor = EnumChatFormatting.GOLD.toString(); + if (rankPlusColorECF != null) { + rankPlusColor = rankPlusColorECF.toString(); + } + + JsonObject misc = Constants.MISC; + if (misc != null) { + if (misc.has("ranks")) { + String rankName = Utils.getElementAsString(Utils.getElement(misc, "ranks." + rank + ".tag"), null); + String rankColor = Utils.getElementAsString(Utils.getElement(misc, "ranks." + rank + ".color"), "7"); + String rankPlus = Utils.getElementAsString(Utils.getElement(misc, "ranks." + rank + ".plus"), ""); + + String name = entityPlayer.getName(); + + if (misc.has("special_bois")) { + JsonArray special_bois = misc.get("special_bois").getAsJsonArray(); + for (int i = 0; i < special_bois.size(); i++) { + if (special_bois.get(i).getAsString().equals(profile.getUuid())) { + name = Utils.chromaString(name); + break; + } + } + } + + playerName = EnumChatFormatting.GRAY + name; + if (rankName != null) { + playerName = + "\u00A7" + rankColor + "[" + rankName + rankPlusColor + rankPlus + "\u00A7" + rankColor + "] " + name; + } + } + } + } + if (playerName != null) { + int rankPrefixLen = fr.getStringWidth(playerName); + int halfRankPrefixLen = rankPrefixLen / 2; + + int x = guiLeft + 63; + int y = guiTop + 54; + + GuiScreen.drawRect(x - halfRankPrefixLen - 1, y - 1, x + halfRankPrefixLen + 1, y + 8, new Color(0, 0, 0, 64).getRGB()); + + fr.drawString(playerName, x - halfRankPrefixLen, y, 0, true); + } + } + + long networth = profile.getNetWorth(profileId); + if (networth > 0) { + Utils.drawStringCentered( + EnumChatFormatting.GREEN + "Net Worth: " + EnumChatFormatting.GOLD + GuiProfileViewer.numberFormat.format(networth), + fr, + guiLeft + 63, + guiTop + 38, + true, + 0 + ); + try { + double networthInCookies = + ( + networth / + NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo("BOOSTER_COOKIE").get("avg_buy").getAsDouble() + ); + String networthIRLMoney = Long.toString(Math.round(((networthInCookies * 325) / 675) * 4.99)); + if ( + mouseX > guiLeft + 8 && + mouseX < guiLeft + 8 + fr.getStringWidth("Net Worth: " + GuiProfileViewer.numberFormat.format(networth)) + ) { + if (mouseY > guiTop + 32 && mouseY < guiTop + 32 + fr.FONT_HEIGHT) { + getInstance().tooltipToDisplay = new ArrayList<>(); + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GREEN + + "Net worth in IRL money: " + + EnumChatFormatting.DARK_GREEN + + "$" + + EnumChatFormatting.GOLD + + networthIRLMoney + ); + getInstance().tooltipToDisplay.add(""); + if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "This is calculated using the current"); + getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "price of booster cookies on bazaar and the price"); + getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "for cookies using gems, then the price of gems"); + getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "is where we get the amount of IRL money you"); + getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "theoretically have on skyblock in net worth."); + } else { + getInstance().tooltipToDisplay.add(EnumChatFormatting.GRAY + "[SHIFT for Info]"); + } + if (!NotEnoughUpdates.INSTANCE.config.hidden.dev) { + getInstance().tooltipToDisplay.add(""); + getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "THIS IS IN NO WAY ENDORSING IRL TRADING!"); + } + } + } + } catch (Exception ignored) {} + } + + if (status != null) { + JsonElement onlineElement = Utils.getElement(status, "online"); + boolean online = onlineElement != null && onlineElement.isJsonPrimitive() && onlineElement.getAsBoolean(); + String statusStr = online ? EnumChatFormatting.GREEN + "ONLINE" : EnumChatFormatting.RED + "OFFLINE"; + String locationStr = null; + if (profile.getUuid().equals("20934ef9488c465180a78f861586b4cf")) { + locationStr = "Ignoring DMs"; + } else if (profile.getUuid().equals("b876ec32e396476ba1158438d83c67d4")) { + statusStr = EnumChatFormatting.LIGHT_PURPLE + "Long live Potato King"; + ItemStack potato_crown = NotEnoughUpdates.INSTANCE.manager.jsonToStack( + NotEnoughUpdates.INSTANCE.manager.getItemInformation().get("POTATO_CROWN") + ); + potato_crown.addEnchantment(Enchantment.unbreaking, 1656638942); // this number may be useful + Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(new ItemStack(Items.potato), guiLeft + 35, guiTop + 160); + Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(potato_crown, guiLeft + 50, guiTop + 162); + Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(new ItemStack(Items.potato), guiLeft + 63, guiTop + 160); + } else if (online) { + locationStr = NotEnoughUpdates.INSTANCE.navigation.getNameForAreaModeOrUnknown(location); + } + if (locationStr != null) { + statusStr += EnumChatFormatting.GRAY + " - " + EnumChatFormatting.GREEN + locationStr; + } + + Utils.drawStringCentered(statusStr, fr, guiLeft + 63, guiTop + 160, true, 0); + } + + if (entityPlayer == null) { + if (!loadingProfile || ((ThreadPoolExecutor) profileLoader).getActiveCount() == 0) { + loadingProfile = true; + UUID playerUUID = UUID.fromString(niceUuid(profile.getUuid())); + + profileLoader.submit(() -> { + GameProfile fakeProfile = Minecraft + .getMinecraft() + .getSessionService() + .fillProfileProperties(new GameProfile(playerUUID, "CoolGuy123"), false); + entityPlayer = + new EntityOtherPlayerMP(Minecraft.getMinecraft().theWorld, fakeProfile) { + public ResourceLocation getLocationSkin() { + return playerLocationSkin == null + ? DefaultPlayerSkin.getDefaultSkin(this.getUniqueID()) + : playerLocationSkin; + } + + public ResourceLocation getLocationCape() { + return playerLocationCape; + } + + public String getSkinType() { + return skinType == null ? DefaultPlayerSkin.getSkinType(this.getUniqueID()) : skinType; + } + }; + entityPlayer.setAlwaysRenderNameTag(false); + entityPlayer.setCustomNameTag(""); + }); + } + } else { + entityPlayer.refreshDisplayName(); + byte b = 0; + for (EnumPlayerModelParts part : EnumPlayerModelParts.values()) { + b |= part.getPartMask(); + } + entityPlayer.getDataWatcher().updateObject(10, b); + } + + JsonObject profileInfo = profile.getProfileInformation(profileId); + if (profileInfo == null) return; + + Map skyblockInfo = profile.getSkyblockInfo(profileId); + JsonObject inventoryInfo = profile.getInventoryInfo(profileId); + + if (entityPlayer != null) { + if (backgroundClickedX != -1 && Mouse.isButtonDown(1)) { + Arrays.fill(entityPlayer.inventory.armorInventory, null); + } else { + if (inventoryInfo != null && inventoryInfo.has("inv_armor")) { + JsonArray items = inventoryInfo.get("inv_armor").getAsJsonArray(); + if (items != null && items.size() == 4) { + for (int i = 0; i < entityPlayer.inventory.armorInventory.length; i++) { + JsonElement itemElement = items.get(i); + if (itemElement != null && itemElement.isJsonObject()) { + entityPlayer.inventory.armorInventory[i] = + NotEnoughUpdates.INSTANCE.manager.jsonToStack(itemElement.getAsJsonObject(), false); + } + } + } + } else { + Arrays.fill(entityPlayer.inventory.armorInventory, null); + } + } + if (entityPlayer.getUniqueID().toString().equals("ae6193ab-494a-4719-b6e7-d50392c8f012")) { + entityPlayer.inventory.armorInventory[3] = + NotEnoughUpdates.INSTANCE.manager.jsonToStack( + NotEnoughUpdates.INSTANCE.manager.getItemInformation().get("SMALL_BACKPACK") + ); + } + } + + if (entityPlayer != null && playerLocationSkin == null) { + try { + Minecraft + .getMinecraft() + .getSkinManager() + .loadProfileTextures( + entityPlayer.getGameProfile(), + (type, location1, profileTexture) -> { + switch (type) { + case SKIN: + playerLocationSkin = location1; + skinType = profileTexture.getMetadata("model"); + + if (skinType == null) { + skinType = "default"; + } + + break; + case CAPE: + playerLocationCape = location1; + } + }, + false + ); + } catch (Exception ignored) {} + } + + GlStateManager.color(1, 1, 1, 1); + JsonObject petsInfo = profile.getPetsInfo(profileId); + if (petsInfo != null) { + JsonElement activePetElement = petsInfo.get("active_pet"); + if (activePetElement != null && activePetElement.isJsonObject()) { + JsonObject activePet = activePetElement.getAsJsonObject(); + + String type = activePet.get("type").getAsString(); + + for (int i = 0; i < 4; i++) { + JsonObject item = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(type + ";" + i); + if (item != null) { + int x = guiLeft + 20; + float y = + guiTop + + 82 + + 15 * + (float) Math.sin(((getInstance().currentTime - getInstance().startTime) / 800f) % (2 * Math.PI)); + GlStateManager.translate(x, y, 0); + ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(item, false); + + //Remove extra attributes so no CIT + NBTTagCompound stackTag = stack.getTagCompound() == null ? new NBTTagCompound() : stack.getTagCompound(); + stackTag.removeTag("ExtraAttributes"); + stack.setTagCompound(stackTag); + + GlStateManager.scale(1.5f, 1.5f, 1); + GlStateManager.enableDepth(); + Utils.drawItemStack(stack, 0, 0); + GlStateManager.scale(1 / 1.5f, 1 / 1.5f, 1); + GlStateManager.translate(-x, -y, 0); + break; + } + } + } + } + if (entityPlayer != null) { + drawEntityOnScreen(guiLeft + 63, guiTop + 128 + 7, 36, guiLeft + 63 - mouseX, guiTop + 129 - mouseY, entityPlayer); + } + + PlayerStats.Stats stats = profile.getStats(profileId); + + if (stats != null) { + Splitter splitter = Splitter.on(" ").omitEmptyStrings().limit(2); + for (int i = 0; i < PlayerStats.defaultStatNames.length; i++) { + String statName = PlayerStats.defaultStatNames[i]; + //if (statName.equals("mining_fortune") || statName.equals("mining_speed")) continue; + String statNamePretty = PlayerStats.defaultStatNamesPretty[i]; + + int val = Math.round(stats.get(statName)); + + GlStateManager.color(1, 1, 1, 1); + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + Utils.renderAlignedString( + statNamePretty, + EnumChatFormatting.WHITE.toString() + val, + guiLeft + 132, + guiTop + 21 + 11f * i, + 80 + ); + + if (mouseX > guiLeft + 132 && mouseX < guiLeft + 212) { + if (mouseY > guiTop + 21 + 11f * i && mouseY < guiTop + 37 + 11f * i) { + List split = splitter.splitToList(statNamePretty); + PlayerStats.Stats baseStats = PlayerStats.getBaseStats(); + getInstance().tooltipToDisplay = new ArrayList<>(); + getInstance().tooltipToDisplay.add(statNamePretty); + int base = Math.round(baseStats.get(statName)); + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GRAY + + "Base " + + split.get(1) + + ": " + + EnumChatFormatting.GREEN + + base + + " " + + split.get(0) + ); + int passive = Math.round(profile.getPassiveStats(profileId).get(statName) - baseStats.get(statName)); + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GRAY + + "Passive " + + split.get(1) + + " Bonus: +" + + EnumChatFormatting.YELLOW + + passive + + " " + + split.get(0) + ); + int itemBonus = Math.round(stats.get(statName) - profile.getPassiveStats(profileId).get(statName)); + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GRAY + + "Item " + + split.get(1) + + " Bonus: +" + + EnumChatFormatting.DARK_PURPLE + + itemBonus + + " " + + split.get(0) + ); + int finalStat = Math.round(stats.get(statName)); + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GRAY + + "Final " + + split.get(1) + + ": +" + + EnumChatFormatting.RED + + finalStat + + " " + + split.get(0) + ); + } + } + } + } else { + Utils.drawStringCentered( + EnumChatFormatting.RED + "Skill/Inv/Coll", + Minecraft.getMinecraft().fontRendererObj, + guiLeft + 172, + guiTop + 101 - 10, + true, + 0 + ); + Utils.drawStringCentered( + EnumChatFormatting.RED + "APIs not", + Minecraft.getMinecraft().fontRendererObj, + guiLeft + 172, + guiTop + 101, + true, + 0 + ); + Utils.drawStringCentered( + EnumChatFormatting.RED + "enabled!", + Minecraft.getMinecraft().fontRendererObj, + guiLeft + 172, + guiTop + 101 + 10, + true, + 0 + ); + } + + if (skyblockInfo != null) { + int position = 0; + for (Map.Entry entry : ProfileViewer.getSkillToSkillDisplayMap().entrySet()) { + if (entry.getValue() == null || entry.getKey() == null) { + position++; + continue; + } + + int yPosition = position % 8; + int xPosition = position / 8; + + String skillName = entry.getValue().getDisplayName(); + + float level = skyblockInfo.get(entry.getKey()).level; + int levelFloored = (int) Math.floor(level); + + int x = guiLeft + 237 + 86 * xPosition; + int y = guiTop + 24 + 21 * yPosition; + + Utils.renderAlignedString(skillName, EnumChatFormatting.WHITE.toString() + levelFloored, x + 14, y - 4, 60); + + if (skyblockInfo.get(entry.getKey()).maxed) { + getInstance().renderGoldBar(x, y + 6, 80); + } else { + getInstance().renderBar(x, y + 6, 80, level % 1); + } + + if (mouseX > x && mouseX < x + 80) { + if (mouseY > y - 4 && mouseY < y + 13) { + getInstance().tooltipToDisplay = new ArrayList<>(); + getInstance().tooltipToDisplay.add(skillName); + if (skyblockInfo.get(entry.getKey()).maxed) { + getInstance().tooltipToDisplay.add(EnumChatFormatting.GRAY + "Progress: " + EnumChatFormatting.GOLD + "MAXED!"); + } else { + int maxXp = (int) skyblockInfo.get(entry.getKey()).maxXpForLevel; + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GRAY + + "Progress: " + + EnumChatFormatting.DARK_PURPLE + + GuiProfileViewer.shortNumberFormat(Math.round((level % 1) * maxXp), 0) + + "/" + + GuiProfileViewer.shortNumberFormat(maxXp, 0) + ); + } + String totalXpS = GuiProfileViewer.numberFormat.format((int) skyblockInfo.get(entry.getKey()).totalXp); + getInstance() + .tooltipToDisplay.add(EnumChatFormatting.GRAY + "Total XP: " + EnumChatFormatting.DARK_PURPLE + totalXpS); + } + } + + GL11.glTranslatef((x), (y - 6f), 0); + GL11.glScalef(0.7f, 0.7f, 1); + Utils.drawItemStackLinear(entry.getValue(), 0, 0); + GL11.glScalef(1 / 0.7f, 1 / 0.7f, 1); + GL11.glTranslatef(-(x), -(y - 6f), 0); + + position++; + } + } else { + Utils.drawStringCentered( + EnumChatFormatting.RED + "Skills API not enabled!", + Minecraft.getMinecraft().fontRendererObj, + guiLeft + 322, + guiTop + 101, + true, + 0 + ); + } + + renderWeight(mouseX, mouseY, skyblockInfo, profileInfo); + } + + @Override + public void resetCache() { + entityPlayer = null; + playerLocationSkin = null; + playerLocationCape = null; + skinType = null; + } + + private String niceUuid(String uuidStr) { + if (uuidStr.length() != 32) return uuidStr; + + return ( + uuidStr.substring(0, 8) + + "-" + + uuidStr.substring(8, 12) + + "-" + + uuidStr.substring(12, 16) + + "-" + + uuidStr.substring(16, 20) + + "-" + + uuidStr.substring(20, 32) + ); + } + + private void renderWeight(int mouseX, int mouseY, Map skyblockInfo, JsonObject profileInfo) { + if (skyblockInfo == null) { + return; + } + + if (Constants.WEIGHT == null || Utils.getElement(Constants.WEIGHT, "lily.skills.overall") == null || !Utils.getElement(Constants.WEIGHT, "lily.skills.overall").isJsonPrimitive()) { + Utils.showOutdatedRepoNotification(); + return; + } + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int guiLeft = GuiProfileViewer.getGuiLeft(); + int guiTop = GuiProfileViewer.getGuiTop(); + + SenitherWeight senitherWeight = new SenitherWeight(skyblockInfo); + LilyWeight lilyWeight = new LilyWeight(skyblockInfo, profileInfo); + + Utils.drawStringCentered( + EnumChatFormatting.GREEN + + "Senither Weight: " + + EnumChatFormatting.GOLD + + GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getTotalWeight().getRaw())), + fr, + guiLeft + 63, + guiTop + 18, + true, + 0 + ); + + int textWidth = fr.getStringWidth( + "Senither Weight: " + GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getTotalWeight().getRaw())) + ); + if (mouseX > guiLeft + 63 - textWidth / 2 && mouseX < guiLeft + 63 + textWidth / 2) { + if (mouseY > guiTop + 12 && mouseY < guiTop + 12 + fr.FONT_HEIGHT) { + getInstance().tooltipToDisplay = new ArrayList<>(); + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GREEN + + "Skills: " + + EnumChatFormatting.GOLD + + GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getSkillsWeight().getWeightStruct().getRaw())) + ); + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GREEN + + "Slayer: " + + EnumChatFormatting.GOLD + + GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getSlayerWeight().getWeightStruct().getRaw())) + ); + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GREEN + + "Dungeons: " + + EnumChatFormatting.GOLD + + GuiProfileViewer.numberFormat.format( + roundToNearestInt(senitherWeight.getDungeonsWeight().getWeightStruct().getRaw()) + ) + ); + } + } + + Utils.drawStringCentered( + EnumChatFormatting.GREEN + + "Lily Weight: " + + EnumChatFormatting.GOLD + + GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getTotalWeight().getRaw())), + fr, + guiLeft + 63, + guiTop + 28, + true, + 0 + ); + + int fontWidth = fr.getStringWidth( + "Lily Weight: " + GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getTotalWeight().getRaw())) + ); + if (mouseX > guiLeft + 63 - fontWidth / 2 && mouseX < guiLeft + 63 + fontWidth / 2) { + if (mouseY > guiTop + 22 && mouseY < guiTop + 22 + fr.FONT_HEIGHT) { + getInstance().tooltipToDisplay = new ArrayList<>(); + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GREEN + + "Skills: " + + EnumChatFormatting.GOLD + + GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getSkillsWeight().getWeightStruct().getRaw())) + ); + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GREEN + + "Slayer: " + + EnumChatFormatting.GOLD + + GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getSlayerWeight().getWeightStruct().getRaw())) + ); + getInstance() + .tooltipToDisplay.add( + EnumChatFormatting.GREEN + + "Dungeons: " + + EnumChatFormatting.GOLD + + GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getDungeonsWeight().getWeightStruct().getRaw())) + ); + } + } + } + + private void drawEntityOnScreen(int posX, int posY, int scale, float mouseX, float mouseY, EntityLivingBase ent) { + GlStateManager.enableColorMaterial(); + GlStateManager.pushMatrix(); + GlStateManager.translate((float) posX, (float) posY, 50.0F); + GlStateManager.scale((float) (-scale), (float) scale, (float) scale); + GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); + float renderYawOffset = ent.renderYawOffset; + float f1 = ent.rotationYaw; + float f2 = ent.rotationPitch; + float f3 = ent.prevRotationYawHead; + float f4 = ent.rotationYawHead; + GlStateManager.rotate(135.0F, 0.0F, 1.0F, 0.0F); + RenderHelper.enableStandardItemLighting(); + GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(25, 1.0F, 0.0F, 0.0F); + ent.renderYawOffset = (float) Math.atan(mouseX / 40.0F) * 20.0F; + ent.rotationYaw = (float) Math.atan(mouseX / 40.0F) * 40.0F; + ent.rotationPitch = -((float) Math.atan(mouseY / 40.0F)) * 20.0F; + ent.rotationYawHead = ent.rotationYaw; + ent.prevRotationYawHead = ent.rotationYaw; + RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager(); + rendermanager.setPlayerViewY(180.0F); + rendermanager.setRenderShadow(false); + rendermanager.renderEntityWithPosYaw(ent, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); + + ent.renderYawOffset = renderYawOffset; + ent.rotationYaw = f1; + ent.rotationPitch = f2; + ent.prevRotationYawHead = f3; + ent.rotationYawHead = f4; + GlStateManager.popMatrix(); + RenderHelper.disableStandardItemLighting(); + GlStateManager.disableRescaleNormal(); + GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); + GlStateManager.disableTexture2D(); + GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java index dfcbb007..27b9b363 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java @@ -24,6 +24,9 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.util.Utils; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -36,17 +39,19 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +public class BingoPage extends GuiProfileViewerPage { -public class BingoPage { private static final ResourceLocation BINGO_GUI_TEXTURE = new ResourceLocation("notenoughupdates:pv_bingo_tab.png"); - private static long lastResourceRequest; - private static List bingoGoals = null; - private static int currentEventId; + private long lastResourceRequest; + private List bingoGoals = null; + private int currentEventId; + + public BingoPage(GuiProfileViewer instance) { + super(instance); + } - public static void renderPage(int mouseX, int mouseY) { + @Override + public void drawPage(int mouseX, int mouseY, float partialTicks) { processBingoResources(); JsonObject bingoInfo = GuiProfileViewer.getProfile().getBingoInformation(); @@ -147,20 +152,22 @@ public class BingoPage { personalGoalsString = EnumChatFormatting.AQUA + "Personal Goals: " + EnumChatFormatting.GOLD + "20/20"; } else { personalGoalsString = - EnumChatFormatting.AQUA + "Personal Goals: " + EnumChatFormatting.WHITE + completedGoals.size() + - EnumChatFormatting.GOLD + "/" + EnumChatFormatting.WHITE + 20; + EnumChatFormatting.AQUA + + "Personal Goals: " + + EnumChatFormatting.WHITE + + completedGoals.size() + + EnumChatFormatting.GOLD + + "/" + + EnumChatFormatting.WHITE + + 20; } - Utils.drawStringF(totalPointsString, Minecraft.getMinecraft().fontRendererObj, - guiLeft + 22, guiTop + 19, true, 0 - ); - Utils.drawStringF(personalGoalsString, Minecraft.getMinecraft().fontRendererObj, - guiLeft + 22, guiTop + 31, true, 0 - ); + Utils.drawStringF(totalPointsString, Minecraft.getMinecraft().fontRendererObj, guiLeft + 22, guiTop + 19, true, 0); + Utils.drawStringF(personalGoalsString, Minecraft.getMinecraft().fontRendererObj, guiLeft + 22, guiTop + 31, true, 0); GlStateManager.enableLighting(); } - private static boolean isCommunityGoalFinished(JsonObject goal) { + private boolean isCommunityGoalFinished(JsonObject goal) { JsonArray tiers = goal.get("tiers").getAsJsonArray(); int totalTiers = tiers.size(); long progress = goal.get("progress").getAsLong(); @@ -175,7 +182,7 @@ public class BingoPage { return finalTier == totalTiers; } - private static String generateProgressIndicator(double progress, double goal) { + private String generateProgressIndicator(double progress, double goal) { int totalFields = 20; int filled; double percentage = progress / goal * 100; @@ -196,7 +203,7 @@ public class BingoPage { return stringBuilder.toString(); } - private static List getTooltip(JsonObject goal, boolean completed, boolean communityGoal) { + private List getTooltip(JsonObject goal, boolean completed, boolean communityGoal) { List tooltip = new ArrayList<>(); if (communityGoal) { //get current tier @@ -211,9 +218,7 @@ public class BingoPage { } finalTier++; } - double nextTier = finalTier < totalTiers ? tiers.get(totalTiers - 1).getAsLong() : tiers - .get(finalTier - 1) - .getAsLong(); + double nextTier = finalTier < totalTiers ? tiers.get(totalTiers - 1).getAsLong() : tiers.get(finalTier - 1).getAsLong(); int progressToNextTier = (int) Math.round(progress / nextTier * 100); if (progressToNextTier > 100) progressToNextTier = 100; String progressBar = generateProgressIndicator(progress, nextTier); @@ -226,21 +231,35 @@ public class BingoPage { tooltip.add(EnumChatFormatting.DARK_GRAY + "Community Goal"); tooltip.add(""); tooltip.add( - EnumChatFormatting.GRAY + "Progress to " + name + " " + nextTierNum + ": " + EnumChatFormatting.YELLOW + - progressToNextTier + EnumChatFormatting.GOLD + "%"); - tooltip.add(progressBar + EnumChatFormatting.YELLOW + " " + progressString + EnumChatFormatting.GOLD + "/" + - EnumChatFormatting.YELLOW + nextTierString); + EnumChatFormatting.GRAY + + "Progress to " + + name + + " " + + nextTierNum + + ": " + + EnumChatFormatting.YELLOW + + progressToNextTier + + EnumChatFormatting.GOLD + + "%" + ); + tooltip.add( + progressBar + + EnumChatFormatting.YELLOW + + " " + + progressString + + EnumChatFormatting.GOLD + + "/" + + EnumChatFormatting.YELLOW + + nextTierString + ); tooltip.add(""); tooltip.add(EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + "Community Goals are"); - tooltip.add( - EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + "collaborative - anyone with a"); - tooltip.add( - EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + "Bingo profile can help to reach"); + tooltip.add(EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + "collaborative - anyone with a"); + tooltip.add(EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + "Bingo profile can help to reach"); tooltip.add(EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + "the goal!"); tooltip.add(""); tooltip.add(EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + "The more you contribute"); - tooltip.add(EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + - "towards the goal, the more you"); + tooltip.add(EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + "towards the goal, the more you"); tooltip.add(EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + "will be rewarded"); if (finalTier == totalTiers) { @@ -266,14 +285,12 @@ public class BingoPage { return tooltip; } - private static void showMissingDataMessage(int guiLeft, int guiTop) { + private void showMissingDataMessage(int guiLeft, int guiTop) { String message = EnumChatFormatting.RED + "No Bingo data for current event!"; - Utils.drawStringCentered(message, Minecraft.getMinecraft().fontRendererObj, - guiLeft + 431 / 2f, guiTop + 101, true, 0 - ); + Utils.drawStringCentered(message, Minecraft.getMinecraft().fontRendererObj, guiLeft + 431 / 2f, guiTop + 101, true, 0); } - private static List jsonArrayToStringList(JsonArray completedGoals) { + private List jsonArrayToStringList(JsonArray completedGoals) { List list = new ArrayList<>(); for (JsonElement completedGoal : completedGoals) { list.add(completedGoal.getAsString()); @@ -281,7 +298,7 @@ public class BingoPage { return list; } - private static List jsonArrayToJsonObjectList(JsonArray goals) { + private List jsonArrayToJsonObjectList(JsonArray goals) { List list = new ArrayList<>(); for (JsonElement goal : goals) { list.add(goal.getAsJsonObject()); @@ -290,7 +307,7 @@ public class BingoPage { return list; } - private static void processBingoResources() { + private void processBingoResources() { long currentTime = System.currentTimeMillis(); //renew every 2 minutes diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionPage.java deleted file mode 100644 index c15190a1..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionPage.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * 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 . - */ - -package io.github.moulberry.notenoughupdates.profileviewer; - -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.util.Constants; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; - -import java.awt.*; -import java.io.IOException; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; - -public class CollectionPage { - - private static int guiLeft; - private static int guiTop; - private static int sizeX = 413; - private static int sizeY = 202; - public static final ResourceLocation pv_cols = new ResourceLocation("notenoughupdates:pv_cols.png"); - public static final ResourceLocation pv_elements = new ResourceLocation("notenoughupdates:pv_elements.png"); - private static final int COLLS_XCOUNT = 5; - private static final int COLLS_YCOUNT = 4; - private static final float COLLS_XPADDING = (190 - COLLS_XCOUNT * 20) / (float) (COLL