diff options
| author | kr45732 <52721908+kr45732@users.noreply.github.com> | 2022-08-11 07:03:39 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-11 21:03:39 +1000 |
| commit | fde462b796ed7fbb22fdf7cf04c032389f3e8629 (patch) | |
| tree | b6791c22df64efdd477a223bd50a84a27a5de953 /src/main/java | |
| parent | ba69e034794b7a5dc8d950ab4ba2d12370aa509f (diff) | |
| download | NotEnoughUpdates-fde462b796ed7fbb22fdf7cf04c032389f3e8629.tar.gz NotEnoughUpdates-fde462b796ed7fbb22fdf7cf04c032389f3e8629.tar.bz2 NotEnoughUpdates-fde462b796ed7fbb22fdf7cf04c032389f3e8629.zip | |
PV Refactoring (#212)
Diffstat (limited to 'src/main/java')
32 files changed, 6783 insertions, 5684 deletions
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<String, ProfileViewer.Level> 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<String, JsonElement> 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<String> 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<String, ProfileViewer.Level> 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 <https://www.gnu.org/licenses/>. + */ + +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<String, ProfileViewer.Level> 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: |
