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') 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) (COLLS_XCOUNT + 1); - private static final float COLLS_YPADDING = (202 - COLLS_YCOUNT * 20) / (float) (COLLS_YCOUNT + 1); - private static final String[] romans = new String[]{ - "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", - "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XIX", "XX" - }; - private static List tooltipToDisplay = null; - private static final NumberFormat numberFormat = NumberFormat.getInstance(Locale.US); - private static ItemStack selectedCollectionCategory = null; - public static void drawColsPage(int mouseX, int mouseY, int width, int height) { - guiLeft = GuiProfileViewer.getGuiLeft(); - guiTop = GuiProfileViewer.getGuiTop(); - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_cols); - Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); - - JsonObject collectionInfo = GuiProfileViewer.getProfile().getCollectionInfo(GuiProfileViewer.getProfileId()); - if (collectionInfo == null) { - Utils.drawStringCentered( - EnumChatFormatting.RED + "Collection API not enabled!", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 134, - guiTop + 101, - true, - 0 - ); - return; - } - JsonObject resourceCollectionInfo = ProfileViewer.getResourceCollectionInformation(); - if (resourceCollectionInfo == null) return; - - int collectionCatSize = ProfileViewer.getCollectionCatToCollectionMap().size(); - int collectionCatYSize = (int) (162f / (collectionCatSize - 1 + 0.0000001f)); - { - int yIndex = 0; - for (ItemStack stack : ProfileViewer.getCollectionCatToCollectionMap().keySet()) { - if (selectedCollectionCategory == null) selectedCollectionCategory = stack; - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - if (stack == selectedCollectionCategory) { - Utils.drawTexturedRect(guiLeft + 7, guiTop + 10 + collectionCatYSize * yIndex, 20, 20, - 20 / 256f, 0, 20 / 256f, 0, GL11.GL_NEAREST - ); - Utils.drawItemStackWithText( - stack, - guiLeft + 10, - guiTop + 13 + collectionCatYSize * yIndex, - "" + (yIndex + 1) - ); - } else { - Utils.drawTexturedRect(guiLeft + 7, guiTop + 10 + collectionCatYSize * yIndex, 20, 20, - 0, 20 / 256f, 0, 20 / 256f, GL11.GL_NEAREST - ); - Utils.drawItemStackWithText(stack, guiLeft + 9, guiTop + 12 + collectionCatYSize * yIndex, "" + (yIndex + 1)); - } - yIndex++; - } - } - - Utils.drawStringCentered( - selectedCollectionCategory.getDisplayName() + " Collections", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 134, - guiTop + 14, - true, - 4210752 - ); - - JsonObject minionTiers = collectionInfo.get("minion_tiers").getAsJsonObject(); - JsonObject collectionTiers = collectionInfo.get("collection_tiers").getAsJsonObject(); - JsonObject maxAmounts = collectionInfo.get("max_amounts").getAsJsonObject(); - JsonObject totalAmounts = collectionInfo.get("total_amounts").getAsJsonObject(); - JsonObject personalAmounts = collectionInfo.get("personal_amounts").getAsJsonObject(); - - List collections = ProfileViewer.getCollectionCatToCollectionMap().get(selectedCollectionCategory); - if (collections != null) { - for (int i = 0; i < collections.size(); i++) { - String collection = collections.get(i); - if (collection != null) { - ItemStack collectionItem = ProfileViewer.getCollectionToCollectionDisplayMap().get(collection); - if (collectionItem != null) { - int xIndex = i % COLLS_XCOUNT; - int yIndex = i / COLLS_XCOUNT; - - float x = 39 + COLLS_XPADDING + (COLLS_XPADDING + 20) * xIndex; - float y = 7 + COLLS_YPADDING + (COLLS_YPADDING + 20) * yIndex; - - String tierString; - int tier = (int) Utils.getElementAsFloat(collectionTiers.get(collection), 0); - if (tier > 20 || tier < 0) { - tierString = String.valueOf(tier); - } else { - tierString = romans[tier]; - } - float amount = Utils.getElementAsFloat(totalAmounts.get(collection), 0); - float maxAmount = Utils.getElementAsFloat(maxAmounts.get(collection), 0); - Color color = new Color(128, 128, 128, 255); - int tierStringColour = color.getRGB(); - float completedness = 0; - if (maxAmount > 0) { - completedness = amount / maxAmount; - } - completedness = Math.min(1, completedness); - if (maxAmounts.has(collection) && completedness >= 1) { - tierStringColour = new Color(255, 215, 0).getRGB(); - } - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - Utils.drawTexturedRect(guiLeft + x, guiTop + y, 20, 20 * (1 - completedness), - 0, 20 / 256f, 0, 20 * (1 - completedness) / 256f, GL11.GL_NEAREST - ); - GlStateManager.color(1, 185 / 255f, 0, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - Utils.drawTexturedRect(guiLeft + x, guiTop + y + 20 * (1 - completedness), 20, 20 * (completedness), - 0, 20 / 256f, 20 * (1 - completedness) / 256f, 20 / 256f, GL11.GL_NEAREST - ); - Utils.drawItemStack(collectionItem, guiLeft + (int) x + 2, guiTop + (int) y + 2); - - if (mouseX > guiLeft + (int) x + 2 && mouseX < guiLeft + (int) x + 18) { - if (mouseY > guiTop + (int) y + 2 && mouseY < guiTop + (int) y + 18) { - tooltipToDisplay = new ArrayList<>(); - tooltipToDisplay.add(collectionItem.getDisplayName() + " " + - (completedness >= 1 ? EnumChatFormatting.GOLD : EnumChatFormatting.GRAY) + tierString); - tooltipToDisplay.add( - "Collected: " + numberFormat.format(Utils.getElementAsFloat(personalAmounts.get(collection), 0))); - tooltipToDisplay.add("Total Collected: " + numberFormat.format(amount)); - } - } - - GlStateManager.color(1, 1, 1, 1); - if (tier >= 0) { - Utils.drawStringCentered(tierString, Minecraft.getMinecraft().fontRendererObj, - guiLeft + x + 10, guiTop + y - 4, true, - tierStringColour - ); - } - - Utils.drawStringCentered(GuiProfileViewer.shortNumberFormat(amount, 0) + "", Minecraft.getMinecraft().fontRendererObj, - guiLeft + x + 10, guiTop + y + 26, true, - color.getRGB() - ); - } - } - } - } - - Utils.drawStringCentered( - selectedCollectionCategory.getDisplayName() + " Minions", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 326, - guiTop + 14, - true, - 4210752 - ); - - List minions = ProfileViewer.getCollectionCatToMinionMap().get(selectedCollectionCategory); - if (minions != null) { - for (int i = 0; i < minions.size(); i++) { - String minion = minions.get(i); - if (minion != null) { - JsonObject misc = Constants.MISC; - float MAX_MINION_TIER = - Utils.getElementAsFloat(Utils.getElement(misc, "minions." + minion + "_GENERATOR"), 11); - - int tier = (int) Utils.getElementAsFloat(minionTiers.get(minion), 0); - JsonObject minionJson; - if (tier == 0) { - minionJson = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(minion + "_GENERATOR_1"); - } else { - minionJson = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(minion + "_GENERATOR_" + tier); - } - - if (minionJson != null) { - int xIndex = i % COLLS_XCOUNT; - int yIndex = i / COLLS_XCOUNT; - - float x = 231 + COLLS_XPADDING + (COLLS_XPADDING + 20) * xIndex; - float y = 7 + COLLS_YPADDING + (COLLS_YPADDING + 20) * yIndex; - - String tierString; - - if (tier - 1 >= romans.length || tier - 1 < 0) { - tierString = String.valueOf(tier); - } else { - tierString = romans[tier - 1]; - } - - Color color = new Color(128, 128, 128, 255); - int tierStringColour = color.getRGB(); - float completedness = tier / MAX_MINION_TIER; - - completedness = Math.min(1, completedness); - if (completedness >= 1) { - tierStringColour = new Color(255, 215, 0).getRGB(); - } - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - Utils.drawTexturedRect(guiLeft + x, guiTop + y, 20, 20 * (1 - completedness), - 0, 20 / 256f, 0, 20 * (1 - completedness) / 256f, GL11.GL_NEAREST - ); - GlStateManager.color(1, 185 / 255f, 0, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - Utils.drawTexturedRect(guiLeft + x, guiTop + y + 20 * (1 - completedness), 20, 20 * (completedness), - 0, 20 / 256f, 20 * (1 - completedness) / 256f, 20 / 256f, GL11.GL_NEAREST - ); - - Utils.drawItemStack( - NotEnoughUpdates.INSTANCE.manager.jsonToStack(minionJson), - guiLeft + (int) x + 2, - guiTop + (int) y + 2 - ); - - if (mouseX > guiLeft + (int) x + 2 && mouseX < guiLeft + (int) x + 18) { - if (mouseY > guiTop + (int) y + 2 && mouseY < guiTop + (int) y + 18) { - tooltipToDisplay = NotEnoughUpdates.INSTANCE.manager.jsonToStack(minionJson) - .getTooltip( - Minecraft.getMinecraft().thePlayer, - false - ); - } - } - - GlStateManager.color(1, 1, 1, 1); - if (tier >= 0) { - Utils.drawStringCentered(tierString, Minecraft.getMinecraft().fontRendererObj, - guiLeft + x + 10, guiTop + y - 4, true, - tierStringColour - ); - } - } - } - } - } - - if (tooltipToDisplay != null) { - List grayTooltip = new ArrayList<>(tooltipToDisplay.size()); - for (String line : tooltipToDisplay) { - grayTooltip.add(EnumChatFormatting.GRAY + line); - } - Utils.drawHoveringText(grayTooltip, mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj); - tooltipToDisplay = null; - } - } - - protected static void keyTypedCols(char typedChar, int keyCode) throws IOException { - ItemStack stack = null; - Iterator items = ProfileViewer.getCollectionCatToCollectionMap().keySet().iterator(); - switch (keyCode) { - case Keyboard.KEY_5: - case Keyboard.KEY_NUMPAD5: - stack = items.next(); - case Keyboard.KEY_4: - case Keyboard.KEY_NUMPAD4: - stack = items.next(); - case Keyboard.KEY_3: - case Keyboard.KEY_NUMPAD3: - stack = items.next(); - case Keyboard.KEY_2: - case Keyboard.KEY_NUMPAD2: - stack = items.next(); - case Keyboard.KEY_1: - case Keyboard.KEY_NUMPAD1: - stack = items.next(); - } - if (stack != null) { - selectedCollectionCategory = stack; - } - Utils.playPressSound(); - } - - public static void mouseReleasedCols(int mouseX, int mouseY, int mouseButton) { - int collectionCatSize = ProfileViewer.getCollectionCatToCollectionMap().size(); - int collectionCatYSize = (int) (162f / (collectionCatSize - 1 + 0.0000001f)); - int yIndex = 0; - for (ItemStack stack : ProfileViewer.getCollectionCatToCollectionMap().keySet()) { - if (mouseX > guiLeft + 7 && mouseX < guiLeft + 7 + 20) { - if (mouseY > guiTop + 10 + collectionCatYSize * yIndex && - mouseY < guiTop + 10 + collectionCatYSize * yIndex + 20) { - selectedCollectionCategory = stack; - Utils.playPressSound(); - return; - } - } - yIndex++; - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java new file mode 100644 index 00000000..b227c815 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java @@ -0,0 +1,493 @@ +/* + * 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 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; +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.input.Mouse; +import org.lwjgl.opengl.GL11; + +public class CollectionsPage extends GuiProfileViewerPage { + + 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) (COLLS_XCOUNT + 1); + private static final float COLLS_YPADDING = (202 - COLLS_YCOUNT * 20) / (float) (COLLS_YCOUNT + 1); + private static final String[] romans = new String[] { + "I", + "II", + "III", + "IV", + "V", + "VI", + "VII", + "VIII", + "IX", + "X", + "XI", + "XII", + "XIII", + "XIV", + "XV", + "XVI", + "XVII", + "XIX", + "XX", + }; + private static final NumberFormat numberFormat = NumberFormat.getInstance(Locale.US); + private static List tooltipToDisplay = null; + private static ItemStack selectedCollectionCategory = null; + private int page = 0; + private int maxPage = 0; + + public CollectionsPage(GuiProfileViewer instance) { + super(instance); + } + + public void drawPage(int mouseX, int mouseY, float partialTicks) { + int guiLeft = GuiProfileViewer.getGuiLeft(); + int guiTop = GuiProfileViewer.getGuiTop(); + + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_cols); + Utils.drawTexturedRect(guiLeft, guiTop, getInstance().sizeX, getInstance().sizeY, GL11.GL_NEAREST); + + JsonObject collectionInfo = GuiProfileViewer.getProfile().getCollectionInfo(GuiProfileViewer.getProfileId()); + if (collectionInfo == null) { + Utils.drawStringCentered( + EnumChatFormatting.RED + "Collection API not enable