From f0293a74282cece3aa8a2a328559889d6e187209 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Sun, 26 Jul 2020 12:12:25 +1000 Subject: 1.11.7 --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'build.gradle') diff --git a/build.gradle b/build.gradle index 29128fba..909e51f3 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ apply plugin: 'com.github.johnrengelman.shadow' sourceCompatibility = 1.8 targetCompatibility = 1.8 -version = "1.0" +version = "1.11.7" group= "io.github.moulberry" archivesBaseName = "NotEnoughUpdates" String modid = "notenoughupdates" @@ -49,6 +49,7 @@ mixin { jar { manifest.attributes( + 'Main-Class': 'NotSkyblockAddonsInstallerFrame', 'TweakClass': 'org.spongepowered.asm.launch.MixinTweaker', 'MixinConfigs': "mixins.${modid}.json", 'FMLCorePluginContainsFMLMod': true, -- cgit From 1fbc1f60082ea1bfb5e40eff1ca50b7122f5f38d Mon Sep 17 00:00:00 2001 From: Moulberry Date: Mon, 27 Jul 2020 11:37:56 +1000 Subject: 1.11.8 --- build.gradle | 2 +- .../moulberry/notenoughupdates/NEUManager.java | 116 ++++++- .../moulberry/notenoughupdates/NEUOverlay.java | 7 +- .../notenoughupdates/NotEnoughUpdates.java | 58 +++- .../notenoughupdates/auction/APIManager.java | 28 +- .../notenoughupdates/commands/SimpleCommand.java | 20 ++ .../profileviewer/GuiProfileViewer.java | 380 ++++++++++++++++----- .../profileviewer/PlayerStats.java | 21 +- .../profileviewer/ProfileViewer.java | 57 +++- .../assets/notenoughupdates/pv_dropdown.png | Bin 0 -> 2386 bytes 10 files changed, 540 insertions(+), 149 deletions(-) create mode 100644 src/main/resources/assets/notenoughupdates/pv_dropdown.png (limited to 'build.gradle') diff --git a/build.gradle b/build.gradle index 909e51f3..4c2aafb1 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ apply plugin: 'com.github.johnrengelman.shadow' sourceCompatibility = 1.8 targetCompatibility = 1.8 -version = "1.11.7" +version = "1.11.8" group= "io.github.moulberry" archivesBaseName = "NotEnoughUpdates" String modid = "notenoughupdates" diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 680094af..f78c7e96 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -1359,6 +1359,103 @@ public class NEUManager { return itemMap; } + public String removeUnusedDecimal(double num) { + if(num % 1 == 0) { + return String.valueOf((int)num); + } else { + return String.valueOf(num); + } + } + + public HashMap getLoreReplacements(String petname, String tier, int level) { + JsonObject petnums = null; + if(petname != null && tier != null) { + petnums = Utils.getConstant("petnums"); + } + + HashMap replacements = new HashMap<>(); + if(level < 1) { + replacements.put("LVL", "1\u27A1100"); + } else { + replacements.put("LVL", ""+level); + } + if(petnums != null) { + if(petnums.has(petname)) { + JsonObject petInfo = petnums.get(petname).getAsJsonObject(); + if(petInfo.has(tier)) { + JsonObject petInfoTier = petInfo.get(tier).getAsJsonObject(); + JsonObject min = petInfoTier.get("1").getAsJsonObject(); + JsonObject max = petInfoTier.get("100").getAsJsonObject(); + + if(level < 1) { + JsonArray otherNumsMin = min.get("otherNums").getAsJsonArray(); + JsonArray otherNumsMax = max.get("otherNums").getAsJsonArray(); + for(int i=0; i entry : max.get("statNums").getAsJsonObject().entrySet()) { + int statMax = (int)Math.floor(entry.getValue().getAsFloat()); + int statMin = (int)Math.floor(min.get("statNums").getAsJsonObject().get(entry.getKey()).getAsFloat()); + String statStr = "+"+statMin+"\u27A1"+statMax; + replacements.put(entry.getKey(), statStr); + } + } else { + + } + } + } + } + + return replacements; + } + + public HashMap getLoreReplacements(NBTTagCompound tag, int level) { + String petname = null; + String tier = null; + if(tag != null && tag.hasKey("ExtraAttributes")) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + if(ea.hasKey("petInfo")) { + String petInfoStr = ea.getString("petInfo"); + JsonObject petInfo = gson.fromJson(petInfoStr, JsonObject.class); + petname = petInfo.get("type").getAsString(); + tier = petInfo.get("tier").getAsString(); + if(petInfo.has("heldItem")) { + String heldItem = petInfo.get("heldItem").getAsString(); + if(heldItem.equals("PET_ITEM_TIER_BOOST")) { + switch(tier) { + case "COMMON": + tier = "UNCOMMON"; break; + case "UNCOMMON": + tier = "RARE"; break; + case "RARE": + tier = "EPIC"; break; + case "EPIC": + tier = "LEGENDARY"; break; + } + } + } + } + } + return getLoreReplacements(petname, tier, level); + } + + public NBTTagList processLore(JsonArray lore, HashMap replacements) { + NBTTagList nbtLore = new NBTTagList(); + for(JsonElement line : lore) { + String lineStr = line.getAsString(); + if(!lineStr.contains("Click to view recipes!") && + !lineStr.contains("Click to view recipe!")) { + for(Map.Entry entry : replacements.entrySet()) { + lineStr = lineStr.replace("{"+entry.getKey()+"}", entry.getValue()); + } + nbtLore.appendTag(new NBTTagString(lineStr)); + } + } + return nbtLore; + } + public ItemStack jsonToStack(JsonObject json) { return jsonToStack(json, true); } @@ -1387,24 +1484,23 @@ public class NEUManager { NBTTagCompound tag = JsonToNBT.getTagFromJson(json.get("nbttag").getAsString()); stack.setTagCompound(tag); } catch(NBTException e) { - if(json.get("internalname").getAsString().equalsIgnoreCase("ROCK;0")) e.printStackTrace(); } } + HashMap replacements = getLoreReplacements(stack.getTagCompound(), -1); + + String displayname = json.get("displayname").getAsString(); + for(Map.Entry entry : replacements.entrySet()) { + displayname = displayname.replace("{"+entry.getKey()+"}", entry.getValue()); + } + stack.setStackDisplayName(displayname); + if(json.has("lore")) { NBTTagCompound display = new NBTTagCompound(); if(stack.getTagCompound() != null && stack.getTagCompound().hasKey("display")) { display = stack.getTagCompound().getCompoundTag("display"); } - NBTTagList lore = new NBTTagList(); - for(JsonElement line : json.get("lore").getAsJsonArray()) { - String lineStr = line.getAsString(); - if(!lineStr.contains("Click to view recipes!") && - !lineStr.contains("Click to view recipe!")) { - lore.appendTag(new NBTTagString(lineStr)); - } - } - display.setTag("Lore", lore); + display.setTag("Lore", processLore(json.get("lore").getAsJsonArray(), replacements)); NBTTagCompound tag = stack.getTagCompound() != null ? stack.getTagCompound() : new NBTTagCompound(); tag.setTag("display", display); stack.setTagCompound(tag); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 7db8875d..a234ca8a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -1803,12 +1803,7 @@ public class NEUOverlay extends Gui { //Render tooltip JsonObject json = tooltipToDisplay.get(); if(json != null) { - List text = new ArrayList<>(); - text.add(json.get("displayname").getAsString()); - JsonArray lore = json.get("lore").getAsJsonArray(); - for(int i=0; i text = manager.jsonToStack(json).getTooltip(Minecraft.getMinecraft().thePlayer, false); String internalname = json.get("internalname").getAsString(); JsonObject auctionInfo = manager.getItemAuctionInfo(internalname); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index efd38c55..169b6b9f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -19,6 +19,7 @@ import io.github.moulberry.notenoughupdates.questing.SBScoreboardData; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.*; @@ -38,10 +39,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.Scoreboard; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.Matrix4f; -import net.minecraft.util.Session; +import net.minecraft.util.*; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.*; import net.minecraftforge.common.MinecraftForge; @@ -140,7 +138,7 @@ public class NotEnoughUpdates { } }); - private static ProfileViewer profileViewer; + public static ProfileViewer profileViewer; SimpleCommand viewProfileCommand = new SimpleCommand("neuprofile", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { @@ -148,16 +146,34 @@ public class NotEnoughUpdates { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This feature requires FBOs to work. Try disabling Optifine's 'Fast Render'.")); } else*/ - if(args.length != 1) { + if (manager.config.apiKey.value == null || manager.config.apiKey.value.trim().isEmpty()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "idiot.")); + "Can't view profile, apikey is not set. Run /api new and put the result in settings.")); + } else if (args.length == 0) { + profileViewer.getProfileByName(Minecraft.getMinecraft().thePlayer.getName(), profile -> { + if (profile != null) profile.resetCache(); + openGui = new GuiProfileViewer(profile); + }); + } else if (args.length > 1) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + + "Too many arguments. Usage: /neuprofile [name]")); } else { profileViewer.getProfileByName(args[0], profile -> { - profile.resetCache(); + if (profile != null) profile.resetCache(); openGui = new GuiProfileViewer(profile); }); } - //openGui = new GuiProfileViewer(null); + } + }, new SimpleCommand.TabCompleteRunnable() { + @Override + public List tabComplete(ICommandSender sender, String[] args, BlockPos pos) { + /*if(args.length) { + + }*/ + for(String arg : args) { + System.out.println(arg); + } + return null; } }); @@ -200,7 +216,7 @@ public class NotEnoughUpdates { "You must be on Skyblock to use this feature.")); } else if(manager.config.apiKey.value == null || manager.config.apiKey.value.trim().isEmpty()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+ - "Can't open NeuAH, Api Key is not set. Run /api new and put the result in settings.")); + "Can't open NeuAH, apikey is not set. Run /api new and put the result in settings.")); } else { openGui = new CustomAHGui(); manager.auctionManager.customAH.lastOpen = System.currentTimeMillis(); @@ -228,7 +244,6 @@ public class NotEnoughUpdates { ClientCommandHandler.instance.registerCommand(viewProfileCommand); ClientCommandHandler.instance.registerCommand(overlayPlacementsCommand); ClientCommandHandler.instance.registerCommand(enchantColourCommand); - //ClientCommandHandler.instance.registerCommand(questingCommand); ClientCommandHandler.instance.registerCommand(neuAhCommand); neuio = new NEUIO(getAccessToken()); @@ -712,7 +727,7 @@ public class NotEnoughUpdates { */ @SubscribeEvent public void onGuiBackgroundDraw(GuiScreenEvent.BackgroundDrawnEvent event) { - if((event.gui instanceof GuiContainer || event.gui instanceof CustomAHGui || event.gui instanceof GuiItemRecipe) && isOnSkyblock()) { + if((shouldRenderOverlay(event.gui) || event.gui instanceof CustomAHGui) && isOnSkyblock()) { ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); int width = scaledresolution.getScaledWidth(); @@ -771,6 +786,19 @@ public class NotEnoughUpdates { } } + private static boolean shouldRenderOverlay(Gui gui) { + boolean validGui = gui instanceof GuiContainer || gui instanceof GuiItemRecipe; + if(gui instanceof GuiChest) { + GuiChest eventGui = (GuiChest) gui; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + if(containerName.trim().equals("Fast Travel")) { + validGui = false; + } + } + return validGui; + } + /** * Will draw the NEUOverlay over the inventory if focusInv == false. (z-translation of 300 is so that NEUOverlay * will draw over Items in the inventory (which render at a z value of about 250)) @@ -779,7 +807,7 @@ public class NotEnoughUpdates { @SubscribeEvent public void onGuiScreenDrawPost(GuiScreenEvent.DrawScreenEvent.Post event) { if(!(event.gui instanceof CustomAHGui || manager.auctionManager.customAH.isRenderOverAuctionView())) { - if((event.gui instanceof GuiContainer || event.gui instanceof GuiItemRecipe) && isOnSkyblock()) { + if(shouldRenderOverlay(event.gui) && isOnSkyblock()) { renderDungeonChestOverlay(event.gui); @@ -889,7 +917,7 @@ public class NotEnoughUpdates { overlay.mouseInput(); return; } - if(event.gui instanceof GuiContainer && !(hoverInv && focusInv) && isOnSkyblock()) { + if(shouldRenderOverlay(event.gui) && !(hoverInv && focusInv) && isOnSkyblock()) { if(overlay.mouseInput()) { event.setCanceled(true); } @@ -914,7 +942,7 @@ public class NotEnoughUpdates { return; } - if(event.gui instanceof GuiContainer && isOnSkyblock()) { + if(shouldRenderOverlay(event.gui) && isOnSkyblock()) { if(overlay.keyboardInput(focusInv)) { event.setCanceled(true); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java index 4d30cf3e..72baf3a7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -365,6 +365,9 @@ public class APIManager { return -1; } + private String[] romans = new String[]{"I","II","III","IV","V","VI","VII","VIII","IX","X","XI", + "XII","XIII","XIV","XV","XVI","XVII","XIX","XX"}; + private void getPageFromAPI(int page) { //System.out.println("Trying to update page: " + page); HashMap args = new HashMap<>(); @@ -411,7 +414,7 @@ public class APIManager { bin = auction.get("bin").getAsBoolean(); } String sbCategory = auction.get("category").getAsString(); - String extras = auction.get("extra").getAsString(); + String extras = auction.get("extra").getAsString().toLowerCase(); String item_name = auction.get("item_name").getAsString(); String item_lore = Utils.fixBrokenAPIColour(auction.get("item_lore").getAsString()); String item_bytes = auction.get("item_bytes").getAsString(); @@ -437,6 +440,8 @@ public class APIManager { String displayNormal = ""; if(manager.getItemInformation().containsKey(internalname)) { displayNormal = Utils.cleanColour(manager.getItemInformation().get(internalname).get("displayname").getAsString()); + } else { + } String[] lore = new String[0]; @@ -451,6 +456,25 @@ public class APIManager { tag.setTag("display", display); item_tag.getTagList("i", 10).getCompoundTagAt(0).setTag("tag", tag); + if(tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + if(ea.hasKey("enchantments", 10)) { + NBTTagCompound enchantments = ea.getCompoundTag("enchantments"); + for(String key : enchantments.getKeySet()) { + String enchantname = key.toLowerCase().replace("_", " "); + int enchantlevel = enchantments.getInteger(key); + String enchantLevelStr; + if(enchantlevel >= 1 && enchantlevel <= 20) { + enchantLevelStr = romans[enchantlevel-1]; + } else { + enchantLevelStr = String.valueOf(enchantlevel); + } + extras = extras.replace(enchantname, enchantname + " " + enchantLevelStr); + } + } + } + int index=0; for(String str : extras.split(" ")) { str = Utils.cleanColour(str).toLowerCase(); @@ -491,7 +515,7 @@ public class APIManager { if(itemType >= 0 && itemType < categoryItemType.length) { category = categoryItemType[itemType]; } - if(extras.startsWith("Enchanted Book")) category = "ebook"; + if(internalname.equals("ENCHANTED_BOOK")) category = "ebook"; if(extras.endsWith("Potion")) category = "potion"; if(extras.contains("Rune")) category = "rune"; if(item_lore.split("\n")[0].endsWith("Furniture")) category = "furniture"; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/SimpleCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/SimpleCommand.java index ae27be46..029e24db 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/SimpleCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/SimpleCommand.java @@ -3,21 +3,36 @@ package io.github.moulberry.notenoughupdates.commands; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; +import net.minecraft.util.BlockPos; + +import java.util.ArrayList; +import java.util.List; public class SimpleCommand extends CommandBase { private String commandName; private ProcessCommandRunnable runnable; + private TabCompleteRunnable tabRunnable; public SimpleCommand(String commandName, ProcessCommandRunnable runnable) { this.commandName = commandName; this.runnable = runnable; } + public SimpleCommand(String commandName, ProcessCommandRunnable runnable, TabCompleteRunnable tabRunnable) { + this.commandName = commandName; + this.runnable = runnable; + this.tabRunnable = tabRunnable; + } + public abstract static class ProcessCommandRunnable { public abstract void processCommand(ICommandSender sender, String[] args); } + public abstract static class TabCompleteRunnable { + public abstract List tabComplete(ICommandSender sender, String[] args, BlockPos pos); + } + public boolean canCommandSenderUseCommand(ICommandSender sender) { return true; } @@ -33,4 +48,9 @@ public class SimpleCommand extends CommandBase { public void processCommand(ICommandSender sender, String[] args) throws CommandException { runnable.processCommand(sender, args); } + + public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { + if(tabRunnable != null) return tabRunnable.tabComplete(sender, args, pos); + return null; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java index 2b3eb2d1..6aa2a1ab 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -66,6 +66,7 @@ public class GuiProfileViewer extends GuiScreen { public static final ResourceLocation pv_invs = new ResourceLocation("notenoughupdates:pv_invs.png"); public static final ResourceLocation pv_cols = new ResourceLocation("notenoughupdates:pv_cols.png"); public static final ResourceLocation pv_pets = new ResourceLocation("notenoughupdates:pv_pets.png"); + public static final ResourceLocation pv_dropdown = new ResourceLocation("notenoughupdates:pv_dropdown.png"); public static final ResourceLocation pv_bg = new ResourceLocation("notenoughupdates:pv_bg.png"); public static final ResourceLocation pv_elements = new ResourceLocation("notenoughupdates:pv_elements.png"); public static final ResourceLocation resource_packs = new ResourceLocation("minecraft:textures/gui/resource_packs.png"); @@ -89,11 +90,16 @@ public class GuiProfileViewer extends GuiScreen { private List tooltipToDisplay = null; + private String profileId = null; + private boolean profileDropdownSelected = false; + public enum ProfileViewerPage { + LOADING(null), + INVALID_NAME(null), BASIC(new ItemStack(Items.paper)), INVS(new ItemStack(Item.getItemFromBlock(Blocks.ender_chest))), - COLS(new ItemStack(Items.painting)), - PETS(new ItemStack(Items.bone)); + COLS(new ItemStack(Items.painting)); + //PETS(new ItemStack(Items.bone)); public final ItemStack stack; @@ -105,13 +111,27 @@ public class GuiProfileViewer extends GuiScreen { public GuiProfileViewer(ProfileViewer.Profile profile) { this.profile = profile; + String name = ""; + if(profile != null) { + name = profile.getHypixelProfile().get("displayname").getAsString(); + } + playerNameTextField = new GuiElementTextField(name, + GuiElementTextField.SCALE_TEXT); + playerNameTextField.setSize(100, 20); } + private GuiElementTextField playerNameTextField; + @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { currentTime = System.currentTimeMillis(); if(startTime == 0) startTime = currentTime; + if(profile == null) currentPage = ProfileViewerPage.INVALID_NAME; + if(profileId == null && profile != null && profile.getLatestProfile() != null) { + profileId = profile.getLatestProfile(); + } + this.sizeX = 431; this.sizeY = 202; this.guiLeft = (this.width-this.sizeX)/2; @@ -121,7 +141,7 @@ public class GuiProfileViewer extends GuiScreen { drawDefaultBackground(); blurBackground(); - renderBlurredBackground(width, height, guiLeft, guiTop, sizeX, sizeY); + renderBlurredBackground(width, height, guiLeft+2, guiTop+2, sizeX-4, sizeY-4); GlStateManager.translate(0, 0, 5); renderTabs(true); @@ -151,13 +171,56 @@ public class GuiProfileViewer extends GuiScreen { case COLS: drawColsPage(mouseX, mouseY, partialTicks); break; - case PETS: - drawPetsPage(mouseX, mouseY, partialTicks); + case LOADING: + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Loading player profiles...", Minecraft.getMinecraft().fontRendererObj, + guiLeft+sizeX/2f, guiTop+101, true, 0); + break; + case INVALID_NAME: + Utils.drawStringCentered(EnumChatFormatting.RED+"Invalid name or API is down!", Minecraft.getMinecraft().fontRendererObj, + guiLeft+sizeX/2f, guiTop+101, true, 0); break; + //case PETS: + // drawPetsPage(mouseX, mouseY, partialTicks); + // break; } lastTime = currentTime; + if(!(currentPage == ProfileViewerPage.LOADING)) { + playerNameTextField.render(guiLeft+sizeX-100, guiTop+sizeY+5); + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + if(profile != null) { + renderBlurredBackground(width, height, guiLeft+2, guiTop+sizeY+3+2, 100-4, 20-4); + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_dropdown); + Utils.drawTexturedRect(guiLeft, guiTop+sizeY+3, 100, 20, + 0, 100/200f, 0, 20/185f, GL11.GL_NEAREST); + Utils.drawStringCenteredScaledMaxWidth(profileId, Minecraft.getMinecraft().fontRendererObj, guiLeft+50, + guiTop+sizeY+3+10, true, 90, new Color(63, 224, 208, 255).getRGB()); + + if(profileDropdownSelected && !profile.getProfileIds().isEmpty() && scaledResolution.getScaleFactor() != 4) { + int dropdownOptionSize = scaledResolution.getScaleFactor()==3?10:20; + + int numProfiles = profile.getProfileIds().size(); + int sizeYDropdown = numProfiles*dropdownOptionSize; + renderBlurredBackground(width, height, guiLeft+2, guiTop+sizeY+23, 100-4, sizeYDropdown-2); + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_dropdown); + Utils.drawTexturedRect(guiLeft, guiTop+sizeY+23-3, 100, 3, + 100/200f, 1, 0, 3/185f, GL11.GL_NEAREST); + Utils.drawTexturedRect(guiLeft, guiTop+sizeY+23+sizeYDropdown-4, 100, 4, + 100/200f, 1, 181/185f, 1, GL11.GL_NEAREST); + Utils.drawTexturedRect(guiLeft, guiTop+sizeY+23, 100, sizeYDropdown-4, + 100/200f, 1, (181-sizeYDropdown)/185f, 181/185f, GL11.GL_NEAREST); + + for(int yIndex=0; yIndex grayTooltip = new ArrayList<>(tooltipToDisplay.size()); @@ -169,12 +232,33 @@ public class GuiProfileViewer extends GuiScreen { } } + private boolean isLoadedProfile() { + return profile.getProfileInformation(profileId) != null; + } + + private boolean isCollectionApiEnabled() { + return profile.getCollectionInfo(profileId) != null; + } + + private boolean isInventoryApiEnabled() { + return profile.getInventoryInfo(profileId) != null; + } + + private boolean isSkillsApiEnabled() { + return profile.getSkillInfo(profileId) != null; + } + private void renderTabs(boolean renderPressed) { + int ignoredTabs = 0; for(int i=0; i x && mouseX < x+28) { - if(mouseY > y && mouseY < y+32) { - if(currentPage != page) Utils.playPressSound(); - currentPage = page; - inventoryTextField.otherComponentClick(); - return; + if(currentPage != ProfileViewerPage.LOADING && currentPage != ProfileViewerPage.INVALID_NAME) { + int ignoredTabs = 0; + for(int i=0; i x && mouseX < x+28) { + if(mouseY > y && mouseY < y+32) { + if(currentPage != page) Utils.playPressSound(); + currentPage = page; + inventoryTextField.otherComponentClick(); + playerNameTextField.otherComponentClick(); + return; + } } } } @@ -242,10 +335,64 @@ public class GuiProfileViewer extends GuiScreen { if(mouseX > guiLeft+19 && mouseX < guiLeft+19+88) { if(mouseY > guiTop+sizeY-26-20 && mouseY < guiTop+sizeY-26) { inventoryTextField.mouseClicked(mouseX, mouseY, mouseButton); + playerNameTextField.otherComponentClick(); return; } } } + if(mouseX > guiLeft+sizeX-100 && mouseX < guiLeft+sizeX) { + if(mouseY > guiTop+sizeY+5 && mouseY < guiTop+sizeY+25) { + playerNameTextField.mouseClicked(mouseX, mouseY, mouseButton); + inventoryTextField.otherComponentClick(); + return; + } + } + if(mouseX > guiLeft && mouseX < guiLeft+100 && profile != null && !profile.getProfileIds().isEmpty()) { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + if(mouseY > guiTop+sizeY+3 && mouseY < guiTop+sizeY+23) { + if(scaledResolution.getScaleFactor() == 4) { + profileDropdownSelected = false; + int profileNum = 0; + for(int index=0; index= profile.getProfileIds().size()) profileNum = 0; + if(profileNum < 0) profileNum = profile.getProfileIds().size()-1; + + String newProfileId = profile.getProfileIds().get(profileNum); + if(profileId != null && !profileId.equals(newProfileId)) { + resetCache(); + } + profileId = newProfileId; + } else { + profileDropdownSelected = !profileDropdownSelected; + } + } else if(scaledResolution.getScaleFactor() != 4) { + int dropdownOptionSize = scaledResolution.getScaleFactor()==3?10:20; + int extraY = mouseY - (guiTop+sizeY+23); + int index = extraY/dropdownOptionSize; + if(index >= 0 && index < profile.getProfileIds().size()) { + String newProfileId = profile.getProfileIds().get(index); + if(profileId != null && !profileId.equals(newProfileId)) { + resetCache(); + } + profileId = newProfileId; + } + } + playerNameTextField.otherComponentClick(); + inventoryTextField.otherComponentClick(); + return; + } + profileDropdownSelected = false; + playerNameTextField.otherComponentClick(); inventoryTextField.otherComponentClick(); } @@ -261,6 +408,16 @@ public class GuiProfileViewer extends GuiScreen { keyTypedCols(typedChar, keyCode); break; } + if(playerNameTextField.getFocus() && !(currentPage == ProfileViewerPage.LOADING)) { + if(keyCode == Keyboard.KEY_RETURN) { + currentPage = ProfileViewerPage.LOADING; + NotEnoughUpdates.profileViewer.getProfileByName(playerNameTextField.getText(), profile -> { //todo: invalid name + if(profile != null) profile.resetCache(); + Minecraft.getMinecraft().displayGuiScreen(new GuiProfileViewer(profile)); + }); + } + playerNameTextField.keyTyped(typedChar, keyCode); + } } @Override @@ -347,9 +504,9 @@ public class GuiProfileViewer extends GuiScreen { i++; } - JsonObject inventoryInfo = profile.getInventoryInfo(null); + JsonObject inventoryInfo = profile.getInventoryInfo(profileId); if(inventoryInfo == null) return; - JsonObject collectionInfo = profile.getCollectionInfo(null); + JsonObject collectionInfo = profile.getCollectionInfo(profileId); if(collectionInfo == null) return; ItemStack[][][] inventories = getItemsForInventory(inventoryInfo, collectionInfo, selectedInventory); @@ -394,11 +551,19 @@ public class GuiProfileViewer extends GuiScreen { } } + private static HashMap minionRarityToNumMap = new HashMap<>(); + static { + minionRarityToNumMap.put("COMMON", "0"); + minionRarityToNumMap.put("UNCOMMON", "1"); + minionRarityToNumMap.put("RARE", "2"); + minionRarityToNumMap.put("EPIC", "3"); + minionRarityToNumMap.put("LEGENDARY", "4"); + } private void drawPetsPage(int mouseX, int mouseY, float partialTicks) { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_pets); Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); - JsonObject petsInfo = profile.getPetsInfo(null); + JsonObject petsInfo = profile.getPetsInfo(profileId); if(petsInfo == null) return; JsonArray pets = petsInfo.get("pets").getAsJsonArray(); @@ -407,7 +572,7 @@ public class GuiProfileViewer extends GuiScreen { } - if(minions != null) { + /*if(minions != null) { for (int i = 0; i < minions.size(); i++) { String minion = minions.get(i); if (minion != null) { @@ -421,7 +586,7 @@ public class GuiProfileViewer extends GuiScreen { } } } - } + }*/ } private String[] romans = new String[]{"I","II","III","IV","V","VI","VII","VIII","IX","X","XI", @@ -436,8 +601,12 @@ public class GuiProfileViewer extends GuiScreen { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_cols); Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); - JsonObject collectionInfo = profile.getCollectionInfo(null); - if(collectionInfo == null) return; + JsonObject collectionInfo = profile.getCollectionInfo(profileId); + 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; @@ -694,6 +863,7 @@ public class GuiProfileViewer extends GuiScreen { } private int getAvailableSlotsForInventory(JsonObject inventoryInfo, JsonObject collectionInfo, String invName) { + if(collectionInfo == null) return -1; JsonObject misc = Utils.getConstant("misc"); if(misc == null) return -1; JsonElement sizesElement = Utils.getElement(misc, "bag_size."+invName+".sizes"); @@ -793,10 +963,52 @@ public class GuiProfileViewer extends GuiScreen { Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); inventoryTextField.setSize(88, 20); - JsonObject inventoryInfo = profile.getInventoryInfo(null); + JsonObject inventoryInfo = profile.getInventoryInfo(profileId); if(inventoryInfo == null) return; - JsonObject collectionInfo = profile.getCollectionInfo(null); - if(collectionInfo == null) return; + JsonObject collectionInfo = profile.getCollectionInfo(profileId); + + int invNameIndex=0; + for(Map.Entry entry : invNameToDisplayMap.entrySet()) { + int xIndex = invNameIndex%3; + int yIndex = invNameIndex/3; + + int x = 19+34*xIndex; + int y = 26+34*yIndex; + + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); + if(entry.getKey().equals(selectedInventory)) { + Utils.drawTexturedRect(guiLeft+x-2, guiTop+y-2, 20, 20, 20/256f, 0, + 20/256f, 0, GL11.GL_NEAREST); + x++; + y++; + } else { + Utils.drawTexturedRect(guiLeft+x-2, guiTop+y-2, 20, 20, 0, 20/256f, + 0, 20/256f, GL11.GL_NEAREST); + } + + Utils.drawItemStackWithText(entry.getValue(), guiLeft+x, guiTop+y, ""+(invNameIndex+1)); + + if(mouseX >= guiLeft+x && mouseX <= guiLeft+x+16) { + if(mouseY >= guiTop+y && mouseY <= guiTop+y+16) { + tooltipToDisplay = entry.getValue().getTooltip(Minecraft.getMinecraft().thePlayer, false); + } + } + + invNameIndex++; + } + + inventoryTextField.render(guiLeft+19, guiTop+sizeY-26-20); + + ItemStack[][][] inventories = getItemsForInventory(inventoryInfo, collectionInfo, selectedInventory); + if(currentInventoryIndex >= inventories.length) currentInventoryIndex = inventories.length-1; + if(currentInventoryIndex < 0) currentInventoryIndex = 0; + + ItemStack[][] inventory = inventories[currentInventoryIndex]; + if(inventory == null) { + Utils.drawStringCentered(EnumChatFormatting.RED+"Inventory API not enabled!", Minecraft.getMinecraft().fontRendererObj, + guiLeft+317, guiTop+101, true, 0); + return; + } if(bestWeapons == null) { bestWeapons = findBestItems(inventoryInfo, 6, new String[]{"inv_contents", "ender_chest_contents"}, @@ -881,45 +1093,6 @@ public class GuiProfileViewer extends GuiScreen { } } - inventoryTextField.render(guiLeft+19, guiTop+sizeY-26-20); - - int i=0; - for(Map.Entry entry : invNameToDisplayMap.entrySet()) { - int xIndex = i%3; - int yIndex = i/3; - - int x = 19+34*xIndex; - int y = 26+34*yIndex; - - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - if(entry.getKey().equals(selectedInventory)) { - Utils.drawTexturedRect(guiLeft+x-2, guiTop+y-2, 20, 20, 20/256f, 0, - 20/256f, 0, GL11.GL_NEAREST); - x++; - y++; - } else { - Utils.drawTexturedRect(guiLeft+x-2, guiTop+y-2, 20, 20, 0, 20/256f, - 0, 20/256f, GL11.GL_NEAREST); - } - - Utils.drawItemStackWithText(entry.getValue(), guiLeft+x, guiTop+y, ""+(i+1)); - - if(mouseX >= guiLeft+x && mouseX <= guiLeft+x+16) { - if(mouseY >= guiTop+y && mouseY <= guiTop+y+16) { - tooltipToDisplay = entry.getValue().getTooltip(Minecraft.getMinecraft().thePlayer, false); - } - } - - i++; - } - - ItemStack[][][] inventories = getItemsForInventory(inventoryInfo, collectionInfo, selectedInventory); - if(currentInventoryIndex >= inventories.length) currentInventoryIndex = inventories.length-1; - if(currentInventoryIndex < 0) currentInventoryIndex = 0; - - ItemStack[][] inventory = inventories[currentInventoryIndex]; - if(inventory == null) return; - int inventoryRows = inventory.length; GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); @@ -1236,7 +1409,7 @@ public class GuiProfileViewer extends GuiScreen { Utils.drawStringCentered(statusStr, fr, guiLeft+63, guiTop+160, true, 0); } - if(profile.getPlayerInformation(null) == null) { + if(!isLoadedProfile()) { //TODO: "Downloading player information" return; } @@ -1268,12 +1441,11 @@ public class GuiProfileViewer extends GuiScreen { entityPlayer.getDataWatcher().updateObject(10, b); } - JsonObject profileInfo = profile.getProfileInformation(null); + JsonObject profileInfo = profile.getProfileInformation(profileId); if(profileInfo == null) return; - JsonObject skillInfo = profile.getSkillInfo(null); - JsonObject inventoryInfo = profile.getInventoryInfo(null); - JsonObject collectionInfo = profile.getCollectionInfo(null); + JsonObject skillInfo = profile.getSkillInfo(profileId); + JsonObject inventoryInfo = profile.getInventoryInfo(profileId); if(backgroundClickedX != -1 && Mouse.isButtonDown(1)) { for(int i=0; i(); + currentInventoryIndex = 0; + arrowCount = -1; + greenCandyCount = -1; + purpleCandyCount = -1; + entityPlayer = null; + playerLocationSkin = null; + playerLocationCape = null; + skinType = null; + } + Shader blurShaderHorz = null; Framebuffer blurOutputHorz = null; Shader blurShaderVert = null; @@ -1643,13 +1839,13 @@ public class GuiProfileViewer extends GuiScreen { public void renderBlurredBackground(int width, int height, int x, int y, int blurWidth, int blurHeight) { float uMin = x/(float)width; float uMax = (x+blurWidth)/(float)width; - float vMin = y/(float)height; - float vMax = (y+blurHeight)/(float)height; + float vMin = (height-y)/(float)height; + float vMax = (height-y-blurHeight)/(float)height; blurOutputVert.bindFramebufferTexture(); GlStateManager.color(1f, 1f, 1f, 1f); //Utils.setScreen(width*f, height*f, f); - Utils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMax, vMin); + Utils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax); //Utils.setScreen(width, height, f); blurOutputVert.unbindFramebufferTexture(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java index 2cbb09d1..d45fd82b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java @@ -316,15 +316,15 @@ public class PlayerStats { return bonuses; } - private static final Pattern HEALTH_PATTERN = Pattern.compile("^Health: \\+([0-9]+)"); - private static final Pattern DEFENCE_PATTERN = Pattern.compile("^Defense: \\+([0-9]+)"); - private static final Pattern STRENGTH_PATTERN = Pattern.compile("^Strength: \\+([0-9]+)"); - private static final Pattern SPEED_PATTERN = Pattern.compile("^Speed: \\+([0-9]+)"); - private static final Pattern CC_PATTERN = Pattern.compile("^Crit Chance: \\+([0-9]+)"); - private static final Pattern CD_PATTERN = Pattern.compile("^Crit Damage: \\+([0-9]+)"); - private static final Pattern ATKSPEED_PATTERN = Pattern.compile("^Bonus Attack Speed: \\+([0-9]+)"); - private static final Pattern INTELLIGENCE_PATTERN = Pattern.compile("^Intelligence: \\+([0-9]+)"); - private static final Pattern SCC_PATTERN = Pattern.compile("^Sea Creature Chance: \\+([0-9]+)"); + private static final Pattern HEALTH_PATTERN = Pattern.compile("^Health: ((?:\\+|-)[0-9]+)"); + private static final Pattern DEFENCE_PATTERN = Pattern.compile("^Defense: ((?:\\+|-)[0-9]+)"); + private static final Pattern STRENGTH_PATTERN = Pattern.compile("^Strength: ((?:\\+|-)[0-9]+)"); + private static final Pattern SPEED_PATTERN = Pattern.compile("^Speed: ((?:\\+|-)[0-9]+)"); + private static final Pattern CC_PATTERN = Pattern.compile("^Crit Chance: ((?:\\+|-)[0-9]+)"); + private static final Pattern CD_PATTERN = Pattern.compile("^Crit Damage: ((?:\\+|-)[0-9]+)"); + private static final Pattern ATKSPEED_PATTERN = Pattern.compile("^Bonus Attack Speed: ((?:\\+|-)[0-9]+)"); + private static final Pattern INTELLIGENCE_PATTERN = Pattern.compile("^Intelligence: ((?:\\+|-)[0-9]+)"); + private static final Pattern SCC_PATTERN = Pattern.compile("^Sea Creature Chance: ((?:\\+|-)[0-9]+)"); private static final HashMap STAT_PATTERN_MAP = new HashMap<>(); static { STAT_PATTERN_MAP.put("health", HEALTH_PATTERN); @@ -472,6 +472,9 @@ public class PlayerStats { } for(Map.Entry statEntry : stats.statsJson.entrySet()) { + if(statEntry.getKey().equals(CRIT_DAMAGE) || + statEntry.getKey().equals(INTELLIGENCE) || + statEntry.getKey().equals(BONUS_ATTACK_SPEED)) continue; stats.statsJson.add(statEntry.getKey(), new JsonPrimitive(Math.max(0, statEntry.getValue().getAsFloat()))); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java index f79b4767..c703bc9e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -261,9 +261,10 @@ public class ProfileViewer { private final HashMap skillInfoMap = new HashMap<>(); private final HashMap inventoryInfoMap = new HashMap<>(); private final HashMap collectionInfoMap = new HashMap<>(); + private List profileIds = new ArrayList<>(); private JsonObject playerStatus = null; - private PlayerStats.Stats stats = null; - private PlayerStats.Stats passiveStats = null; + private HashMap stats = new HashMap<>(); + private HashMap passiveStats = new HashMap<>(); public Profile(String uuid) { this.uuid = uuid; @@ -294,6 +295,10 @@ public class ProfileViewer { return null; } + public String getLatestProfile() { + return latestProfile; + } + public JsonArray getPlayerInformation(Runnable runnable) { if (playerInformation != null) return playerInformation; if (updatingPlayerInfoState.get()) return null; @@ -312,10 +317,15 @@ public class ProfileViewer { if (playerInformation == null) return; String backup = null; long backupLastSave = 0; + + profileIds.clear(); + for (int i = 0; i < playerInformation.size(); i++) { JsonObject profile = playerInformation.get(i).getAsJsonObject(); String cute_name = profile.get("cute_name").getAsString(); + profileIds.add(cute_name); + if (backup == null) backup = cute_name; if (!profile.has("members")) continue; @@ -343,6 +353,10 @@ public class ProfileViewer { return null; } + public List getProfileIds() { + return profileIds; + } + public JsonObject getProfileInformation(String profileId) { JsonArray playerInfo = getPlayerInformation(() -> {}); if(playerInfo == null) return null; @@ -358,7 +372,7 @@ public class ProfileViewer { if(profile.get("cute_name").getAsString().equalsIgnoreCase(profileId)) { if(!profile.has("members")) return null; JsonObject members = profile.get("members").getAsJsonObject(); - if(!members.has(uuid)) return null; + if(!members.has(uuid)) continue; JsonObject profileInfo = members.get(uuid).getAsJsonObject(); if(profile.has("banking")) { profileInfo.add("banking", profile.get("banking").getAsJsonObject()); @@ -406,8 +420,9 @@ public class ProfileViewer { playerInformation = null; basicInfo = null; playerStatus = null; - stats = null; - passiveStats = null; + stats.clear(); + passiveStats.clear(); + profileIds.clear(); profileMap.clear(); coopProfileMap.clear(); petsInfoMap.clear(); @@ -638,13 +653,17 @@ public class ProfileViewer { JsonElement crafted_generators_element = Utils.getElement(profileInfo, "crafted_generators"); JsonElement collectionInfoElement = Utils.getElement(profileInfo, "collection"); + if(unlocked_coll_tiers_element == null || crafted_generators_element == null || collectionInfoElement == null) { + return null; + } + JsonObject collectionInfo = new JsonObject(); JsonObject collectionTiers = new JsonObject(); JsonObject minionTiers = new JsonObject(); JsonObject personalAmounts = new JsonObject(); JsonObject totalAmounts = new JsonObject(); - if(collectionInfoElement != null && collectionInfoElement.isJsonObject()) { + if(collectionInfoElement.isJsonObject()) { personalAmounts = collectionInfoElement.getAsJsonObject(); } @@ -747,25 +766,28 @@ public class ProfileViewer { } public PlayerStats.Stats getPassiveStats(String profileId) { - if(passiveStats != null) return passiveStats; + if(passiveStats.get(profileId) != null) return passiveStats.get(profileId); JsonObject profileInfo = getProfileInformation(profileId); if(profileInfo == null) return null; - passiveStats = PlayerStats.getPassiveBonuses(getSkillInfo(profileId), profileInfo); + PlayerStats.Stats passiveStats = PlayerStats.getPassiveBonuses(getSkillInfo(profileId), profileInfo); if(passiveStats != null) { passiveStats.add(PlayerStats.getBaseStats()); } + this.passiveStats.put(profileId, passiveStats); + return passiveStats; } public PlayerStats.Stats getStats(String profileId) { - if(stats != null) return stats; + if(stats.get(profileId) != null) return stats.get(profileId); JsonObject profileInfo = getProfileInformation(profileId); if(profileInfo == null) return null; - stats = PlayerStats.getStats(getSkillInfo(profileId), getInventoryInfo(profileId), getCollectionInfo(profileId), profileInfo); + PlayerStats.Stats stats = PlayerStats.getStats(getSkillInfo(profileId), getInventoryInfo(profileId), getCollectionInfo(profileId), profileInfo); + this.stats.put(profileId, stats); return stats; } @@ -788,12 +810,14 @@ public class ProfileViewer { args.put("name", ""+name); manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "player", args, jsonObject -> { - if(jsonObject == null) return; - - if(jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { + if(jsonObject != null && jsonObject.has("success") && jsonObject.get("success").getAsBoolean() + && jsonObject.get("player").isJsonObject()) { nameToHypixelProfile.put(name, jsonObject.get("player").getAsJsonObject()); uuidToHypixelProfile.put(jsonObject.get("player").getAsJsonObject().get("uuid").getAsString(), jsonObject.get("player").getAsJsonObject()); if(callback != null) callback.accept(jsonObject); + } else { + if(callback != null) callback.accept(null); + return; } } ); @@ -806,7 +830,12 @@ public class ProfileViewer { return profile; } else { getHypixelProfile(name, jsonObject -> { - callback.accept(getProfileReset(jsonObject.get("player").getAsJsonObject().get("uuid").getAsString(), ignored -> {})); + if(jsonObject == null) { + callback.accept(null); + } else { + callback.accept(getProfileReset(jsonObject.get("player").getAsJsonObject().get("uuid").getAsString(), ignored -> {})); + } + }); } return null; diff --git a/src/main/resources/assets/notenoughupdates/pv_dropdown.png b/src/main/resources/assets/notenoughupdates/pv_dropdown.png new file mode 100644 index 00000000..af847f27 Binary files /dev/null and b/src/main/resources/assets/notenoughupdates/pv_dropdown.png differ -- cgit From 9716e11a253a370e16dd1f0bdfdd70ac21ee4102 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Tue, 28 Jul 2020 10:35:58 +1000 Subject: 1.11.10 --- build.gradle | 2 +- .../moulberry/notenoughupdates/NEUManager.java | 48 ++- .../notenoughupdates/NotEnoughUpdates.java | 20 +- .../moulberry/notenoughupdates/SBAIntegration.java | 196 +++++++++++ .../notenoughupdates/auction/APIManager.java | 2 +- .../notenoughupdates/options/Options.java | 3 +- .../profileviewer/GuiProfileViewer.java | 373 ++++++++++++++++----- .../notenoughupdates/profileviewer/Panorama.java | 5 +- .../profileviewer/PlayerStats.java | 1 - .../profileviewer/ProfileViewer.java | 14 +- .../assets/notenoughupdates/pv_elements.png | Bin 831 -> 2567 bytes .../assets/notenoughupdates/wkhtmltox.zip | Bin 31902481 -> 16009138 bytes 12 files changed, 560 insertions(+), 104 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java (limited to 'build.gradle') diff --git a/build.gradle b/build.gradle index 4c2aafb1..e25cc9c9 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ apply plugin: 'com.github.johnrengelman.shadow' sourceCompatibility = 1.8 targetCompatibility = 1.8 -version = "1.11.8" +version = "1.11.10" group= "io.github.moulberry" archivesBaseName = "NotEnoughUpdates" String modid = "notenoughupdates" diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index f78c7e96..ffd57b41 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -921,8 +921,14 @@ public class NEUManager { if(tag != null && tag.hasKey("ExtraAttributes", 10)) { NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - if (ea.hasKey("new_year_cake_bag_data", 7)) { - byte[] bytes = ea.getByteArray("new_year_cake_bag_data"); + byte[] bytes = null; + for(String key : ea.getKeySet()) { + if(key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { + bytes = ea.getByteArray(key); + break; + } + } + if(bytes != null) { JsonArray bytesArr = new JsonArray(); for(byte b : bytes) { bytesArr.add(new JsonPrimitive(b)); @@ -1384,6 +1390,10 @@ public class NEUManager { JsonObject petInfo = petnums.get(petname).getAsJsonObject(); if(petInfo.has(tier)) { JsonObject petInfoTier = petInfo.get(tier).getAsJsonObject(); + if(petInfoTier == null || !petInfoTier.has("1") || !petInfoTier.has("100")) { + return replacements; + } + JsonObject min = petInfoTier.get("1").getAsJsonObject(); JsonObject max = petInfoTier.get("100").getAsJsonObject(); @@ -1402,7 +1412,23 @@ public class NEUManager { replacements.put(entry.getKey(), statStr); } } else { + float minMix = (100-level)/99f; + float maxMix = (level-1)/99f; + + JsonArray otherNumsMin = min.get("otherNums").getAsJsonArray(); + JsonArray otherNumsMax = max.get("otherNums").getAsJsonArray(); + for(int i=0; i entry : max.get("statNums").getAsJsonObject().entrySet()) { + float statMax = entry.getValue().getAsFloat(); + float statMin = min.get("statNums").getAsJsonObject().get(entry.getKey()).getAsFloat(); + float val = statMin*minMix + statMax*maxMix; + String statStr = "+"+(int)Math.floor(val); + replacements.put(entry.getKey(), statStr); + } } } } @@ -1461,6 +1487,10 @@ public class NEUManager { } public ItemStack jsonToStack(JsonObject json, boolean useCache) { + return jsonToStack(json, useCache, true); + } + + public ItemStack jsonToStack(JsonObject json, boolean useCache, boolean useReplacements) { if(useCache && itemstackCache.containsKey(json.get("internalname").getAsString())) { return itemstackCache.get(json.get("internalname").getAsString()).copy(); } @@ -1487,13 +1517,17 @@ public class NEUManager { } } - HashMap replacements = getLoreReplacements(stack.getTagCompound(), -1); + HashMap replacements = new HashMap<>(); + + if(useReplacements) { + replacements = getLoreReplacements(stack.getTagCompound(), -1); - String displayname = json.get("displayname").getAsString(); - for(Map.Entry entry : replacements.entrySet()) { - displayname = displayname.replace("{"+entry.getKey()+"}", entry.getValue()); + String displayname = json.get("displayname").getAsString(); + for(Map.Entry entry : replacements.entrySet()) { + displayname = displayname.replace("{"+entry.getKey()+"}", entry.getValue()); + } + stack.setStackDisplayName(displayname); } - stack.setStackDisplayName(displayname); if(json.has("lore")) { NBTTagCompound display = new NBTTagCompound(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 169b6b9f..f5475123 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -29,6 +29,7 @@ import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.shader.Framebuffer; import net.minecraft.client.shader.Shader; import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.event.ClickEvent; import net.minecraft.init.Blocks; import net.minecraft.inventory.ContainerChest; @@ -167,13 +168,17 @@ public class NotEnoughUpdates { }, new SimpleCommand.TabCompleteRunnable() { @Override public List tabComplete(ICommandSender sender, String[] args, BlockPos pos) { - /*if(args.length) { - - }*/ - for(String arg : args) { - System.out.println(arg); + if(args.length != 1) return null; + + String lastArg = args[args.length-1]; + List playerMatches = new ArrayList<>(); + for(EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { + String playerName = player.getName(); + if(playerName.toLowerCase().startsWith(lastArg.toLowerCase())) { + playerMatches.add(playerName); + } } - return null; + return playerMatches; } }); @@ -705,7 +710,8 @@ public class NotEnoughUpdates { missingRecipe.set(true); } //System.out.println(e.message); - if(isOnSkyblock() && manager.config.streamerMode.value && e.message instanceof ChatComponentText) { + if(unformatted.startsWith("Sending to server") && + isOnSkyblock() && manager.config.streamerMode.value && e.message instanceof ChatComponentText) { String m = e.message.getFormattedText(); String m2 = StreamerMode.filterChat(e.message.getFormattedText()); if(!m.equals(m2)) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java b/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java new file mode 100644 index 00000000..502792df --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java @@ -0,0 +1,196 @@ +package io.github.moulberry.notenoughupdates; + +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.item.ItemStack; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.List; + +public class SBAIntegration { + + private static boolean hasSBA = true; + private static Class skyblockAddonsClass = null; + private static Method skyblockAddons_getInstance = null; + private static Method skyblockAddons_getUtils = null; + private static Class backpackManagerClass = null; + private static Method backpackManager_getFromItem = null; + private static Class backpackClass = null; + private static Method backpackClass_setX= null; + private static Method backpackClass_setY = null; + private static Class utilsClass = null; + private static Method utils_setBackpackToPreview = null; + public static boolean setActiveBackpack(ItemStack stack, int mouseX, int mouseY) { + if(!hasSBA) return false; + try { + if(skyblockAddonsClass == null) { + skyblockAddonsClass = Class.forName("codes.biscuit.skyblockaddons.SkyblockAddons"); + } + if(skyblockAddons_getInstance == null) { + skyblockAddons_getInstance = skyblockAddonsClass.getDeclaredMethod("getInstance"); + } + if(skyblockAddons_getUtils == null) { + skyblockAddons_getUtils = skyblockAddonsClass.getDeclaredMethod("getUtils"); + } + if(backpackManagerClass == null) { + backpackManagerClass = Class.forName("codes.biscuit.skyblockaddons.utils.BackpackManager"); + } + if(backpackManager_getFromItem == null) { + backpackManager_getFromItem = backpackManagerClass.getDeclaredMethod("getFromItem", ItemStack.class); + } + if(backpackClass == null) { + backpackClass = Class.forName("codes.biscuit.skyblockaddons.utils.Backpack"); + } + if(backpackClass_setX == null) { + backpackClass_setX = backpackClass.getDeclaredMethod("setX", int.class); + } + if(backpackClass_setY == null) { + backpackClass_setY = backpackClass.getDeclaredMethod("setY", int.class); + } + if(utilsClass == null) { + utilsClass = Class.forName("codes.biscuit.skyblockaddons.utils.Utils"); + } + if(utils_setBackpackToPreview == null) { + utils_setBackpackToPreview = utilsClass.getDeclaredMethod("setBackpackToPreview", backpackClass); + } + } catch(Exception e) { + e.printStackTrace(); + hasSBA = false; + return false; + } + try { + Object skyblockAddons = skyblockAddons_getInstance.invoke(null); + Object utils = skyblockAddons_getUtils.invoke(skyblockAddons); + if(stack == null) { + utils_setBackpackToPreview.invoke(utils, (Object) null); + } else { + Object backpack = backpackManager_getFromItem.invoke(null, stack); + backpackClass_setX.invoke(backpack, mouseX); + backpackClass_setY.invoke(backpack, mouseY); + utils_setBackpackToPreview.invoke(utils, backpack); + } + } catch(Exception e) { return false; } + return true; + } + + private static Field guiContainerHook_freezeBackpack = null; + public static boolean isFreezeBackpack() { + if(!hasSBA) return false; + try { + if(guiContainerHookClass == null) { + guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); + } + if(guiContainerHook_freezeBackpack == null) { + guiContainerHook_freezeBackpack = guiContainerHookClass.getDeclaredField("freezeBackpack"); + guiContainerHook_freezeBackpack.setAccessible(true); + } + } catch(Exception e) { + e.printStackTrace(); + hasSBA = false; + return false; + } + try { + return (boolean) guiContainerHook_freezeBackpack.get(null); + } catch(Exception e) { + return false; + } + } + + public static boolean setFreezeBackpack(boolean freezeBackpack) { + if(!hasSBA) return false; + try { + if(guiContainerHookClass == null) { + guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); + } + if(guiContainerHook_freezeBackpack == null) { + guiContainerHook_freezeBackpack = guiContainerHookClass.getDeclaredField("freezeBackpack"); + guiContainerHook_freezeBackpack.setAccessible(true); + } + } catch(Exception e) { + e.printStackTrace(); + hasSBA = false; + return false; + } + try { + guiContainerHook_freezeBackpack.set(null, freezeBackpack); + return true; + } catch(Exception e) { + return false; + } + } + + private static Method guiContainerHook_keyTyped = null; + private static Method skyblockAddons_getFreezeBackpackKey = null; + public static boolean keyTyped(int keyCode) { + if(!hasSBA) return false; + try { + if(skyblockAddonsClass == null) { + skyblockAddonsClass = Class.forName("codes.biscuit.skyblockaddons.SkyblockAddons"); + } + if(skyblockAddons_getInstance == null) { + skyblockAddons_getInstance = skyblockAddonsClass.getDeclaredMethod("getInstance"); + } + if(skyblockAddons_getFreezeBackpackKey == null) { + skyblockAddons_getFreezeBackpackKey = skyblockAddonsClass.getDeclaredMethod("getFreezeBackpackKey"); + } + if(guiContainerHookClass == null) { + guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); + } + if(guiContainerHook_keyTyped == null) { + guiContainerHook_keyTyped = guiContainerHookClass.getDeclaredMethod("keyTyped", int.class); + } + } catch(Exception e) { + e.printStackTrace(); + hasSBA = false; + return false; + } + try { + Object skyblockAddons = skyblockAddons_getInstance.invoke(null); + if(!isFreezeBackpack() && ((KeyBinding)skyblockAddons_getFreezeBackpackKey.invoke(skyblockAddons)).getKeyCode() == keyCode) { + setFreezeBackpack(true); + } else { + guiContainerHook_keyTyped.invoke(null, keyCode); + } + } catch(Exception e) { return false; } + return true; + } + + private static Class guiContainerHookClass = null; + private static Method guiContainerHook_drawBackpacks = null; + public static boolean renderActiveBackpack(int mouseX, int mouseY, FontRenderer fontRendererObj) { + if(!hasSBA) return false; + try { + if(guiContainerHookClass == null) { + guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); + } + if(guiContainerHook_drawBackpacks == null) { + guiContainerHook_drawBackpacks = guiContainerHookClass.getDeclaredMethod("drawBackpacks", + GuiContainer.class, int.class, int.class, FontRenderer.class); + } + } catch(Exception e) { + e.printStackTrace(); + hasSBA = false; + return false; + } + try { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + + GuiContainer container = new GuiContainer(null) { + protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + } + }; + container.setWorldAndResolution(Minecraft.getMinecraft(), width, height); + + guiContainerHook_drawBackpacks.invoke(null, container, mouseX, mouseY, fontRendererObj); + } catch(Exception e) { return false; } + return true; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java index 72baf3a7..07c21304 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -515,7 +515,7 @@ public class APIManager { if(itemType >= 0 && itemType < categoryItemType.length) { category = categoryItemType[itemType]; } - if(internalname.equals("ENCHANTED_BOOK")) category = "ebook"; + if(internalname.contains("ENCHANTED_BOOK")) category = "ebook"; if(extras.endsWith("Potion")) category = "potion"; if(extras.contains("Rune")) category = "rune"; if(item_lore.split("\n")[0].endsWith("Furniture")) category = "furniture"; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java b/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java index 8cd82568..0de6cafc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java @@ -279,6 +279,8 @@ public class Options { public List