diff options
Diffstat (limited to 'src/main')
5 files changed, 133 insertions, 41 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index e5a09f2c..440106bc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -1209,40 +1209,6 @@ public class NEUOverlay extends Gui { updateSearch(); } - public static String[] rarityArr = new String[]{ - EnumChatFormatting.WHITE + EnumChatFormatting.BOLD.toString() + "COMMON", - EnumChatFormatting.GREEN + EnumChatFormatting.BOLD.toString() + "UNCOMMON", - EnumChatFormatting.BLUE + EnumChatFormatting.BOLD.toString() + "RARE", - EnumChatFormatting.DARK_PURPLE + EnumChatFormatting.BOLD.toString() + "EPIC", - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD.toString() + "LEGENDARY", - EnumChatFormatting.LIGHT_PURPLE + EnumChatFormatting.BOLD.toString() + "MYTHIC", - EnumChatFormatting.RED + EnumChatFormatting.BOLD.toString() + "SPECIAL", - }; - - /** - * Finds the rarity from the lore of an item. - * -1 = UNKNOWN - * 0 = COMMON - * 1 = UNCOMMON - * 2 = RARE - * 3 = EPIC - * 4 = LEGENDARY - * 5 = MYTHIC - * 6 = SPECIAL - */ - public static int getRarity(JsonArray lore) { - for (int i = lore.size() - 1; i >= 0; i--) { - String line = lore.get(i).getAsString(); - - for (int j = 0; j < rarityArr.length; j++) { - if (line.startsWith(rarityArr[j])) { - return j; - } - } - } - return -1; - } - /** * Convenience functions that get various compare/sort modes from the config. */ @@ -1283,8 +1249,8 @@ public class NEUOverlay extends Gui { int mult = getCompareAscending().get(getCompareMode()) ? 1 : -1; if (getCompareMode() == COMPARE_MODE_RARITY) { - int rarity1 = getRarity(o1.get("lore").getAsJsonArray()); - int rarity2 = getRarity(o2.get("lore").getAsJsonArray()); + int rarity1 = Utils.getRarityFromLore(o1.get("lore").getAsJsonArray()); + int rarity2 = Utils.getRarityFromLore(o2.get("lore").getAsJsonArray()); if (rarity1 < rarity2) return mult; if (rarity1 > rarity2) return -mult; @@ -1338,7 +1304,7 @@ public class NEUOverlay extends Gui { for (int i = lore.size() - 1; i >= 0; i--) { String line = lore.get(i).getAsString(); - for (String rarity : rarityArr) { + for (String rarity : Utils.rarityArrC) { for (int j = 0; j < typeMatches.length; j++) { if (line.trim().equals(rarity + " " + typeMatches[j])) { return j; 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 e910a802..fa20b48a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -879,7 +879,7 @@ public class PetInfoOverlay extends TextOverlay { return; } - int rarity = NEUOverlay.getRarity(jsonStack.get("lore").getAsJsonArray()); + int rarity = Utils.getRarityFromLore(jsonStack.get("lore").getAsJsonArray()); String rarityString = Utils.getRarityFromInt(rarity); String name = StringUtils.cleanColour(petStack.getDisplayName()); 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 af56ec1f..90ad36c0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -701,7 +701,7 @@ public class GuiProfileViewer extends GuiScreen { drawExtraPage(mouseX, mouseY, partialTicks); break; case INVENTORIES: - drawInvsPage(mouseX, mouseY, partialTicks); + drawInvsPage(mouseX, mouseY); break; case COLLECTIONS: drawColsPage(mouseX, mouseY, partialTicks); @@ -1099,7 +1099,7 @@ public class GuiProfileViewer extends GuiScreen { keyTypedDung(typedChar, keyCode); break; } - if (playerNameTextField.getFocus() && !(currentPage == ProfileViewerPage.LOADING)) { + if (playerNameTextField.getFocus()) { if (keyCode == Keyboard.KEY_RETURN) { currentPage = ProfileViewerPage.LOADING; NotEnoughUpdates.profileViewer.getProfileByName(playerNameTextField.getText(), profile -> { //todo: invalid name @@ -1202,6 +1202,8 @@ public class GuiProfileViewer extends GuiScreen { case Keyboard.KEY_NUMPAD8: selectedInventory = "potion_bag"; break; + default: + return; } Utils.playPressSound(); @@ -2871,7 +2873,7 @@ public class GuiProfileViewer extends GuiScreen { return inventories; } - private void drawInvsPage(int mouseX, int mouseY, float partialTicks) { + private void drawInvsPage(int mouseX, int mouseY) { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_invs); Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); inventoryTextField.setSize(88, 20); @@ -2905,6 +2907,19 @@ public class GuiProfileViewer extends GuiScreen { if (mouseX >= guiLeft + x && mouseX <= guiLeft + x + 16) { if (mouseY >= guiTop + y && mouseY <= guiTop + y + 16) { tooltipToDisplay = entry.getValue().getTooltip(Minecraft.getMinecraft().thePlayer, false); + if (Objects.equals(entry.getKey(), "talisman_bag")) { + StringBuilder magicalPowerString = new StringBuilder(EnumChatFormatting.DARK_GRAY + "Magical Power: "); + int magicalPower = PlayerStats.getMagicalPower(inventoryInfo); + tooltipToDisplay.add(magicalPower == -1 + ? magicalPowerString.append(EnumChatFormatting.RED).append("Error while calculating!").toString() + : magicalPowerString.append(EnumChatFormatting.GOLD).append(Utils.formatNumberWithDots(magicalPower)).toString()); + + StringBuilder selectedPowerString = new StringBuilder(EnumChatFormatting.DARK_GRAY + "Selected Power: "); + String selectedPower = PlayerStats.getSelectedMagicalPower(profile.getProfileInformation(profileId)); + tooltipToDisplay.add(selectedPower == null + ? selectedPowerString.append(EnumChatFormatting.RED).append("None!").toString() + : selectedPowerString.append(EnumChatFormatting.GREEN).append(selectedPower).toString()); + } } } 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 4865830c..8d24a082 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java @@ -27,10 +27,13 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTException; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.Nullable; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -710,4 +713,87 @@ public class PlayerStats { return stats; } + + /** + * Calculates the amount of Magical Power the player has using the list of accessories + * + * @param inventoryInfo inventory info object + * @return the amount of Magical Power or -1 + * @see io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer.Profile#getInventoryInfo(String) + */ + public static int getMagicalPower(JsonObject inventoryInfo) { + if (inventoryInfo == null || !inventoryInfo.has("talisman_bag") || + !inventoryInfo.get("talisman_bag").isJsonArray()) { + return -1; + } + JsonArray accessories = inventoryInfo.get("talisman_bag").getAsJsonArray(); + int powderAmount = 0; + for (JsonElement element : accessories) { + if (element == null || !element.isJsonObject()) { + continue; + } + JsonObject accessory = element.getAsJsonObject(); + NBTTagCompound tag; + try { + tag = JsonToNBT.getTagFromJson(accessory.get("nbttag").getAsString()); + } catch (NBTException ignored) { + continue; + } + + NBTTagList loreTagList = tag.getCompoundTag("display").getTagList("Lore", 8); + String lastElement = loreTagList.getStringTagAt(loreTagList.tagCount() - 1); + + //strip information that suggests the rarity has been upgraded (obfuscated char) + if (lastElement.contains("§k")) { + lastElement = lastElement.substring(lastElement.indexOf(' ')).trim().substring(4); + } + + JsonArray lastElementJsonArray = new JsonArray(); + lastElementJsonArray.add(new JsonPrimitive(lastElement)); + switch (Utils.getRarityFromLore(lastElementJsonArray)) { + case 0: + case 6: + powderAmount += 3; + break; + case 1: + case 7: + powderAmount += 5; + break; + case 2: + powderAmount += 8; + break; + case 3: + powderAmount += 12; + break; + case 4: + powderAmount += 16; + break; + case 5: + powderAmount += 22; + break; + } + + } + return powderAmount; + } + + /** + * Finds the Magical Power the player selected if applicable + * + * @param profileInfo profile information object + * @return selected magical power as a String or null + * @see io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer.Profile#getProfileInformation(String) + */ + public static @Nullable String getSelectedMagicalPower(JsonObject profileInfo) { + String abs = "accessory_bag_storage"; + + if (profileInfo == null + || !profileInfo.has(abs) + || !profileInfo.get(abs).isJsonObject() + || !profileInfo.get(abs).getAsJsonObject().has("selected_power")) { + return null; + } + String selectedPower = profileInfo.get(abs).getAsJsonObject().get("selected_power").getAsString(); + return selectedPower.substring(0, 1).toUpperCase() + selectedPower.substring(1); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index ce0ecc4a..3745d72e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -1947,4 +1947,29 @@ public class Utils { true, true ); } + + /** + * Finds the rarity from the lore of an item. + * -1 = UNKNOWN + * 0 = COMMON + * 1 = UNCOMMON + * 2 = RARE + * 3 = EPIC + * 4 = LEGENDARY + * 5 = MYTHIC + * 6 = SPECIAL + * 7 = VERY SPECIAL + */ + public static int getRarityFromLore(JsonArray lore) { + for (int i = lore.size() - 1; i >= 0; i--) { + String line = lore.get(i).getAsString(); + + for (int j = 0; j < rarityArrC.length; j++) { + if (line.startsWith(rarityArrC[j])) { + return j; + } + } + } + return -1; + } } |