From f518f70869961dc32112e6a7ef6192e6a8ca4db7 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 7 Sep 2022 09:30:30 +0200 Subject: todo and forge with tab (#255) --- .../listener/NEUEventListener.java | 16 ++++++-- .../options/seperateSections/Mining.java | 10 +++++ .../options/seperateSections/MiscOverlays.java | 9 +++++ .../notenoughupdates/overlays/MiningOverlay.java | 17 +++++--- .../notenoughupdates/overlays/TextTabOverlay.java | 47 ++++++++++++++++++++++ .../notenoughupdates/overlays/TimersOverlay.java | 9 ++++- 6 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/overlays/TextTabOverlay.java (limited to 'src/main') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java index 041da446..305135fc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java @@ -19,7 +19,6 @@ package io.github.moulberry.notenoughupdates.listener; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; @@ -38,6 +37,7 @@ import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant; import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.overlays.TextOverlay; +import io.github.moulberry.notenoughupdates.overlays.TextTabOverlay; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.NotificationHandler; import io.github.moulberry.notenoughupdates.util.ProfileApiSyncer; @@ -45,7 +45,6 @@ import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.XPInformation; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.event.ClickEvent; import net.minecraft.init.Items; @@ -58,9 +57,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.lwjgl.input.Keyboard; -import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -149,6 +146,17 @@ public class NEUEventListener { } } + //MiningOverlay and TimersOverlay need real tick speed + if (neu.hasSkyblockScoreboard()) { + for (TextOverlay overlay : OverlayManager.textOverlays) { + if (overlay instanceof TextTabOverlay) { + TextTabOverlay skillOverlay = (TextTabOverlay) overlay; + skillOverlay.realTick(); + } + } + } + + if (longUpdate) { CrystalOverlay.tick(); FairySouls.getInstance().tick(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java index 2f31261d..727ad329 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java @@ -207,6 +207,16 @@ public class Mining { @ConfigAccordionId(id = 2) public int forgeDisplayEnabledLocations = 0; + @Expose + @ConfigOption( + name = "Forge Tab", + desc = "Only show the forge display when tab list is open\n" + + "\u00A7cThis only works outside of Dwarven Caves!" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 2) + public boolean forgeDisplayOnlyShowTab = false; + @ConfigOption( name = "Metal Detector Solver", desc = "" diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/MiscOverlays.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/MiscOverlays.java index d2bfdbd9..18b89733 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/MiscOverlays.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/MiscOverlays.java @@ -50,6 +50,15 @@ public class MiscOverlays { @ConfigAccordionId(id = 0) public boolean todoOverlay2 = false; + @Expose + @ConfigOption( + name = "Todo Overlay Tab", + desc = "Only show the todo overlay when tab list is open" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean todoOverlayOnlyShowTab = false; + @Expose @ConfigOption( name = "Todo Text", diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java index 5dda0d85..d24f005d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java @@ -43,6 +43,7 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.WorldSettings; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import org.lwjgl.input.Keyboard; import org.lwjgl.util.vector.Vector2f; import java.util.ArrayList; @@ -64,7 +65,7 @@ import static net.minecraft.util.EnumChatFormatting.RED; import static net.minecraft.util.EnumChatFormatting.RESET; import static net.minecraft.util.EnumChatFormatting.YELLOW; -public class MiningOverlay extends TextOverlay { +public class MiningOverlay extends TextTabOverlay { public MiningOverlay( Position position, Supplier> dummyStrings, @@ -440,11 +441,15 @@ public class MiningOverlay extends TextOverlay { } if (forgeDisplay) { overlayStrings = new ArrayList<>(); - if (NotEnoughUpdates.INSTANCE.config.mining.forgeDisplayEnabledLocations == 1 && - !SBInfo.getInstance().isInDungeon) { - overlayStrings.addAll(getForgeStrings(profileConfig.forgeItems)); - } else if (NotEnoughUpdates.INSTANCE.config.mining.forgeDisplayEnabledLocations == 2) { - overlayStrings.addAll(getForgeStrings(profileConfig.forgeItems)); + + if (!NotEnoughUpdates.INSTANCE.config.mining.forgeDisplayOnlyShowTab || + Keyboard.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindPlayerList.getKeyCode())) { + if (NotEnoughUpdates.INSTANCE.config.mining.forgeDisplayEnabledLocations == 1 && + !SBInfo.getInstance().isInDungeon) { + overlayStrings.addAll(getForgeStrings(profileConfig.forgeItems)); + } else if (NotEnoughUpdates.INSTANCE.config.mining.forgeDisplayEnabledLocations == 2) { + overlayStrings.addAll(getForgeStrings(profileConfig.forgeItems)); + } } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextTabOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextTabOverlay.java new file mode 100644 index 00000000..69a0cd00 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextTabOverlay.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.overlays; + +import io.github.moulberry.notenoughupdates.core.config.Position; +import net.minecraft.client.Minecraft; +import org.lwjgl.input.Keyboard; + +import java.util.List; +import java.util.function.Supplier; + +public abstract class TextTabOverlay extends TextOverlay { + public TextTabOverlay( + Position position, + Supplier> dummyStrings, + Supplier styleSupplier + ) { + super(position, dummyStrings, styleSupplier); + } + + private boolean lastTabState = false; + + public void realTick() { + boolean currentTabState = Keyboard.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindPlayerList.getKeyCode()); + if (lastTabState != currentTabState) { + lastTabState = currentTabState; + update(); + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java index d5d8afd7..86df47ff 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java @@ -37,6 +37,7 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.lwjgl.input.Keyboard; import org.lwjgl.util.vector.Vector2f; import java.time.ZoneId; @@ -50,7 +51,7 @@ import java.util.regex.Pattern; import static net.minecraft.util.EnumChatFormatting.DARK_AQUA; -public class TimersOverlay extends TextOverlay { +public class TimersOverlay extends TextTabOverlay { private static final Pattern PATTERN_ACTIVE_EFFECTS = Pattern.compile( "\u00a7r\u00a7r\u00a77You have a \u00a7r\u00a7cGod Potion \u00a7r\u00a77active! \u00a7r\u00a7d([0-9]*?:?[0-9]*?:?[0-9]*)\u00a7r"); @@ -234,6 +235,12 @@ public class TimersOverlay extends TextOverlay { NEUConfig.HiddenProfileSpecific hidden = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); if (hidden == null) return; + if (NotEnoughUpdates.INSTANCE.config.miscOverlays.todoOverlayOnlyShowTab && + !Keyboard.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindPlayerList.getKeyCode())) { + overlayStrings = null; + return; + } + if (Minecraft.getMinecraft().currentScreen instanceof GuiChest) { GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; ContainerChest container = (ContainerChest) chest.inventorySlots; -- cgit From 1695ef38badc02ed6b5abae2d7bb6175e62855bc Mon Sep 17 00:00:00 2001 From: efefury <69400149+efefury@users.noreply.github.com> Date: Wed, 7 Sep 2022 12:00:36 +0000 Subject: neuitemedtior revert (#259) --- .../notenoughupdates/itemeditor/NEUItemEditor.java | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'src/main') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java index 9dc8d8b0..6a080ff8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java @@ -93,19 +93,6 @@ public class NEUItemEditor extends GuiScreen { extraAttributes.removeTag("uuid"); extraAttributes.removeTag("timestamp"); - if (extraAttributes.hasKey("petInfo")) { - try { - NBTTagCompound petInfo = JsonToNBT.getTagFromJson(extraAttributes.getString("petInfo")); - - petInfo.removeTag("\"heldItem\""); - petInfo.setString("\"exp\"", "0.0"); - petInfo.setString("\"candyUsed\"", "0"); - petInfo.removeTag("\"uuid\""); - - extraAttributes.setString("petInfo", petInfo.toString()); - } catch (NBTException ignored) { - } - } savedRepoItem = NotEnoughUpdates.INSTANCE.manager.getItemInformation().getOrDefault(internalName, null); internalName = internalName == null ? "" : internalName; -- cgit From c671d5c03fb5d0410645d8b6edc56adeda3d94a7 Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Thu, 8 Sep 2022 14:12:03 +0200 Subject: Add item ids to Books in more places (#256) * Add item ids to Books in more places Add item ids to Enchanted Books in the Bazaar and in the Experimentation Table. Add ItemResolutionQuery as a new way to query items and item ids. Co-authored-by: romangraef * Update 2.1.md * Infer found a bug that already existed before. * add support for animated crab hats Co-authored-by: hannibal00212 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: nopo --- Update Notes/2.1.md | 1 + .../moulberry/notenoughupdates/NEUManager.java | 108 +++------- .../notenoughupdates/auction/APIManager.java | 1 + .../notenoughupdates/core/util/StringUtils.java | 8 + .../listener/ItemTooltipListener.java | 31 +-- .../miscfeatures/EnchantingSolvers.java | 4 +- .../notenoughupdates/util/ItemResolutionQuery.java | 239 +++++++++++++++++++++ .../moulberry/notenoughupdates/util/ItemUtils.java | 14 +- 8 files changed, 312 insertions(+), 94 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java (limited to 'src/main') diff --git a/Update Notes/2.1.md b/Update Notes/2.1.md index 90ebbf87..b5853248 100644 --- a/Update Notes/2.1.md +++ b/Update Notes/2.1.md @@ -109,6 +109,7 @@ - Added blur limit to map at 100 - nopo - Added bazaar sacks profit feature - hannibal2 - Added an option to disable etherwarp overlay when TP is denied - hannibal2 +- Added bazaar prices to enchants in the enchantment table - hannibal2 / nea89 ### **Bug Fixes:** diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 4e5c5b7d..35385f38 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -36,6 +36,8 @@ import io.github.moulberry.notenoughupdates.recipes.NeuRecipe; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.HotmInformation; import io.github.moulberry.notenoughupdates.util.HypixelApi; +import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery; +import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -679,82 +681,18 @@ public class NEUManager { return null; } + /** + * Replaced with {@link #createItemResolutionQuery()} + */ + @Deprecated public String getInternalnameFromNBT(NBTTagCompound tag) { - String internalname = null; - if (tag != null && tag.hasKey("ExtraAttributes", 10)) { - NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - - if (ea.hasKey("id", 8)) { - internalname = ea.getString("id").replaceAll(":", "-"); - } else { - return null; - } - - if ("PET".equals(internalname)) { - String petInfo = ea.getString("petInfo"); - if (petInfo.length() > 0) { - JsonObject petInfoObject = gson.fromJson(petInfo, JsonObject.class); - internalname = petInfoObject.get("type").getAsString(); - String tier = petInfoObject.get("tier").getAsString(); - switch (tier) { - case "COMMON": - internalname += ";0"; - break; - case "UNCOMMON": - internalname += ";1"; - break; - case "RARE": - internalname += ";2"; - break; - case "EPIC": - internalname += ";3"; - break; - case "LEGENDARY": - internalname += ";4"; - break; - case "MYTHIC": - internalname += ";5"; - break; - } - } - } - if ("ENCHANTED_BOOK".equals(internalname) && ea.hasKey("enchantments", 10)) { - NBTTagCompound enchants = ea.getCompoundTag("enchantments"); - - for (String enchname : enchants.getKeySet()) { - internalname = enchname.toUpperCase() + ";" + enchants.getInteger(enchname); - break; - } - } - if ("RUNE".equals(internalname) && ea.hasKey("runes", 10)) { - NBTTagCompound rune = ea.getCompoundTag("runes"); - - for (String runename : rune.getKeySet()) { - internalname = runename.toUpperCase() + "_RUNE" + ";" + rune.getInteger(runename); - break; - } - } - if ("PARTY_HAT_CRAB".equals(internalname) && (ea.getString("party_hat_color") != null)) { - String crabhat = ea.getString("party_hat_color"); - internalname = "PARTY_HAT_CRAB" + "_" + crabhat.toUpperCase(); - } - } - - return internalname; + return createItemResolutionQuery() + .withItemNBT(tag) + .resolveInternalName(); } public String[] getLoreFromNBT(NBTTagCompound tag) { - String[] lore = new String[0]; - NBTTagCompound display = tag.getCompoundTag("display"); - - if (display.hasKey("Lore", 9)) { - NBTTagList list = display.getTagList("Lore", 8); - lore = new String[list.tagCount()]; - for (int k = 0; k < list.tagCount(); k++) { - lore[k] = list.getStringTagAt(k); - } - } - return lore; + return ItemUtils.getLore(tag).toArray(new String[0]); } public JsonObject getJsonFromNBT(NBTTagCompound tag) { @@ -914,10 +852,18 @@ public class NEUManager { return getSkullValueFromNBT(tag); } + public ItemResolutionQuery createItemResolutionQuery() { + return new ItemResolutionQuery(this); + } + + /** + * Replaced with {@link #createItemResolutionQuery()} + */ + @Deprecated public String getInternalNameForItem(ItemStack stack) { - if (stack == null) return null; - NBTTagCompound tag = stack.getTagCompound(); - return getInternalnameFromNBT(tag); + return createItemResolutionQuery() + .withItemStack(stack) + .resolveInternalName(); } public String getUUIDForItem(ItemStack stack) { @@ -1573,9 +1519,13 @@ public class NEUManager { return comp; } - public ItemStack createItem(String internalname) { - JsonObject jsonObject = itemMap.get(internalname); - if (jsonObject == null) return null; - return jsonToStack(jsonObject); + public ItemStack createItem(String internalName) { + return createItemResolutionQuery() + .withKnownInternalName(internalName) + .resolveToItemStack(); + } + + public boolean isValidInternalName(String internalName) { + return itemMap.containsKey(internalName); } } 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 c3999fb6..74ef2483 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -168,6 +168,7 @@ public class APIManager { return stack; } else { JsonObject item = manager.getJsonFromNBT(item_tag); + if (item == null) return null; ItemStack stack = manager.jsonToStack(item, false); JsonObject itemDefault = manager.getItemInformation().get(item.get("internalname").getAsString()); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java index ecb4cd8b..6143085c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java @@ -74,4 +74,12 @@ public class StringUtils { throw new RuntimeException(e); // UTF 8 should always be present } } + + /** + * taken and modified from https://stackoverflow.com/a/23326014/5507634 + */ + public static String replaceLast(String string, String toReplace, String replacement) { + int start = string.lastIndexOf(toReplace); + return string.substring(0, start) + replacement + string.substring(start + toReplace.length()); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java index f3ed8e7c..e5c3324f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java @@ -28,6 +28,7 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture; import io.github.moulberry.notenoughupdates.ItemPriceInformation; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.MiscUtils; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; import io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; @@ -42,7 +43,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTUtil; import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.StringUtils; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.eventhandler.EventPriority; @@ -104,8 +104,13 @@ public class ItemTooltipListener { public void onItemTooltipLow(ItemTooltipEvent event) { if (!NotEnoughUpdates.INSTANCE.isOnSkyblock()) return; - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(event.itemStack); - if (internalname == null) { + String internalName = NotEnoughUpdates.INSTANCE.manager + .createItemResolutionQuery() + .withCurrentGuiContext() + .withItemStack(event.itemStack) + .resolveInternalName(); + + if (internalName == null) { return; } petToolTipXPExtendPetMenu(event); @@ -155,7 +160,8 @@ public class ItemTooltipListener { for (int j = 0; j < Utils.rarityArrC.length; j++) { for (Map.Entry entry : enchantsObj.entrySet()) { if (line.contains(Utils.rarityArrC[j] + " " + entry.getKey()) || line.contains( - Utils.rarityArrC[j] + " DUNGEON " + entry.getKey()) || line.contains("SHINY " + Utils.rarityArrC[j].replaceAll("§.§.","") + " DUNGEON " + entry.getKey())) { + Utils.rarityArrC[j] + " DUNGEON " + entry.getKey()) || line.contains( + "SHINY " + Utils.rarityArrC[j].replaceAll("§.§.", "") + " DUNGEON " + entry.getKey())) { allItemEnchs = entry.getValue().getAsJsonArray(); break out; } @@ -180,7 +186,7 @@ public class ItemTooltipListener { NotEnoughUpdates.INSTANCE.config.tooltipTweaks.showReforgeStats) { JsonObject reforgeStones = Constants.REFORGESTONES; - if (reforgeStones != null && reforgeStones.has(internalname)) { + if (reforgeStones != null && reforgeStones.has(internalName)) { boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); if (!pressedShiftLast && shift) { showReforgeStoneStats = !showReforgeStoneStats; @@ -195,7 +201,7 @@ public class ItemTooltipListener { newTooltip.add(EnumChatFormatting.DARK_GRAY + "[Press SHIFT to hide extra info]"); } - JsonObject reforgeInfo = reforgeStones.get(internalname).getAsJsonObject(); + JsonObject reforgeInfo = reforgeStones.get(internalName).getAsJsonObject(); JsonArray requiredRaritiesArray = reforgeInfo.get("requiredRarities").getAsJsonArray(); if (showReforgeStoneStats && requiredRaritiesArray.size() > 0) { @@ -526,7 +532,7 @@ public class ItemTooltipListener { newTooltip.add(""); newTooltip.add(EnumChatFormatting.GRAY + "[SHIFT for Price Info]"); } else { - ItemPriceInformation.addToTooltip(newTooltip, internalname, event.itemStack); + ItemPriceInformation.addToTooltip(newTooltip, internalName, event.itemStack); } } } @@ -583,9 +589,10 @@ public class ItemTooltipListener { JsonObject auctionInfo = neu.manager.auctionManager.getItemAuctionInfo(internal); if (auctionInfo != null) { if (auctionInfo.has("clean_price")) { - worth = (long)auctionInfo.get("clean_price").getAsDouble(); + worth = (long) auctionInfo.get("clean_price").getAsDouble(); } else { - worth = (long) (auctionInfo.get("price").getAsDouble() / auctionInfo.get("count").getAsDouble()); + worth = + (long) (auctionInfo.get("price").getAsDouble() / auctionInfo.get("count").getAsDouble()); } } break; @@ -703,7 +710,7 @@ public class ItemTooltipListener { event.toolTip.addAll(newTooltip); if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.showPriceInfoInvItem) { - ItemPriceInformation.addToTooltip(event.toolTip, internalname, event.itemStack); + ItemPriceInformation.addToTooltip(event.toolTip, internalName, event.itemStack); } if (event.itemStack.getTagCompound() != null && event.itemStack.getTagCompound().getBoolean("NEUHIDEPETTOOLTIP") && @@ -824,14 +831,14 @@ public class ItemTooltipListener { if (event.toolTip == null) return; if (event.toolTip.size() > 2 && NotEnoughUpdates.INSTANCE.config.tooltipTweaks.hideDefaultReforgeStats) { - String secondLine = StringUtils.stripControlCodes(event.toolTip.get(1)); + String secondLine = StringUtils.cleanColour(event.toolTip.get(1)); if (secondLine.equals("Reforge Stone")) { Integer startIndex = null; Integer cutoffIndex = null; //loop from the back of the List to find the wanted index sooner for (int i = event.toolTip.size() - 1; i >= 0; i--) { //rarity or mining level requirement - String line = StringUtils.stripControlCodes(event.toolTip.get(i)); + String line = StringUtils.cleanColour(event.toolTip.get(i)); if (line.contains("REFORGE STONE") || line.contains("Requires Mining Skill Level")) { cutoffIndex = i; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java index 6b541256..558917fe 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java @@ -45,9 +45,9 @@ import java.util.List; import java.util.Map; public class EnchantingSolvers { - private static SolverType currentSolver = SolverType.NONE; + public static SolverType currentSolver = SolverType.NONE; - private enum SolverType { + public enum SolverType { NONE, CHRONOMATRON, ULTRASEQUENCER, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java new file mode 100644 index 00000000..1ff659ac --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java @@ -0,0 +1,239 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util; + +import com.google.common.collect.Iterables; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import io.github.moulberry.notenoughupdates.NEUManager; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.init.Items; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ItemResolutionQuery { + + private static final Pattern ENCHANTED_BOOK_NAME_PATTERN = Pattern.compile("^((?:§.)+)([^§]+) ([IVXL]+)$"); + private static final String EXTRA_ATTRIBUTES = "ExtraAttributes"; + private static final List PET_RARITIES = Arrays.asList( + "COMMON", + "UNCOMMON", + "RARE", + "EPIC", + "LEGENDARY", + "MYTHIC" + ); + private final NEUManager manager; + private NBTTagCompound compound; + private Item itemType; + private int stackSize = -1; + private Gui guiContext; + private String knownInternalName; + + public ItemResolutionQuery(NEUManager manager) { + this.manager = manager; + } + + public ItemResolutionQuery withItemNBT(NBTTagCompound compound) { + this.compound = compound; + return this; + } + + public ItemResolutionQuery withItemStack(ItemStack stack) { + if (stack == null) return this; + this.itemType = stack.getItem(); + this.compound = stack.getTagCompound(); + this.stackSize = stack.stackSize; + return this; + } + + public ItemResolutionQuery withGuiContext(Gui gui) { + this.guiContext = gui; + return this; + } + + public ItemResolutionQuery withCurrentGuiContext() { + this.guiContext = Minecraft.getMinecraft().currentScreen; + return this; + } + + public ItemResolutionQuery withKnownInternalName(String knownInternalName) { + this.knownInternalName = knownInternalName; + return this; + } + + @Nullable + public String resolveInternalName() { + if (knownInternalName != null) { + return knownInternalName; + } + String resolvedName = resolveFromSkyblock(); + if (resolvedName == null) { + resolvedName = resolveContextualName(); + } else { + switch (resolvedName.intern()) { + case "PET": + resolvedName = resolvePetName(); + break; + case "RUNE": + resolvedName = resolveRuneName(); + break; + case "ENCHANTED_BOOK": + resolvedName = resolveEnchantedBookNameFromNBT(); + break; + case "PARTY_HAT_CRAB": + case "PARTY_HAT_CRAB_ANIMATED": + resolvedName = resolveCrabHatName(); + break; + } + } + + return resolvedName; + } + + @Nullable + public JsonObject resolveToItemListJson() { + String internalName = resolveInternalName(); + if (internalName == null) { + return null; + } + return manager.getItemInformation().get(internalName); + } + + @Nullable + public ItemStack resolveToItemStack() { + JsonObject jsonObject = resolveToItemListJson(); + if (jsonObject == null) return null; + return manager.jsonToStack(jsonObject); + } + + // + private boolean isBazaar(IInventory chest) { + if (chest.getDisplayName().getFormattedText().startsWith("Bazaar ➜ ")) { + return true; + } + int bazaarSlot = chest.getSizeInventory() - 5; + if (bazaarSlot < 0) return false; + ItemStack stackInSlot = chest.getStackInSlot(bazaarSlot); + if (stackInSlot == null || stackInSlot.stackSize == 0) return false; + // NBT lore, we do not care about rendered lore + List lore = ItemUtils.getLore(stackInSlot); + return lore.contains("§7To Bazaar"); + } + + private String resolveContextualName() { + if (!(guiContext instanceof GuiChest)) { + return null; + } + GuiChest chest = (GuiChest) guiContext; + ContainerChest inventorySlots = (ContainerChest) chest.inventorySlots; + String guiName = inventorySlots.getLowerChestInventory().getDisplayName().getUnformattedText(); + boolean isOnBazaar = isBazaar(inventorySlots.getLowerChestInventory()); + String displayName = ItemUtils.getDisplayName(compound); + if (displayName == null) return null; + if (itemType == Items.enchanted_book && isOnBazaar && compound != null) { + return resolveEnchantmentByName(displayName); + } + if (displayName.endsWith("Enchanted Book") && guiName.startsWith("Superpairs")) { + for (String loreLine : ItemUtils.getLore(compound)) { + String enchantmentIdCandidate = resolveEnchantmentByName(loreLine); + if (enchantmentIdCandidate != null) return enchantmentIdCandidate; + } + return null; + } + return null; + } + + private String resolveEnchantmentByName(String name) { + Matcher matcher = ENCHANTED_BOOK_NAME_PATTERN.matcher(name); + if (!matcher.matches()) return null; + String format = matcher.group(1).toLowerCase(Locale.ROOT); + String enchantmentName = matcher.group(2).trim(); + String romanLevel = matcher.group(3); + boolean ultimate = (format.contains("§l")); + + return (ultimate ? "ULTIMATE_" : "") + + enchantmentName.replace(" ", "_").toUpperCase(Locale.ROOT) + + ";" + Utils.parseRomanNumeral(romanLevel); + } + + private String resolveCrabHatName() { + int crabHatYear = getExtraAttributes().getInteger("party_hat_year"); + String color = getExtraAttributes().getString("party_hat_color"); + return "PARTY_HAT_CRAB_" + color.toUpperCase(Locale.ROOT) + (crabHatYear == 2022 ? "_ANIMATED" : ""); + } + + private String resolveEnchantedBookNameFromNBT() { + NBTTagCompound enchantments = getExtraAttributes().getCompoundTag("enchantments"); + String enchantName = Iterables.getOnlyElement(enchantments.getKeySet(), null); + if (enchantName == null || enchantName.isEmpty()) return null; + return enchantName.toUpperCase(Locale.ROOT) + ";" + enchantments.getInteger(enchantName); + } + + private String resolveRuneName() { + NBTTagCompound runes = getExtraAttributes().getCompoundTag("runes"); + String runeName = Iterables.getOnlyElement(runes.getKeySet(), null); + if (runeName == null || runeName.isEmpty()) return null; + return runeName.toUpperCase(Locale.ROOT) + "_RUNE;" + runes.getInteger(runeName); + } + + private String resolvePetName() { + String petInfo = getExtraAttributes().getString("petInfo"); + if (petInfo == null || petInfo.isEmpty()) return null; + try { + JsonObject petInfoObject = manager.gson.fromJson(petInfo, JsonObject.class); + String petId = petInfoObject.get("type").getAsString(); + String petTier = petInfoObject.get("tier").getAsString(); + int rarityIndex = PET_RARITIES.indexOf(petTier); + return petId.toUpperCase(Locale.ROOT) + ";" + rarityIndex; + } catch (JsonParseException | ClassCastException ex) { + /* This happens if Hypixel changed the pet json format; + I still log this exception, since this case *is* exceptional and cannot easily be recovered from */ + ex.printStackTrace(); + return null; + } + } + + private NBTTagCompound getExtraAttributes() { + if (compound == null) return new NBTTagCompound(); + return compound.getCompoundTag(EXTRA_ATTRIBUTES); + } + + private String resolveFromSkyblock() { + String internalName = getExtraAttributes().getString("id"); + if (internalName == null || internalName.isEmpty()) return null; + return internalName.toUpperCase(Locale.ROOT); + } + + // + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java index 3a2db0fb..cffdd164 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java @@ -73,7 +73,10 @@ public class ItemUtils { } public static List getLore(ItemStack is) { - NBTTagCompound tagCompound = is.getTagCompound(); + return getLore(is.getTagCompound()); + } + + public static List getLore(NBTTagCompound tagCompound) { if (tagCompound == null) { return Collections.emptyList(); } @@ -84,4 +87,13 @@ public class ItemUtils { } return list; } + + public static String getDisplayName(NBTTagCompound compound) { + if (compound == null) return null; + String string = compound.getCompoundTag("display").getString("Name"); + if (string == null || string.isEmpty()) + return null; + return string; + } + } -- cgit From 827acac6fcf836c1dba5bea338f726694951d18e Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 8 Sep 2022 14:23:40 +0200 Subject: double bazaar fun and cleanup stuff (#257) * support for showing bazaar prices smaller than 0 and cleanup in ItemPriceInformation * only showing comma when price < 5 * format changes * change the format for dungeon profit too --- .../notenoughupdates/ItemPriceInformation.java | 91 ++++++++-------------- .../notenoughupdates/listener/RenderListener.java | 28 ++++--- 2 files changed, 48 insertions(+), 71 deletions(-) (limited to 'src/main') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java index b47a7c7f..a773abdc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java @@ -39,6 +39,8 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.HashSet; import java.util.List; @@ -49,6 +51,7 @@ public class ItemPriceInformation { private static File file; private static HashSet auctionableItems = null; private static Gson gson; + private static final NumberFormat format = new DecimalFormat("#,##0.#", new DecimalFormatSymbols(Locale.US)); public static boolean addToTooltip(List tooltip, String internalname, ItemStack stack) { return addToTooltip(tooltip, internalname, stack, true); @@ -103,7 +106,7 @@ public class ItemPriceInformation { JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); double lowestBinAvg = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalname); - long lowestBin = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname); + double lowestBin = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname); APIManager.CraftInfo craftCost = NotEnoughUpdates.INSTANCE.manager.auctionManager.getCraftCost(internalname); boolean bazaarItem = bazaarInfo != null; @@ -119,8 +122,6 @@ public class ItemPriceInformation { } } - NumberFormat format = NumberFormat.getInstance(Locale.US); - boolean shortNumber = NotEnoughUpdates.INSTANCE.config.tooltipTweaks.shortNumberFormatPrices; if (bazaarItem) { List lines = NotEnoughUpdates.INSTANCE.config.tooltipTweaks.priceInfoBaz; @@ -145,11 +146,8 @@ public class ItemPriceInformation { tooltip.add(EnumChatFormatting.DARK_GRAY + "[SHIFT show x" + shiftStackMultiplier + "]"); added = true; } - long bazaarBuyPrice = (long) bazaarInfo.get("avg_buy").getAsFloat() * stackMultiplier; - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Buy: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + (shortNumber && bazaarBuyPrice > 1000 - ? Utils.shortNumberFormat(bazaarBuyPrice, 0) - : format.format(bazaarBuyPrice)) + " coins"); + double bazaarBuyPrice = bazaarInfo.get("avg_buy").getAsFloat() * stackMultiplier; + tooltip.add(formatPrice("Bazaar Buy: ", bazaarBuyPrice)); } break; case 1: @@ -160,11 +158,8 @@ public class ItemPriceInformation { tooltip.add(EnumChatFormatting.DARK_GRAY + "[SHIFT show x" + shiftStackMultiplier + "]"); added = true; } - long bazaarSellPrice = (long) bazaarInfo.get("avg_sell").getAsFloat() * stackMultiplier; - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Sell: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + (shortNumber && bazaarSellPrice > 1000 - ? Utils.shortNumberFormat(bazaarSellPrice, 0) - : format.format(bazaarSellPrice)) + " coins"); + double bazaarSellPrice = bazaarInfo.get("avg_sell").getAsDouble() * stackMultiplier; + tooltip.add(formatPrice("Bazaar Sell: ", bazaarSellPrice)); } break; case 2: @@ -175,12 +170,8 @@ public class ItemPriceInformation { tooltip.add(EnumChatFormatting.DARK_GRAY + "[SHIFT show x" + shiftStackMultiplier + "]"); added = true; } - long bazaarInstantBuyPrice = (long) bazaarInfo.get("curr_buy").getAsFloat() * stackMultiplier; - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Insta-Buy: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + (shortNumber && bazaarInstantBuyPrice > 1000 - ? Utils.shortNumberFormat(bazaarInstantBuyPrice, 0) - : format.format(bazaarInstantBuyPrice)) + - " coins"); + double bazaarInstantBuyPrice = bazaarInfo.get("curr_buy").getAsFloat() * stackMultiplier; + tooltip.add(formatPrice("Bazaar Insta-Buy: ", bazaarInstantBuyPrice)); } break; case 3: @@ -191,20 +182,13 @@ public class ItemPriceInformation { tooltip.add(EnumChatFormatting.DARK_GRAY + "[SHIFT show x" + shiftStackMultiplier + "]"); added = true; } - long bazaarInstantSellPrice = (long) bazaarInfo.get("curr_sell").getAsFloat() * stackMultiplier; - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Insta-Sell: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + (shortNumber && bazaarInstantSellPrice > 1000 - ? Utils.shortNumberFormat( - bazaarInstantSellPrice, - 0 - ) - : format.format(bazaarInstantSellPrice)) + - " coins"); + double bazaarInstantSellPrice = bazaarInfo.get("curr_sell").getAsFloat() * stackMultiplier; + tooltip.add(formatPrice("Bazaar Insta-Sell: ", bazaarInstantSellPrice)); } break; case 4: if (craftCost != null && craftCost.fromRecipe) { - if ((int) craftCost.craftCost == 0) { + if (craftCost.craftCost == 0) { continue; } if (!added) { @@ -213,10 +197,7 @@ public class ItemPriceInformation { } double cost = craftCost.craftCost; if (shiftPressed) cost = cost * shiftStackMultiplier; - - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Raw Craft Cost: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + - (shortNumber && cost > 1000 ? Utils.shortNumberFormat(cost, 0) : format.format((int) cost)) + " coins"); + tooltip.add(formatPrice("Raw Craft Cost: ", cost)); } break; } @@ -236,8 +217,7 @@ public class ItemPriceInformation { tooltip.add(""); added = true; } - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Lowest BIN: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + format.format(lowestBin) + " coins"); + tooltip.add(formatPrice("Lowest BIN: ", lowestBin)); } break; case 1: @@ -248,21 +228,11 @@ public class ItemPriceInformation { } if (auctionInfo.has("clean_price")) { - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "AH Price (Clean): " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + - (shortNumber && auctionInfo.get("clean_price").getAsFloat() > 1000 ? Utils.shortNumberFormat( - auctionInfo.get("clean_price").getAsFloat(), - 0 - ) : format.format((int) auctionInfo.get("clean_price").getAsFloat()) - + " coins")); + double cleanPrice = auctionInfo.get("clean_price").getAsDouble(); + tooltip.add(formatPrice("AH Price (Clean): ", cleanPrice)); } else { - int auctionPrice = - (int) (auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "AH Price: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + - (shortNumber && auctionPrice > 1000 - ? Utils.shortNumberFormat(auctionPrice, 0) - : format.format(auctionPrice)) + " coins"); + double auctionPrice = auctionInfo.get("price").getAsDouble() / auctionInfo.get("count").getAsFloat(); + tooltip.add(formatPrice("AH Price: ", auctionPrice)); } } @@ -292,18 +262,14 @@ public class ItemPriceInformation { break; case 3: if (craftCost != null && craftCost.fromRecipe) { - if ((int) craftCost.craftCost == 0) { + if (craftCost.craftCost == 0) { continue; } if (!added) { tooltip.add(""); added = true; } - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Raw Craft Cost: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + - (shortNumber && craftCost.craftCost > 1000 - ? Utils.shortNumberFormat(craftCost.craftCost, 0) - : format.format((int) craftCost.craftCost)) + " coins"); + tooltip.add(formatPrice("Raw Craft Cost: ", craftCost.craftCost)); } break; case 4: @@ -312,11 +278,7 @@ public class ItemPriceInformation { tooltip.add(""); added = true; } - tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "AVG Lowest BIN: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + - (shortNumber && lowestBinAvg > 1000 - ? Utils.shortNumberFormat(lowestBinAvg, 0) - : format.format(lowestBinAvg)) + " coins"); + tooltip.add(formatPrice("AVG Lowest BIN: ", lowestBinAvg)); } break; case 5: @@ -391,4 +353,13 @@ public class ItemPriceInformation { return false; } + + private static String formatPrice(String label, double price) { + boolean shortNumber = NotEnoughUpdates.INSTANCE.config.tooltipTweaks.shortNumberFormatPrices; + String number = (shortNumber && price > 1000 + ? Utils.shortNumberFormat(price, 0) + : price > 5 ? format.format((int) price) : format.format(price)); + return "§e§l" + label + "§6§l" + number + " coins"; + } + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index 96f15ba1..54b647e9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -106,6 +106,8 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.ArrayList; import java.util.ConcurrentModificationException; @@ -142,6 +144,7 @@ public class RenderListener { private boolean typing; private HashMap cachedDefinitions; private boolean inDungeonPage = false; + private final NumberFormat format = new DecimalFormat("#,##0.#", new DecimalFormatSymbols(Locale.US)); public RenderListener(NotEnoughUpdates neu) { this.neu = neu; @@ -744,7 +747,7 @@ public class RenderListener { } String missingItem = null; - int totalValue = 0; + double totalValue = 0; HashMap itemValues = new HashMap<>(); for (int i = 0; i < 5; i++) { ItemStack item = lower.getStackInSlot(11 + i); @@ -788,9 +791,9 @@ public class RenderListener { JsonObject auctionInfo = neu.manager.auctionManager.getItemAuctionInfo(internal); if (auctionInfo != null) { if (auctionInfo.has("clean_price")) { - worth = (int) auctionInfo.get("clean_price").getAsFloat(); + worth = auctionInfo.get("clean_price").getAsFloat(); } else { - worth = (int) (auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); + worth = (auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); } } } @@ -831,18 +834,17 @@ public class RenderListener { } } - NumberFormat format = NumberFormat.getInstance(Locale.US); String valueStringBIN1; String valueStringBIN2; if (totalValue >= 0) { valueStringBIN1 = EnumChatFormatting.YELLOW + "Value (BIN): "; - valueStringBIN2 = EnumChatFormatting.GOLD + format.format(totalValue) + " coins"; + valueStringBIN2 = EnumChatFormatting.GOLD + formatCoins(totalValue) + " coins"; } else { valueStringBIN1 = EnumChatFormatting.YELLOW + "Can't find BIN: "; valueStringBIN2 = missingItem; } - long profitLossBIN = totalValue - chestCost; + double profitLossBIN = totalValue - chestCost; boolean kismetUsed = false; // checking for kismet @@ -856,8 +858,8 @@ public class RenderListener { } } } - long kismetPrice = neu.manager.auctionManager.getLowestBin("KISMET_FEATHER"); - String kismetStr = EnumChatFormatting.RED + format.format(kismetPrice) + " coins"; + double kismetPrice = neu.manager.auctionManager.getLowestBin("KISMET_FEATHER"); + String kismetStr = EnumChatFormatting.RED + formatCoins(kismetPrice) + " coins"; if (neu.config.dungeons.useKismetOnDungeonProfit) profitLossBIN = kismetUsed ? profitLossBIN - kismetPrice : profitLossBIN; @@ -867,9 +869,9 @@ public class RenderListener { String plStringBIN; if (profitLossBIN >= 0) { - plStringBIN = prefix + "+" + format.format(profitLossBIN) + " coins"; + plStringBIN = prefix + "+" + formatCoins(profitLossBIN) + " coins"; } else { - plStringBIN = prefix + "-" + format.format(-profitLossBIN) + " coins"; + plStringBIN = prefix + "-" + formatCoins(-profitLossBIN) + " coins"; } if (NotEnoughUpdates.INSTANCE.config.dungeons.profitDisplayLoc == 1 && !valueStringBIN2.equals(missingItem)) { @@ -916,7 +918,7 @@ public class RenderListener { for (Map.Entry entry : itemValues.entrySet()) { Utils.renderAlignedString( entry.getKey(), - prefix + format.format(entry.getValue().longValue()), + prefix + formatCoins(entry.getValue().doubleValue()), guiLeft + xSize + 4 + 10, guiTop + (neu.config.dungeons.useKismetOnDungeonProfit ? (kismetUsed ? 39 : 29) : 29) + (++index) * 10, 160 @@ -944,6 +946,10 @@ public class RenderListener { } } + private String formatCoins(double price) { + return format.format(price < 5 ? price : (long) price); + } + /** * Sends a mouse event to NEUOverlay if the inventory isn't hovered AND focused. * Will also cancel the event if if NEUOverlay#mouseInput returns true. -- cgit From d3805f080af87eb2bc7d2a2eac6c3f8db539324f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 8 Sep 2022 17:00:49 +0200 Subject: 0.14 - Finished :) (#233) Co-authored-by: nopo Co-authored-by: jani270 <69345714+jani270@users.noreply.github.com> Co-authored-by: Ascynx <78341107+Ascynx@users.noreply.github.com> Co-authored-by: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Co-authored-by: Lulonaut --- Update Notes/2.1.md | 13 +- .../moulberry/notenoughupdates/NEUOverlay.java | 4 +- .../notenoughupdates/NotEnoughUpdates.java | 4 + .../notenoughupdates/auction/APIManager.java | 13 +- .../notenoughupdates/core/util/StringUtils.java | 20 + .../events/RepositoryReloadEvent.java | 2 +- .../notenoughupdates/listener/ChatListener.java | 4 +- .../listener/ItemTooltipEssenceShopListener.java | 84 +++ .../listener/ItemTooltipListener.java | 3 +- .../listener/ItemTooltipRngListener.java | 330 ++++++++++++ .../notenoughupdates/listener/RenderListener.java | 36 +- .../miscfeatures/AuctionProfit.java | 6 +- .../miscfeatures/BazaarSacksProfit.java | 9 +- .../miscfeatures/DamageCommas.java | 29 +- .../miscgui/AccessoryBagOverlay.java | 4 +- .../miscgui/TrophyRewardOverlay.java | 2 +- .../notenoughupdates/mixins/MixinGuiContainer.java | 2 +- .../notenoughupdates/mixins/MixinRenderItem.java | 6 +- .../mixins/MixinSkyclientCosmetics.java | 39 ++ .../notenoughupdates/options/NEUConfig.java | 10 + .../options/seperateSections/BazaarTweaks.java | 81 +++ .../options/seperateSections/Dungeons.java | 9 + .../options/seperateSections/Misc.java | 8 +- .../options/seperateSections/SkillOverlays.java | 9 +- .../options/seperateSections/TooltipTweaks.java | 40 +- .../overlays/AuctionSearchOverlay.java | 2 +- .../overlays/BazaarSearchOverlay.java | 572 +++++++++++++++++++++ .../overlays/CombatSkillOverlay.java | 82 ++- .../notenoughupdates/profileviewer/BasicPage.java | 5 +- .../profileviewer/CollectionsPage.java | 18 +- .../profileviewer/DungeonPage.java | 32 +- .../notenoughupdates/profileviewer/ExtraPage.java | 84 ++- .../profileviewer/GuiProfileViewer.java | 20 +- .../profileviewer/InventoriesPage.java | 108 ++-- .../notenoughupdates/profileviewer/MiningPage.java | 20 +- .../notenoughupdates/profileviewer/PetsPage.java | 24 +- .../profileviewer/bestiary/BestiaryPage.java | 18 +- .../notenoughupdates/util/Calculator.java | 2 + src/main/resources/mixins.notenoughupdates.json | 1 + 39 files changed, 1576 insertions(+), 179 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipEssenceShopListener.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinSkyclientCosmetics.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/BazaarTweaks.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java (limited to 'src/main') diff --git a/Update Notes/2.1.md b/Update Notes/2.1.md index b5853248..050eaa93 100644 --- a/Update Notes/2.1.md +++ b/Update Notes/2.1.md @@ -37,6 +37,9 @@ - Added senither and lily weight - CrypticPlasma - Added the Quiver Info when hovering in inventory tab over Arrows display - Lulonaut - Added the Magical Power Info when hovering in inventory tab over Accessory Bag display - Lulonaut + - Added carpentry skill to skill average - hannibal2 + - Fixed sort order of fishing rods in profile viewer page - hannibal2 + - Changing sort logic from strength plus damage to bin price for best weapons in pv inventory page - hannibal2 ### **Minor Changes:** @@ -106,9 +109,13 @@ - Add Auto-Updater (linux only) - nea89 - Added power stone feature - hannibal2 - Added abiphone warning - hannibal2 -- Added blur limit to map at 100 - nopo +- Added blur limit at 100 - nopo - Added bazaar sacks profit feature - hannibal2 - Added an option to disable etherwarp overlay when TP is denied - hannibal2 +- Added bazaar search overlay - hannibal2 +- Added fraction display instead of percentage in slayer and dungeon RNG meter inventory - hannibal2 +- Added profit per score/XP to RNG meter - hannibal2 +- Added showing the amount of dungeon runs or slayer bosses needed for the rng meter to fill up - hannibal2 - Added bazaar prices to enchants in the enchantment table - hannibal2 / nea89 @@ -137,6 +144,9 @@ - Fixed crash with spamming remove enchant in /neuec - nopo - Fixed missing enchants not working with shiny items - nopo - Fixed golden dragon not working in pet overlay - CrypticPlasma +- Fixed shortened damage - nopo +- Fixed bazaar prices sorting order in neu item list - hannibal2 +- Fixed priceless items showing first in the missing tab of the accessory bag overlay - nopo ### **Other:** @@ -155,6 +165,7 @@ - NeucrystalHollowsJungle - NeucrystalHollowsMagmaFields - NeucrystalHollowsCrystalNucleus +- Disabled Skyclient cosmetics disabling neu map - nopo ### **Previous change log** diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 19f5a780..18be69e6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -1265,8 +1265,8 @@ public class NEUOverlay extends Gui { String internal1 = o1.get("internalname").getAsString(); String internal2 = o2.get("internalname").getAsString(); - double cost1 = manager.auctionManager.getLowestBin(internal1); - double cost2 = manager.auctionManager.getLowestBin(internal2); + double cost1 = manager.auctionManager.getBazaarOrBin(internal1); + double cost2 = manager.auctionManager.getBazaarOrBin(internal2); if (cost1 < cost2) return mult; if (cost1 > cost2) return -mult; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index dd4c01af..6732336c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -29,7 +29,9 @@ import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; import io.github.moulberry.notenoughupdates.cosmetics.ShaderManager; import io.github.moulberry.notenoughupdates.dungeons.DungeonMap; import io.github.moulberry.notenoughupdates.listener.ChatListener; +import io.github.moulberry.notenoughupdates.listener.ItemTooltipEssenceShopListener; import io.github.moulberry.notenoughupdates.listener.ItemTooltipListener; +import io.github.moulberry.notenoughupdates.listener.ItemTooltipRngListener; import io.github.moulberry.notenoughupdates.listener.NEUEventListener; import io.github.moulberry.notenoughupdates.listener.OldAnimationChecker; import io.github.moulberry.notenoughupdates.listener.RenderListener; @@ -283,6 +285,8 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(CustomBiomes.INSTANCE); MinecraftForge.EVENT_BUS.register(new ChatListener(this)); MinecraftForge.EVENT_BUS.register(new ItemTooltipListener(this)); + MinecraftForge.EVENT_BUS.register(new ItemTooltipRngListener(this)); + MinecraftForge.EVENT_BUS.register(new ItemTooltipEssenceShopListener(this)); MinecraftForge.EVENT_BUS.register(new RenderListener(this)); MinecraftForge.EVENT_BUS.register(new OldAnimationChecker()); MinecraftForge.EVENT_BUS.register(new SignCalculator()); 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 74ef2483..2dc02b7e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -807,9 +807,18 @@ public class APIManager { return keys; } - public JsonObject getBazaarInfo(String internalname) { + public double getBazaarOrBin(String internalName) { + JsonObject bazaarInfo = manager.auctionManager.getBazaarInfo(internalName); + if (bazaarInfo != null && bazaarInfo.get("curr_buy") != null) { + return bazaarInfo.get("curr_buy").getAsFloat(); + } else { + return manager.auctionManager.getLowestBin(internalName); + } + } + + public JsonObject getBazaarInfo(String internalName) { if (bazaarJson == null) return null; - JsonElement e = bazaarJson.get(internalname); + JsonElement e = bazaarJson.get(internalName); if (e == null) { return null; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java index 6143085c..a4f814d1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java @@ -67,6 +67,26 @@ public class StringUtils { return Integer.parseInt(str); } + public static String shortNumberFormat(double n) { + return shortNumberFormat(n, 0); + } + + private static final char[] c = new char[] { 'k', 'm', 'b', 't' }; + + public static String shortNumberFormat(double n, int iteration) { + if (n < 1000) { + if (n % 1 == 0) { + return Integer.toString((int) n); + } else { + return String.format("%.2f", n); + } + } + + double d = ((long) n / 100) / 10.0; + boolean isRound = (d * 10) % 10 == 0; + return d < 1000 ? (isRound || d > 9.99 ? (int) d * 10 / 10 : d + "") + "" + c[iteration] : shortNumberFormat(d, iteration + 1); + } + public static String urlEncode(String something) { try { return URLEncoder.encode(something, StandardCharsets.UTF_8.name()); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/RepositoryReloadEvent.java b/src/main/java/io/github/moulberry/notenoughupdates/events/RepositoryReloadEvent.java index bf6448a2..ab650c54 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/events/RepositoryReloadEvent.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/events/RepositoryReloadEvent.java @@ -23,7 +23,7 @@ import java.io.File; public class RepositoryReloadEvent extends NEUEvent { private final File baseFile; - private boolean isFirstLoad; + private final boolean isFirstLoad; public RepositoryReloadEvent(File baseFile, boolean isFirstLoad) { this.baseFile = baseFile; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java index 5bd47f3a..b59eaf17 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java @@ -198,8 +198,8 @@ public class ChatListener { timeSinceLastBoss2 = timeSinceLastBoss; timeSinceLastBoss = System.currentTimeMillis(); } - } else if (unformatted.startsWith(" RNGesus Meter:")) { - RNGMeter = unformatted.substring(" RNGesus Meter: -------------------- ".length()); + } else if (unformatted.startsWith(" RNG Meter")) { + RNGMeter = unformatted.substring(" RNG Meter - ".length()); } else if (matcher.matches()) { //matcher.group(1); SlayerOverlay.slayerLVL = matcher.group(2); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipEssenceShopListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipEssenceShopListener.java new file mode 100644 index 00000000..4b380c2f --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipEssenceShopListener.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.listener; + +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ItemTooltipEssenceShopListener { + private final NotEnoughUpdates neu; + + private final Pattern ESSENCE_PATTERN = Pattern.compile("§5§o§d([\\d,]+) (.+) Essence"); + + public ItemTooltipEssenceShopListener(NotEnoughUpdates neu) { + this.neu = neu; + } + + @SubscribeEvent + public void onItemTooltip(ItemTooltipEvent event) { + if (!neu.isOnSkyblock()) return; + if (event.toolTip == null) return; + if (!Utils.getOpenChestName().endsWith(" Essence Shop")) return; + if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.essencePriceInEssenceShop) return; + + List newToolTip = new ArrayList<>(); + boolean next = false; + for (String line : event.toolTip) { + + if (next) { + next = false; + Matcher matcher = ESSENCE_PATTERN.matcher(line); + if (matcher.matches()) { + String rawNumber = matcher.group(1).replace(",", ""); + int amount = Integer.parseInt(rawNumber); + String type = matcher.group(2); + + String essenceName = "ESSENCE_" + type.toUpperCase(); + JsonObject bazaarInfo = neu.manager.auctionManager.getBazaarInfo(essenceName); + + if (bazaarInfo != null && bazaarInfo.has("curr_sell")) { + float bazaarPrice = bazaarInfo.get("curr_sell").getAsFloat(); + double price = bazaarPrice * amount; + String format = StringUtils.shortNumberFormat(price); + newToolTip.add(line + " §7(§6" + format + " coins§7)"); + continue; + } + } + } + + if (line.contains("Cost")) { + next = true; + } + newToolTip.add(line); + } + + event.toolTip.clear(); + event.toolTip.addAll(newToolTip); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java index e5c3324f..3936ad74 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java @@ -266,8 +266,7 @@ public class ItemTooltipListener { newTooltip.add(""); } - newTooltip.add(EnumChatFormatting.BLUE + "Stats for " + rarityFormatted + - "\u00a79: [\u00a7l\u00a7m< \u00a79Switch\u00a7l\u27a1\u00a79]"); + newTooltip.add(EnumChatFormatting.BLUE + "Stats for " + rarityFormatted + "§9: [§l§m< §9Switch§l➡§9]"); if (statsE != null && statsE.isJsonObject()) { JsonObject stats = statsE.getAsJsonObject(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java new file mode 100644 index 00000000..bbbb9049 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java @@ -0,0 +1,330 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.listener; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent; +import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; +import io.github.moulberry.notenoughupdates.util.Calculator; +import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.item.ItemStack; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.lwjgl.input.Keyboard; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ItemTooltipRngListener { + private final NotEnoughUpdates neu; + private boolean showSlayerRngFractions = false; + private boolean pressedShiftLast = false; + private int currentSelected = 0; + private boolean pressedArrowLast = false; + private boolean repoReloadNeeded = true; + + private final Pattern ODDS_PATTERN = Pattern.compile("§5§o§7Odds: (.+) §7\\(§7(.*)%\\)"); + private final Pattern ODDS_SELECTED_PATTERN = Pattern.compile("§5§o§7Odds: (.+) §7\\(§8§m(.*)%§r §7(.+)%\\)"); + + private final Pattern RUNS_PATTERN = Pattern.compile("§5§o§7(Dungeon Score|Slayer XP): §d(.*)§5/§d(.+)"); + private final Pattern RUNS_SELECTED_PATTERN = Pattern.compile("§5§o§d-(.+)- §d(.*)§5/§d(.+)"); + + private final Pattern SLAYER_INVENTORY_TITLE_PATTERN = Pattern.compile("(.+) RNG Meter"); + + private final Map dungeonData = new LinkedHashMap<>(); + private final Map> slayerData = new LinkedHashMap<>(); + + public ItemTooltipRngListener(NotEnoughUpdates neu) { + this.neu = neu; + } + + @SubscribeEvent + public void onItemTooltip(ItemTooltipEvent event) { + if (!neu.isOnSkyblock()) return; + if (event.toolTip == null) return; + if (!Utils.getOpenChestName().endsWith(" RNG Meter") && !slayerData.containsKey(Utils.getOpenChestName())) return; + + List newToolTip = new ArrayList<>(); + + boolean nextLineProgress = false; + for (String line : event.toolTip) { + + if (line.contains("Odds:")) { + if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.rngMeterFractionDisplay) { + fractionDisplay(newToolTip, line); + continue; + } + } + + if (nextLineProgress || line.contains("Dungeon Score:") || line.contains("Slayer XP:")) { + Matcher matcher = RUNS_PATTERN.matcher(line); + Matcher matcherSelected = RUNS_SELECTED_PATTERN.matcher(line); + Matcher m = null; + if (matcher.matches()) { + m = matcher; + } else if (matcherSelected.matches()) { + m = matcherSelected; + } + + if (m != null) { + int having; + try { + having = Calculator.calculate(m.group(2).replace(",", "")).intValue(); + } catch (Calculator.CalculatorException e) { + having = -1; + } + + int needed; + try { + needed = Calculator.calculate(m.group(3).replace(",", "")).intValue(); + } catch (Calculator.CalculatorException e) { + needed = -1; + } + if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.rngMeterRunsNeeded) { + runsRequired(newToolTip, having, needed, nextLineProgress, event.itemStack); + } + + if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.rngMeterProfitPerUnit) { + if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.rngMeterRunsNeeded) { + String name = Utils.getOpenChestName().contains("Catacombs") ? "Score" : "XP"; + String formatCoinsPer = getFormatCoinsPer(event.itemStack, needed, 1, name); + if (formatCoinsPer != null) { + newToolTip.add(line); + newToolTip.add(formatCoinsPer); + continue; + } + } + } + } + nextLineProgress = false; + } + + if (line.contains("Progress:")) { + nextLineProgress = true; + } + newToolTip.add(line); + } + + event.toolTip.clear(); + event.toolTip.addAll(newToolTip); + } + + private String getFormatCoinsPer(ItemStack stack, int needed, int multiplier, String name) { + String internalName = neu.manager.getInternalNameForItem(stack); + double bin = neu.manager.auctionManager.getBazaarOrBin(internalName); + if (bin <= 0) return null; + + double coinsPer = (bin / needed) * multiplier; + String format = StringUtils.shortNumberFormat(coinsPer); + return "§7Coins per " + name + ": §6" + format + " coins"; + } + + private void fractionDisplay(List newToolTip, String line) { + boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); + if (!pressedShiftLast && shift) { + showSlayerRngFractions = !showSlayerRngFractions; + } + pressedShiftLast = shift; + + String result; + Matcher matcher = ODDS_PATTERN.matcher(line); + Matcher matcherSelected = ODDS_SELECTED_PATTERN.matcher(line); + if (matcher.matches()) { + String odds = matcher.group(1); + int baseChance = calculateChance(matcher.group(2)); + String baseFormat = GuiProfileViewer.numberFormat.format(baseChance); + + String fractionFormat = "§7(1/" + baseFormat + ")"; + result = odds + " " + fractionFormat; + } else if (matcherSelected.matches()) { + String odds = matcherSelected.group(1); + int baseChance = calculateChance(matcherSelected.group(2)); + String baseFormat = GuiProfileViewer.numberFormat.format(baseChance); + + int increasedChance = calculateChance(matcherSelected.group(3)); + String increased = GuiProfileViewer.numberFormat.format(increasedChance); + String fractionFormat = "§7(§8§m1/" + baseFormat + "§r §71/" + increased + ")"; + + result = odds + " " + fractionFormat; + } else { + return; + } + + if (showSlayerRngFractions) { + newToolTip.add("§7Odds: " + result); + newToolTip.add("§8[Press SHIFT to show odds as percentages]"); + } else { + newToolTip.add(line); + newToolTip.add("§8[Press SHIFT to show odds as fractions]"); + } + } + + /** + * This adds support for the /neureloadrepo command + */ + @SubscribeEvent(priority = EventPriority.LOWEST) + public void onRepoReload(RepositoryReloadEvent event) { + repoReloadNeeded = true; + } + + public void checkUpdateData() { + if (repoReloadNeeded) { + updateRepoData(); + } + } + + private void updateRepoData() { + slayerData.clear(); + dungeonData.clear(); + + JsonObject leveling = Constants.LEVELING; + if (!leveling.has("slayer_boss_xp") || + !leveling.has("slayer_highest_tier") || + !leveling.has("slayer_tier_colors") || + !leveling.has("rng_meter_dungeon_score")) { + Utils.showOutdatedRepoNotification(); + return; + } + + List slayerExp = new ArrayList<>(); + for (JsonElement element : leveling.get("slayer_boss_xp").getAsJsonArray()) { + slayerExp.add(element.getAsInt()); + } + + List slayerColors = new ArrayList<>(); + for (JsonElement element : leveling.get("slayer_tier_colors").getAsJsonArray()) { + slayerColors.add(element.getAsString()); + } + + for (Map.Entry entry : leveling.get("slayer_highest_tier").getAsJsonObject().entrySet()) { + String slayerName = entry.getKey(); + int maxTier = entry.getValue().getAsInt(); + LinkedHashMap singleSlayerData = new LinkedHashMap<>(); + for (int i = 0; i < maxTier; i++) { + String name = slayerColors.get(i) + "Tier " + (i + 1); + singleSlayerData.put(name, slayerExp.get(i)); + } + slayerData.put(slayerName, singleSlayerData); + } + + for (Map.Entry entry : leveling.get("rng_meter_dungeon_score").getAsJsonObject().entrySet()) { + String dungeonScore = entry.getKey(); + int score = entry.getValue().getAsInt(); + dungeonData.put(dungeonScore, score); + } + + repoReloadNeeded = false; + } + + private void runsRequired( + List toolTip, + int having, + int needed, + boolean nextLineProgress, + ItemStack stack + ) { + checkUpdateData(); + if (repoReloadNeeded) return; + + String openChestName = Utils.getOpenChestName(); + Map runsData; + String labelPlural; + String labelSingular; + if (openChestName.contains("Catacombs")) { + runsData = dungeonData; + labelPlural = "Runs"; + labelSingular = "Run"; + } else { // Slayer + Matcher matcher = SLAYER_INVENTORY_TITLE_PATTERN.matcher(openChestName); + if (!matcher.matches()) { + //Happens for the first 4-5 ticks after inventory opens. Thanks hypixel + return; + } + + String slayerName = matcher.group(1); + runsData = slayerData.get(slayerName); + labelPlural = "Bosses"; + labelSingular = "Boss"; + } + + handleArrowKeys(runsData); + + if (currentSelected >= runsData.keySet().size()) { + currentSelected = 0; + } + + String name = (String) runsData.keySet().toArray()[currentSelected]; + int gainPerRun = runsData.get(name); + + int runsNeeded = needed / gainPerRun; + int runsHaving = having / gainPerRun; + String runsNeededFormat = GuiProfileViewer.numberFormat.format(runsNeeded); + String runsHavingFormat = GuiProfileViewer.numberFormat.format(runsHaving); + + String progressString = null; + if (nextLineProgress) { + progressString = toolTip.remove(toolTip.size() - 1); + } + + toolTip.add("§9Stats for " + name + "§9: [§l§m< §9Switch§l➡§9]"); + toolTip.add( + " §7" + labelPlural + " completed: §e" + runsHavingFormat + " §7(of §e" + runsNeededFormat + " §7needed)"); + + if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.rngMeterProfitPerUnit) { + String formatCoinsPer = getFormatCoinsPer(stack, needed, gainPerRun, labelSingular); + if (formatCoinsPer != null) { + toolTip.add(" " + formatCoinsPer); + } + } + + toolTip.add(" "); + if (progressString != null) { + toolTip.add(progressString); + } + } + + private void handleArrowKeys(Map runsData) { + boolean left = Keyboard.isKeyDown(Keyboard.KEY_LEFT); + boolean right = Keyboard.isKeyDown(Keyboard.KEY_RIGHT); + if (!pressedArrowLast && (left || right)) { + if (Utils.getOpenChestName().contains("Catacombs") ? right : left) { + currentSelected--; + } else { + currentSelected++; + } + if (currentSelected < 0) currentSelected = 0; + if (currentSelected >= runsData.size()) currentSelected = runsData.size() - 1; + } + pressedArrowLast = left || right; + } + + private int calculateChance(String string) { + return (int) (100.0 / Double.parseDouble(string)); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index 54b647e9..166e46d0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -53,6 +53,7 @@ import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay; +import io.github.moulberry.notenoughupdates.overlays.BazaarSearchOverlay; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.overlays.RancherBootOverlay; import io.github.moulberry.notenoughupdates.overlays.TextOverlay; @@ -119,6 +120,8 @@ import java.util.TreeMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import static io.github.moulberry.notenoughupdates.util.GuiTextures.dungeon_chest_worth; @@ -146,6 +149,8 @@ public class RenderListener { private boolean inDungeonPage = false; private final NumberFormat format = new DecimalFormat("#,##0.#", new DecimalFormatSymbols(Locale.US)); + private final Pattern ESSENCE_PATTERN = Pattern.compile("§d(.+) Essence §8x([\\d,]+)"); + public RenderListener(NotEnoughUpdates neu) { this.neu = neu; } @@ -420,6 +425,11 @@ public class RenderListener { event.setCanceled(true); return; } + if (BazaarSearchOverlay.shouldReplace()) { + BazaarSearchOverlay.render(); + event.setCanceled(true); + return; + } if (RancherBootOverlay.shouldReplace()) { RancherBootOverlay.render(); event.setCanceled(true); @@ -736,7 +746,7 @@ public class RenderListener { StringBuilder cost = new StringBuilder(); for (int i = 0; i < line6.length(); i++) { char c = line6.charAt(i); - if ("0123456789".indexOf(c) >= 0) { + if (Character.isDigit(c)) { cost.append(c); } } @@ -752,6 +762,20 @@ public class RenderListener { for (int i = 0; i < 5; i++) { ItemStack item = lower.getStackInSlot(11 + i); String internal = neu.manager.getInternalNameForItem(item); + String displayName = item.getDisplayName(); + Matcher matcher = ESSENCE_PATTERN.matcher(displayName); + if (neu.config.dungeons.useEssenceCostFromBazaar && matcher.matches()) { + String type = matcher.group(1).toUpperCase(); + JsonObject bazaarInfo = neu.manager.auctionManager.getBazaarInfo("ESSENCE_" + type); + if (bazaarInfo != null && bazaarInfo.has("curr_sell")) { + float bazaarPrice = bazaarInfo.get("curr_sell").getAsFloat(); + int amount = Integer.parseInt(matcher.group(2)); + double price = bazaarPrice * amount; + itemValues.put(displayName, price); + totalValue += price; + } + continue; + } if (internal != null) { internal = internal.replace("\u00CD", "I").replace("\u0130", "I"); float bazaarPrice = -1; @@ -986,6 +1010,11 @@ public class RenderListener { event.setCanceled(true); return; } + if (BazaarSearchOverlay.shouldReplace()) { + BazaarSearchOverlay.mouseEvent(); + event.setCanceled(true); + return; + } if (RancherBootOverlay.shouldReplace()) { RancherBootOverlay.mouseEvent(); event.setCanceled(true); @@ -1466,6 +1495,11 @@ public class RenderListener { event.setCanceled(true); return; } + if (BazaarSearchOverlay.shouldReplace()) { + BazaarSearchOverlay.keyEvent(); + event.setCanceled(true); + return; + } if (RancherBootOverlay.shouldReplace()) { RancherBootOverlay.keyEvent(); event.setCanceled(true); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java index e1024eab..88ca0cc8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java @@ -20,8 +20,8 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; -import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -145,10 +145,10 @@ public class AuctionProfit { String coinsToCollectStr = EnumChatFormatting.BOLD + EnumChatFormatting.DARK_GRAY.toString() + "Coins to collect: " + EnumChatFormatting.RESET + EnumChatFormatting.DARK_GREEN + "" + - GuiProfileViewer.shortNumberFormat(coinsToCollect, 0); + StringUtils.shortNumberFormat(coinsToCollect); String valueIfSoldStr = EnumChatFormatting.BOLD + EnumChatFormatting.DARK_GRAY.toString() + "Value if all sold: " + EnumChatFormatting.RESET + EnumChatFormatting.DARK_GREEN + "" + - GuiProfileViewer.shortNumberFormat(coinsIfAllSold, 0); + StringUtils.shortNumberFormat(coinsIfAllSold); fontRendererObj.drawString(coinsToCollectStr, a + 6, guiTop + 32, -1, false); fontRendererObj.drawString(valueIfSoldStr, a + 6, guiTop + 42, -1, false); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java index 084fd03f..7007f39b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java @@ -68,7 +68,7 @@ public class BazaarSacksProfit { @SubscribeEvent(priority = EventPriority.LOW) public void onItemTooltipLow(ItemTooltipEvent event) { - if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.bazaarSacksProfit) return; + if (!NotEnoughUpdates.INSTANCE.config.bazaarTweaks.bazaarSacksProfit) return; if (!inBazaar()) return; ItemStack itemStack = event.itemStack; @@ -89,6 +89,11 @@ public class BazaarSacksProfit { out: for (String line : ItemUtils.getLore(itemStack)) { + + if (line.equals("§8Loading...")) { + dirty = true; + return; + } if (line.contains("§7x ")) { String[] split = line.split("§7x "); String rawAmount = StringUtils.cleanColour(split[0]).replace(",", "").substring(1); @@ -108,7 +113,7 @@ public class BazaarSacksProfit { } } } - System.out.println("no bazaar item in repo found for '" + bazaarName + "'"); + System.err.println("no bazaar item in repo found for '" + bazaarName + "'"); invalidNames.add(bazaarName); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java index 127edcde..b1ab11c1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java @@ -45,15 +45,18 @@ public class DamageCommas { }; private static final char STAR = '\u2727'; + private static final char OVERLOAD_STAR = '\u272F'; private static final Pattern PATTERN_CRIT = Pattern.compile( - "\u00a7f" + STAR + "((?:\u00a7.\\d)+)\u00a7." + STAR + "(.*)"); - private static final Pattern PATTERN_NO_CRIT = Pattern.compile("\u00a77(\\d+)(.*)"); + "\u00a7f" + STAR + "((?:\u00a7.\\d(?:§.,)?)+)\u00a7." + STAR + "(.*)"); + private static final Pattern PATTERN_NO_CRIT = Pattern.compile("(\u00a7.)([\\d+,]*)(.*)"); + private static final Pattern OVERLOAD_PATTERN = Pattern.compile("(\u00a7.)" + OVERLOAD_STAR + "((?:\u00a7.[\\d,])+)(\u00a7.)" + OVERLOAD_STAR + "\u00a7r"); public static IChatComponent replaceName(EntityLivingBase entity) { if (!entity.hasCustomName()) return entity.getDisplayName(); IChatComponent name = entity.getDisplayName(); - if (NotEnoughUpdates.INSTANCE.config.misc.damageIndicatorStyle == 0) return name; + if (!NotEnoughUpdates.INSTANCE.config.misc.damageIndicatorStyle2) return name; + if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return name; if (replacementMap.containsKey(entity)) { ChatComponentText component = replacementMap.get(entity); @@ -69,17 +72,23 @@ public class DamageCommas { String suffix; Matcher matcherCrit = PATTERN_CRIT.matcher(formatted); + Matcher matcherOverload = OVERLOAD_PATTERN.matcher(formatted); if (matcherCrit.matches()) { crit = true; - numbers = StringUtils.cleanColour(matcherCrit.group(1)); + numbers = StringUtils.cleanColour(matcherCrit.group(1)).replace(",", ""); prefix = "\u00a7f" + STAR; suffix = "\u00a7f" + STAR + matcherCrit.group(2); - } else { + } else if (matcherOverload.matches()) { + crit = true; + numbers = StringUtils.cleanColour(matcherOverload.group(2)).replace(",", ""); + prefix = matcherOverload.group(1) + OVERLOAD_STAR; + suffix = matcherOverload.group(3) + OVERLOAD_STAR + "\u00a7r"; + } else { Matcher matcherNoCrit = PATTERN_NO_CRIT.matcher(formatted); if (matcherNoCrit.matches()) { - numbers = matcherNoCrit.group(1); - prefix = "\u00A77"; - suffix = "\u00A7r" + matcherNoCrit.group(2); + numbers = matcherNoCrit.group(2).replace(",", ""); + prefix = matcherNoCrit.group(1); + suffix = "\u00A7r" + matcherNoCrit.group(3); } else { replacementMap.put(entity, null); return name; @@ -91,10 +100,10 @@ public class DamageCommas { try { int number = Integer.parseInt(numbers); - if (number > 999 && NotEnoughUpdates.INSTANCE.config.misc.damageIndicatorStyle == 2) { + if (number > 999) { newFormatted.append(Utils.shortNumberFormat(number, 0)); } else { - newFormatted.append(NumberFormat.getIntegerInstance().format(number)); + return name; } } catch (NumberFormatException e) { replacementMap.put(entity, null); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java index b6c3e763..530dcfd1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java @@ -847,7 +847,7 @@ public class AccessoryBagOverlay { if (info != null) cost1 = info.craftCost; else - cost1 = 0; + cost1 = -1; } double cost2; JsonObject o2Auc = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(o2); @@ -858,7 +858,7 @@ public class AccessoryBagOverlay { if (info != null) cost2 = info.craftCost; else - cost2 = 0; + cost2 = -1; } if (cost1 == -1 && cost2 == -1) return o1.compareTo(o2); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java index 2b600d2e..e6c4dc74 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java @@ -70,7 +70,7 @@ public class TrophyRewardOverlay { * This adds support for the /neureloadrepo command */ @SubscribeEvent(priority = EventPriority.LOWEST) - public void reload(RepositoryReloadEvent event) { + public void onRepoReload(RepositoryReloadEvent event) { reloadNeeded = true; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java index 06512fa8..7c3414fa 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -125,7 +125,7 @@ public abstract class MixinGuiContainer extends GuiScreen { else if (!($this instanceof GuiChest)) BetterContainers.profileViewerStackIndex = -1; - if (slot.getStack() == null && NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen) { + if (slot.getStack() == null && NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { GlStateManager.pushMatrix(); GlStateManager.translate(0, 0, 100 + Minecraft.getMinecraft().getRenderItem().zLevel); GlStateManager.depthMask(false); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java index 4f193c98..dc59c0bb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java @@ -195,7 +195,7 @@ public abstract class MixinRenderItem { @Inject(method = "renderItemIntoGUI", at = @At("HEAD")) public void renderItemHead(ItemStack stack, int x, int y, CallbackInfo ci) { - if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen) { + if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { boolean matches = false; GuiTextField textField = NotEnoughUpdates.INSTANCE.overlay.getTextField(); @@ -221,7 +221,7 @@ public abstract class MixinRenderItem { @Inject(method = "renderItemIntoGUI", at = @At("RETURN")) public void renderItemReturn(ItemStack stack, int x, int y, CallbackInfo ci) { if (stack != null && stack.stackSize != 1) return; - if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen) { + if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { boolean matches = false; GuiTextField textField = NotEnoughUpdates.INSTANCE.overlay.getTextField(); @@ -252,7 +252,7 @@ public abstract class MixinRenderItem { CallbackInfo ci ) { if (stack != null && stack.stackSize != 1) { - if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen) { + if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { boolean matches = false; GuiTextField textField = NotEnoughUpdates.INSTANCE.overlay.getTextField(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinSkyclientCosmetics.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinSkyclientCosmetics.java new file mode 100644 index 00000000..32c9f418 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinSkyclientCosmetics.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.mixins; + +import net.minecraftforge.event.world.WorldEvent; +import org.spongepowered.asm.mixin.Dynamic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Pseudo +@Mixin(targets = "co.skyclient.scc.SkyclientCosmetics") +public class MixinSkyclientCosmetics { + + @Dynamic + @Inject(method = "onWorldLoad", at = @At("HEAD"), cancellable = true, remap = false) + public void onWorldLoad(WorldEvent.Load event, CallbackInfo ci) { + ci.cancel(); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index ade9edfe..4d04bfbc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -37,6 +37,7 @@ import io.github.moulberry.notenoughupdates.options.seperateSections.AHGraph; import io.github.moulberry.notenoughupdates.options.seperateSections.AHTweaks; import io.github.moulberry.notenoughupdates.options.seperateSections.AccessoryBag; import io.github.moulberry.notenoughupdates.options.seperateSections.ApiData; +import io.github.moulberry.notenoughupdates.options.seperateSections.BazaarTweaks; import io.github.moulberry.notenoughupdates.options.seperateSections.Calendar; import io.github.moulberry.notenoughupdates.options.seperateSections.CustomArmour; import io.github.moulberry.notenoughupdates.options.seperateSections.DungeonMapConfig; @@ -369,6 +370,13 @@ public class NEUConfig extends Config { ) public AHTweaks ahTweaks = new AHTweaks(); + @Expose + @Category( + name = "Bazaar Tweaks", + desc = "Tweaks for the Bazaar" + ) + public BazaarTweaks bazaarTweaks = new BazaarTweaks(); + @Expose @Category( name = "AH/BZ Graph", @@ -445,6 +453,8 @@ public class NEUConfig extends Config { @Expose public ArrayList previousAuctionSearches = new ArrayList<>(); @Expose + public ArrayList previousBazaarSearches = new ArrayList<>(); + @Expose public ArrayList eventFavourites = new ArrayList<>(); @Expose public ArrayList quickCommands = createDefaultQuickCommands(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/BazaarTweaks.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/BazaarTweaks.java new file mode 100644 index 00000000..2ba0b718 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/BazaarTweaks.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.options.seperateSections; + +import com.google.gson.annotations.Expose; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigAccordionId; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorAccordion; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; + +public class BazaarTweaks { + + @ConfigOption( + name = "Search GUI", + desc = "" + ) + @ConfigEditorAccordion(id = 0) + public boolean searchAccordion = false; + + @Expose + @ConfigOption( + name = "Enable Search GUI", + desc = "Use the advanced search GUI with autocomplete and history instead of the normal sign GUI" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean enableSearchOverlay = true; + + @Expose + @ConfigOption( + name = "Keep Previous Search", + desc = "Don't clear the search bar after closing the GUI" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean keepPreviousSearch = false; + + @Expose + @ConfigOption( + name = "Past Searches", + desc = "Show past searches below the autocomplete box" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean showPastSearches = true; + + @Expose + @ConfigOption( + name = "ESC to Full Close", + desc = "Make pressing ESCAPE close the search GUI without opening up the Bazaar again\n" + + "ENTER can still be used to search" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean escFullClose = true; + + @Expose + @ConfigOption( + name = "Bazaar Sacks Profit", + desc = "Orders the items in your sacks in the bazaar inventory and adding buy order toggle" + ) + @ConfigEditorBoolean + public boolean bazaarSacksProfit = true; +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Dungeons.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Dungeons.java index e080db7d..c94bd181 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Dungeons.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Dungeons.java @@ -114,6 +114,15 @@ public class Dungeons { @ConfigAccordionId(id = 1) public boolean useKismetOnDungeonProfit = true; + @Expose + @ConfigOption( + name = "Include Essence Cost", + desc = "Include Bazaar Essence Sell Cost in the Profit Calculation for Dungeon Chests" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 1) + public boolean useEssenceCostFromBazaar = true; + @Expose @ConfigOption( name = "Warning if Derpy active", diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index d87082b4..84e2322e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -126,13 +126,11 @@ public class Misc { @Expose @ConfigOption( name = "Damage Indicator Style", - desc = "Change the style of Skyblock damage indicators to be easier to read\n" + + desc = "Change Skyblock damage indicators to use shortened numbers\n" + "\u00A7cSome old animations mods break this feature" ) - @ConfigEditorDropdown( - values = {"Off", "Commas", "Shortened"} - ) - public int damageIndicatorStyle = 1; + @ConfigEditorBoolean + public boolean damageIndicatorStyle2 = false; @Expose @ConfigOption( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SkillOverlays.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SkillOverlays.java index 8b7002f9..943417e6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SkillOverlays.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SkillOverlays.java @@ -274,7 +274,7 @@ public class SkillOverlays { @Expose @ConfigOption( name = "\u00A7cWarning", - desc = "The combat display will only show if you have a Book of Stats on the item you are using" + desc = "The combat display will only show if you have a Book of Stats or the Champion enchant" ) @ConfigEditorFSR( runnableId = 12, @@ -305,11 +305,12 @@ public class SkillOverlays { "\u00a7bCurrent XP: \u00a7e6,734", "\u00a7bRemaining XP: \u00a7e3,265", "\u00a7bXP/h: \u00a7e238,129", - "\u00a7bETA: \u00a7e13h12m" + "\u00a7bETA: \u00a7e13h12m", + "\u00a7bChampion XP: \u00a7e3,523" } ) @ConfigAccordionId(id = 4) - public List combatText = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5)); + public List combatText = new ArrayList<>(Arrays.asList(0, 6, 1, 2, 3, 4, 5)); @Expose @ConfigOption( @@ -337,7 +338,7 @@ public class SkillOverlays { @Expose @ConfigOption( name = "Always show combat overlay", - desc = "Shows combat overlay even if you dont have Book of Stats" + desc = "Shows combat overlay even if you dont have Book of Stats or the Champion enchant" ) @ConfigEditorBoolean @ConfigAccordionId(id = 4) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java index 0729df97..1edc0921 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java @@ -181,11 +181,45 @@ public class TooltipTweaks { @ConfigEditorBoolean public boolean powerStoneStats = true; + @ConfigOption( + name = "RNG Meter", + desc = "" + ) + @ConfigEditorAccordion(id = 1) + public boolean rngMeter = false; + + @Expose + @ConfigOption( + name = "Fraction Display", + desc = "Show the fraction instead of the percentage in the slayer and dungeon rng meter inventory" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 1) + public boolean rngMeterFractionDisplay = true; + + @Expose + @ConfigOption( + name = " Profit Per Score/XP", + desc = "Show the amount of coins per Score/XP in the rng meter inventory" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 1) + public boolean rngMeterProfitPerUnit = true; + + @Expose + @ConfigOption( + name = "Dungeon/Slayer Needed Counter", + desc = "Show the amount of dungeon runs or slayer bosses needed for the rng meter to fill up" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 1) + public boolean rngMeterRunsNeeded = true; + @Expose @ConfigOption( - name = "Bazaar Sacks Profit", - desc = "Orders the items in your sacks in the bazaar inventory and adding buy order toggle" + name = "Essence Price In Shop", + desc = "Show the essence price in the essence shop in the dungeon hub" ) @ConfigEditorBoolean - public boolean bazaarSacksProfit = true; + public boolean essencePriceInEssenceShop = true; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java index 8ff3218a..fcea79dd 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -607,7 +607,7 @@ public class AuctionSearchOverlay { close(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow(Minecraft.getMinecraft().thePlayer.openContainer.windowId)); NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(new NEUConfigEditor( - NotEnoughUpdates.INSTANCE.config, "AH Search GUI")); + NotEnoughUpdates.INSTANCE.config, "AH Tweaks")); } } } else if (Mouse.getEventButton() == 0) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java new file mode 100644 index 00000000..66dacda3 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java @@ -0,0 +1,572 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.overlays; + +import com.google.common.base.Splitter; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.GuiElementTextField; +import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; +import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign; +import io.github.moulberry.notenoughupdates.options.NEUConfigEditor; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.gui.inventory.GuiEditSign; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.item.ItemStack; +import net.minecraft.network.play.client.C0DPacketCloseWindow; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; + +public class BazaarSearchOverlay { + private static final ResourceLocation SEARCH_OVERLAY_TEXTURE = new ResourceLocation( + "notenoughupdates:auc_search/ah_search_overlay.png"); + private static final ResourceLocation SEARCH_OVERLAY_TEXTURE_TAB_COMPLETED = new ResourceLocation( + "notenoughupdates:auc_search/ah_search_overlay_tab_completed.png"); + + private static final GuiElementTextField textField = new GuiElementTextField("", 200, 20, 0); + private static boolean searchFieldClicked = false; + private static String searchString = ""; + private static String searchStringExtra = ""; + private static final Splitter SPACE_SPLITTER = Splitter.on(" ").omitEmptyStrings().trimResults(); + private static boolean tabCompleted = false; + private static int tabCompletionIndex = -1; + + private static final int AUTOCOMPLETE_HEIGHT = 118; + + private static final Set autocompletedItems = new LinkedHashSet<>(); + + private static final Comparator salesComparator = (o1, o2) -> { + JsonObject bazaarInfo1 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(o1); + JsonObject bazaarInfo2 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(o2); + + boolean auc1Invalid = bazaarInfo1 == null || !bazaarInfo1.has("curr_sell"); + boolean auc2Invalid = bazaarInfo2 == null || !bazaarInfo2.has("curr_sell"); + + if (auc1Invalid && auc2Invalid) return o1.compareTo(o2); + if (auc1Invalid) return -1; + if (auc2Invalid) return 1; + + int sales1 = bazaarInfo1.get("curr_sell").getAsInt(); + int sales2 = bazaarInfo2.get("curr_sell").getAsInt(); + + if (sales1 == sales2) return o1.compareTo(o2); + if (sales1 > sales2) return -1; + return 1; + }; + + public static boolean shouldReplace() { + if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return false; + if (!NotEnoughUpdates.INSTANCE.config.bazaarTweaks.enableSearchOverlay) return false; + + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiEditSign)) { + if (!NotEnoughUpdates.INSTANCE.config.bazaarTweaks.keepPreviousSearch) searchString = ""; + return false; + } + + String lastContainer = Utils.getLastOpenChestName(); + if (!lastContainer.startsWith("Bazaar ➜ ")) return false; + + TileEntitySign tes = ((AccessorGuiEditSign) Minecraft.getMinecraft().currentScreen).getTileSign(); + + if (tes == null) return false; + if (tes.getPos().getY() != 0) return false; + if (!tes.signText[2].getUnformattedText().equals("^^^^^^^^^^^^^^^")) return false; + return tes.signText[3].getUnformattedText().equals("Enter query"); + } + + public static void render() { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + + Utils.drawGradientRect(0, 0, width, height, -1072689136, -804253680); + + int h = NotEnoughUpdates.INSTANCE.config.bazaarTweaks.showPastSearches ? 219 : 145; + + int topY = height / 4; + if (scaledResolution.getScaleFactor() >= 4) { + topY = height / 2 - h / 2 + 5; + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(width / 2 - 100, topY - 1, 203, h, 0, 203 / 512f, 0, h / 256f, GL11.GL_NEAREST); + + Minecraft.getMinecraft().fontRendererObj.drawString("Enter Query:", width / 2 - 100, topY - 10, 0xdddddd, true); + + textField.setFocus(true); + textField.setText(searchString); + textField.setSize(149, 20); + textField.setCustomBorderColour(0xffffff); + textField.render(width / 2 - 100 + 1, topY + 1); + + if (textField.getText().trim().isEmpty()) autocompletedItems.clear(); + + List tooltipToDisplay = null; + + int num = 0; + synchronized (autocompletedItems) { + String[] autoCompletedItemsArray = autocompletedItems.toArray(new String[0]); + for (int i = 0; i < autoCompletedItemsArray.length; i++) { + String str = autoCompletedItemsArray[i]; + JsonObject obj = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(str); + if (obj != null) { + ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(obj); + if (i == tabCompletionIndex) { + Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE_TAB_COMPLETED); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect( + width / 2 - 96 + 1, + topY + 30 + num * 22 + 1, + 193, + 21, + 0 / 512f, + 193 / 512f, + 0, + 21 / 256f, + GL11.GL_NEAREST + ); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_OVERLAY_TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect( + width / 2 - 96 + 1, + topY + 30 + num * 22 + 1, + 193, + 21, + 214 / 512f, + 407 / 512f, + 0, + 21 / 256f, + GL11.GL_NEAREST + ); + + } + String itemName = Utils.trimIgnoreColour(stack.getDisplayName().replaceAll("\\[.+]", "")); + if (itemName.contains("Enchanted Book") && str.contains(";")) { + String[] lore = NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound()); + itemName = lore[0].trim(); + } + + Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().fontRendererObj.trimStringToWidth( + itemName, + 165 + ), + width / 2 - 74, topY + 35 + num * 22 + 1, 0xdddddd, true + ); + + GlStateManager.enableDepth(); + Utils.drawItemStack(stack, width / 2 - 94 + 2, topY + 32 + num * 22 + 1); + + if (mouseX > width / 2 - 96 && mouseX < width / 2 + 96 && mouseY > topY + 30 + num * 22 && + mouseY < topY + 30 + num * 22 + 20) { + tooltipToDisplay = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } + + if (++num >= 5) break; + } + } + } + + if (NotEnoughUpdates.INSTANCE.config.bazaarTweaks.showPastSearches) { + Minecraft.getMinecraft().fontRendererObj.drawString( + "Past Searches:", + width / 2 - 100, + topY + 25 + AUTOCOMPLETE_HEIGHT + 5, + 0xdddddd, + true + ); + + for (int i = 0; i < 5; i++) { + if (i >= NotEnoughUpdates.INSTANCE.config.hidden.previousBazaarSearches.size()) break; + + String s = NotEnoughUpdates.INSTANCE.config.hidden.previousBazaarSearches.get(i); + Minecraft.getMinecraft().fontRendererObj.drawString( + s, + width / 2 - 95 + 1, + topY + 45 + AUTOCOMPLETE_HEIGHT + i * 10 + 2, + 0xdddddd, + true + ); + } + + if (tooltipToDisplay != null) { + Utils.drawHoveringText( + tooltipToDisplay, + mouseX, + mouseY, + width, + height, + -1, + Minecraft.getMinecraft().fontRendererObj + ); + } + } + + } + + private static final ExecutorService searchES = Executors.newSingleThreadExecutor(); + private static final AtomicInteger searchId = new AtomicInteger(0); + + private static String getItemIdAtIndex(int i) { + if (!autocompletedItems.isEmpty()) { + if ((i > autocompletedItems.size() - 1) || i < 0 || i > 4) { + return ""; + } + String searchString = autocompletedItems.toArray()[i].toString(); + JsonObject repoObject = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(searchString); + if (repoObject != null) { + ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(repoObject); + return Utils.cleanColour(stack.getDisplayName().replaceAll("\\[.+]", "")); + } + + } + return null; + } + + public static void close() { + if (tabCompleted) { + tabCompletionIndex = -1; + tabCompleted = false; + } + if (NotEnoughUpdates.INSTANCE.config.bazaarTweaks.keepPreviousSearch) { + search(); + } else { + synchronized (autocompletedItems) { + autocompletedItems.clear(); + } + } + + TileEntitySign tes = ((AccessorGuiEditSign) Minecraft.getMinecraft().currentScreen).getTileSign(); + + StringBuilder stringBuilder = new StringBuilder(searchString.trim()); + if (!searchStringExtra.isEmpty()) { + stringBuilder.append(searchStringExtra); + } + + String search = stringBuilder.toString(); + + if (search.length() <= 15) { + tes.signText[0] = new ChatComponentText(search.substring(0, Math.min(search.length(), 15))); + } else { + List words = SPACE_SPLITTER.splitToList(search); + + StringBuilder line0 = new StringBuilder(); + StringBuilder line1 = new StringBuilder(); + + int currentLine = 0; + for (String word : words) { + if (currentLine == 0) { + if (line0.length() + word.length() > 15) { + currentLine++; + } else { + line0.append(word); + if (line0.length() >= 15) { + currentLine++; + continue; + } else { + line0.append(" "); + } + } + } + if (currentLine == 1) { + if (line1.length() + word.length() > 15) { + line1.append(word, 0, 15 - line1.length()); + break; + } else { + line1.append(word); + if (line1.length() >= 15) { + break; + } else { + line1.append(" "); + } + } + } + if (line1.length() >= 15) break; + } + + tes.signText[0] = new ChatComponentText(line0.toString().trim()); + tes.signText[1] = new ChatComponentText(line1.toString().trim()); + } + + if (!searchString.trim().isEmpty()) { + List previousBazaarSearches = NotEnoughUpdates.INSTANCE.config.hidden.previousBazaarSearches; + previousBazaarSearches.remove(searchString); + previousBazaarSearches.remove(searchString); + previousBazaarSearches.add(0, searchString); + while (previousBazaarSearches.size() > 5) { + previousBazaarSearches.remove(previousBazaarSearches.size() - 1); + } + } + + Minecraft.getMinecraft().displayGuiScreen(null); + + if (Minecraft.getMinecraft().currentScreen == null) { + Minecraft.getMinecraft().setIngameFocus(); + } + } + + private static boolean updateTabCompletedSearch(int key) { + String id; + if (key == Keyboard.KEY_DOWN || key == Keyboard.KEY_TAB) { + id = getItemIdAtIndex(tabCompletionIndex + 1); + if (id == null) { + textField.setFocus(true); + textField.setText(searchString); + tabCompleted = false; + tabCompletionIndex = -1; + return true; + } else if (id.equals("")) { + tabCompletionIndex = 0; + return true; + } else { + searchString = id; + tabCompletionIndex += 1; + return true; + } + } else if (key == Keyboard.KEY_UP) { + id = getItemIdAtIndex(tabCompletionIndex - 1); + if (id == null) { + textField.setFocus(true); + textField.setText(searchString); + tabCompleted = false; + tabCompletionIndex = -1; + return true; + } else if (id.equals("")) { + if (autocompletedItems.size() > 4) tabCompletionIndex = 4; + else tabCompletionIndex = autocompletedItems.size() - 1; + tabCompletionIndex = autocompletedItems.size() - 1; + return true; + } else { + searchString = id; + tabCompletionIndex -= 1; + return true; + } + } + return false; + } + + public static void search() { + final int thisSearchId = searchId.incrementAndGet(); + + searchES.submit(() -> { + if (thisSearchId != searchId.get()) return; + + List title = new ArrayList<>(NotEnoughUpdates.INSTANCE.manager.search("title:" + searchString.trim())); + + if (thisSearchId != searchId.get()) return; + + if (!searchString.trim().contains(" ")) { + StringBuilder sb = new StringBuilder(); + for (char c : searchString.toCharArray()) { + sb.append(c).append(" "); + } + title.addAll(NotEnoughUpdates.INSTANCE.manager.search("title:" + sb.toString().trim())); + } + + if (thisSearchId != searchId.get()) return; + + List desc = new ArrayList<>(NotEnoughUpdates.INSTANCE.manager.search("desc:" + searchString.trim())); + desc.removeAll(title); + + if (thisSearchId != searchId.get()) return; + + Set bazaarItems = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarKeySet(); + // Amalgamated Crimsonite (Old) // TODO remove from repo + bazaarItems.remove("AMALGAMATED_CRIMSONITE"); + + title.retainAll(bazaarItems); + desc.retainAll(bazaarItems); + + title.sort(salesComparator); + desc.sort(salesComparator); + + if (thisSearchId != searchId.get()) return; + + synchronized (autocompletedItems) { + autocompletedItems.clear(); + autocompletedItems.addAll(title); + autocompletedItems.addAll(desc); + } + }); + } + + public static void keyEvent() { + boolean ignoreKey = false; + + if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { + searchStringExtra = ""; + close(); + if (NotEnoughUpdates.INSTANCE.config.bazaarTweaks.escFullClose) { + Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow(Minecraft.getMinecraft().thePlayer.openContainer.windowId)); + } + return; + } else if (Keyboard.getEventKey() == Keyboard.KEY_RETURN) { + searchStringExtra = ""; + close(); + return; + } else if (Keyboard.getEventKey() == Keyboard.KEY_TAB) { + //autocomplete to first item in the list + if (!tabCompleted) { + tabCompleted = true; + ignoreKey = true; + String id = getItemIdAtIndex(0); + if (id == null) { + tabCompleted = false; + textField.setFocus(true); + textField.setText(searchString); + } else { + tabCompletionIndex = 0; + searchString = id; + } + } + } + + if (Keyboard.getEventKeyState()) { + if (tabCompleted) { + if (!ignoreKey) { + boolean success = updateTabCompletedSearch(Keyboard.getEventKey()); + if (success) return; + textField.setFocus(true); + textField.setText(searchString); + tabCompleted = false; + tabCompletionIndex = -1; + } else return; + + } + textField.setFocus(true); + textField.setText(searchString); + textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); + searchString = textField.getText(); + + search(); + } + } + + public static void mouseEvent() { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + + int h = NotEnoughUpdates.INSTANCE.config.bazaarTweaks.showPastSearches ? 219 : 145; + + int topY = height / 4; + if (scaledResolution.getScaleFactor() >= 4) { + topY = height / 2 - h / 2 + 5; + } + + if (!Mouse.getEventButtonState() && Mouse.getEventButton() == -1 && searchFieldClicked) { + textField.mouseClickMove(mouseX - 2, topY + 10, 0, 0); + } + + if (Mouse.getEventButton() != -1) { + searchFieldClicked = false; + } + + if (Mouse.getEventButtonState()) { + if (mouseY > topY && mouseY < topY + 20) { + if (mouseX > width / 2 - 100) { + if (mouseX < width / 2 + 49) { + searchFieldClicked = true; + textField.mouseClicked(mouseX - 2, mouseY, Mouse.getEventButton()); + + if (Mouse.getEventButton() == 1) { + searchString = ""; + synchronized (autocompletedItems) { + autocompletedItems.clear(); + } + } + } else if (mouseX < width / 2 + 75) { + searchStringExtra = ""; + close(); + } else if (mouseX < width / 2 + 100) { + searchStringExtra = ""; + close(); + Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow(Minecraft.getMinecraft().thePlayer.openContainer.windowId)); + NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(new NEUConfigEditor( + NotEnoughUpdates.INSTANCE.config, "Bazaar Tweaks")); + } + } + } else if (Mouse.getEventButton() == 0) { + int num = 0; + synchronized (autocompletedItems) { + for (String str : autocompletedItems) { + JsonObject obj = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(str); + if (obj != null) { + ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(obj); + if (mouseX >= width / 2 - 96 && mouseX <= width / 2 + 96 && mouseY >= topY + 30 + num * 22 && + mouseY <= topY + 30 + num * 22 + 20) { + searchString = Utils.cleanColour(stack.getDisplayName().replaceAll("\\[.+]", "")).trim(); + if (searchString.contains("Enchanted Book") && str.contains(";")) { + String[] lore = NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound()); + if (lore != null) { + searchString = Utils.cleanColour(lore[0]); + } + } + + searchStringExtra = " "; + + close(); + return; + } + + if (++num >= 5) break; + } + } + } + + if (NotEnoughUpdates.INSTANCE.config.bazaarTweaks.showPastSearches) { + for (int i = 0; i < 5; i++) { + if (i >= NotEnoughUpdates.INSTANCE.config.hidden.previousBazaarSearches.size()) break; + + String s = NotEnoughUpdates.INSTANCE.config.hidden.previousBazaarSearches.get(i); + if (mouseX >= width / 2 - 95 && mouseX <= width / 2 + 95 && + mouseY >= topY + 45 + AUTOCOMPLETE_HEIGHT + i * 10 && + mouseY <= topY + 45 + AUTOCOMPLETE_HEIGHT + i * 10 + 10) { + searchString = s; + searchStringExtra = ""; + close(); + return; + } + } + } + } + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java index 250be27d..4ad6767d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java @@ -41,6 +41,10 @@ public class CombatSkillOverlay private long lastUpdate = -1; private int killLast = -1; private int kill = -1; + private int championTier = -1; + private String championTierAmount = "1"; + private int championXp = -1; + private int championXpLast = -1; private final LinkedList killQueue = new LinkedList<>(); private XPInformation.SkillInfo skillInfo = null; @@ -84,6 +88,7 @@ public class CombatSkillOverlay lastUpdate = System.currentTimeMillis(); killLast = kill; + championXpLast = championXp; xpGainHourLast = xpGainHour; kill = -1; @@ -100,9 +105,67 @@ public class CombatSkillOverlay kill = ea.getInteger("stats_book"); killQueue.add(0, kill); } + if (ea.hasKey("champion_combat_xp", 99)) { + championXp = (int) ea.getDouble("champion_combat_xp"); + } } } + if (championXp < 50000) { + championTier = 1; + } else if (championXp < 100000) { + championTier = 2; + } else if (championXp < 250000) { + championTier = 3; + } else if (championXp < 500000) { + championTier = 4; + } else if (championXp < 1000000) { + championTier = 5; + } else if (championXp < 1500000) { + championTier = 6; + } else if (championXp < 2000000) { + championTier = 7; + } else if (championXp < 2500000) { + championTier = 8; + } else if (championXp < 3000000) { + championTier = 9; + } else if (championXp > 3000000) { + championTier = 10; + } + + switch (championTier) { + case 1: + championTierAmount = "50,000"; + break; + case 2: + championTierAmount = "100,000"; + break; + case 3: + championTierAmount = "250,000"; + break; + case 4: + championTierAmount = "500,000"; + break; + case 5: + championTierAmount = "1,000,000"; + break; + case 6: + championTierAmount = "1,500,000"; + break; + case 7: + championTierAmount = "2,000,000"; + break; + case 8: + championTierAmount = "2,500,000"; + break; + case 9: + championTierAmount = "3,000,000"; + break; + case 10: + championTierAmount = "Maxed"; + break; + } + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); skillInfoLast = skillInfo; @@ -165,7 +228,7 @@ public class CombatSkillOverlay public void updateFrequent() { super.updateFrequent(); - if (kill < 0 && !NotEnoughUpdates.INSTANCE.config.skillOverlays.alwaysShowCombatOverlay) { + if ((kill < 0 || championXp < 0) && !NotEnoughUpdates.INSTANCE.config.skillOverlays.alwaysShowCombatOverlay) { overlayStrings = null; } else { HashMap lineMap = new HashMap<>(); @@ -180,6 +243,23 @@ public class CombatSkillOverlay lineMap.put(0, EnumChatFormatting.AQUA + "Kills: " + EnumChatFormatting.YELLOW + format.format(counterInterp)); } + if (championTier <= 9) { + int counterInterp = (int) interp(championXp, championXpLast); + lineMap.put( + 6, + EnumChatFormatting.AQUA + "Champion: " + EnumChatFormatting.YELLOW + format.format(counterInterp) + "/" + + championTierAmount + ); + } + if (championTier == 10) { + int counterInterp = (int) interp(championXp, championXpLast); + lineMap.put( + 6, + EnumChatFormatting.AQUA + "Champion: " + EnumChatFormatting.YELLOW + format.format(counterInterp) + " " + + EnumChatFormatting.RED + championTierAmount + ); + } + float xpInterp = xpGainHour; if (xpGainHourLast == xpGainHour && xpGainHour <= 0) { lineMap.put(4, EnumChatFormatting.AQUA + "XP/h: " + EnumChatFormatting.YELLOW + "N/A"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java index dcbcb9e4..a72e0a24 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java @@ -25,6 +25,7 @@ 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.core.util.StringUtils; 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; @@ -617,9 +618,9 @@ public class BasicPage extends GuiProfileViewerPage { EnumChatFormatting.GRAY + "Progress: " + EnumChatFormatting.DARK_PURPLE + - GuiProfileViewer.shortNumberFormat(Math.round((level % 1) * maxXp), 0) + + StringUtils.shortNumberFormat(Math.round((level % 1) * maxXp)) + "/" + - GuiProfileViewer.shortNumberFormat(maxXp, 0) + StringUtils.shortNumberFormat(maxXp) ); } String totalXpS = GuiProfileViewer.numberFormat.format((int) skyblockInfo.get(entry.getKey()).totalXp); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java index b227c815..554e204c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java @@ -21,15 +21,9 @@ package io.github.moulberry.notenoughupdates.profileviewer; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; -import java.awt.*; -import java.io.IOException; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.item.ItemStack; @@ -39,6 +33,14 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import java.awt.*; +import java.io.IOException; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; + public class CollectionsPage extends GuiProfileViewerPage { public static final ResourceLocation pv_cols = new ResourceLocation("notenoughupdates:pv_cols.png"); @@ -290,7 +292,7 @@ public class CollectionsPage extends GuiProfileViewerPage { } Utils.drawStringCentered( - GuiProfileViewer.shortNumberFormat(amount, 0) + "", + StringUtils.shortNumberFormat(amount) + "", Minecraft.getMinecraft().fontRendererObj, guiLeft + x + 10, guiTop + y + 26, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/DungeonPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/DungeonPage.java index 73bbd295..c707f7fc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/DungeonPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/DungeonPage.java @@ -25,14 +25,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; -import java.io.IOException; -import java.util.Base64; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.UUID; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.GlStateManager; @@ -48,6 +44,12 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; +import java.io.IOException; +import java.util.Base64; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.UUID; + public class DungeonPage extends GuiProfileViewerPage { private static final ResourceLocation pv_dung = new ResourceLocation("notenoughupdates:pv_dung.png"); @@ -172,7 +174,7 @@ public class DungeonPage extends GuiProfileViewerPage { Utils.renderAlignedString( EnumChatFormatting.YELLOW + "Until Cata " + floorLevelTo + ": ", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(floorLevelToXP, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat((double) floorLevelToXP), x, y + 16, sectionWidth @@ -222,9 +224,9 @@ public class DungeonPage extends GuiProfileViewerPage { getInstance().tooltipToDisplay = Lists.newArrayList( - String.format("# F5 Runs (%s xp) : %d", GuiProfileViewer.shortNumberFormat(xpF5, 0), runsF5), - String.format("# F6 Runs (%s xp) : %d", GuiProfileViewer.shortNumberFormat(xpF6, 0), runsF6), - String.format("# F7 Runs (%s xp) : %d", GuiProfileViewer.shortNumberFormat(xpF7, 0), runsF7), + String.format("# F5 Runs (%s xp) : %d", StringUtils.shortNumberFormat(xpF5), runsF5), + String.format("# F6 Runs (%s xp) : %d", StringUtils.shortNumberFormat(xpF6), runsF6), + String.format("# F7 Runs (%s xp) : %d", StringUtils.shortNumberFormat(xpF7), runsF7), "" ); boolean hasTime = false; @@ -352,10 +354,10 @@ public class DungeonPage extends GuiProfileViewerPage { getInstance().tooltipToDisplay = Lists.newArrayList( - String.format("# M3 Runs (%s xp) : %d", GuiProfileViewer.shortNumberFormat(xpM3, 0), runsM3), - String.format("# M4 Runs (%s xp) : %d", GuiProfileViewer.shortNumberFormat(xpM4, 0), runsM4), - String.format("# M5 Runs (%s xp) : %d", GuiProfileViewer.shortNumberFormat(xpM5, 0), runsM5), - String.format("# M6 Runs (%s xp) : %d", GuiProfileViewer.shortNumberFormat(xpM6, 0), runsM6), + String.format("# M3 Runs (%s xp) : %d", StringUtils.shortNumberFormat(xpM3), runsM3), + String.format("# M4 Runs (%s xp) : %d", StringUtils.shortNumberFormat(xpM4), runsM4), + String.format("# M5 Runs (%s xp) : %d", StringUtils.shortNumberFormat(xpM5), runsM5), + String.format("# M6 Runs (%s xp) : %d", StringUtils.shortNumberFormat(xpM6), runsM6), "" ); boolean hasTime = false; @@ -482,7 +484,7 @@ public class DungeonPage extends GuiProfileViewerPage { ); Utils.renderAlignedString( EnumChatFormatting.YELLOW + "Secrets (Total) ", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(secrets, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(secrets), x, miscTopY + 20, sectionWidth @@ -496,7 +498,7 @@ public class DungeonPage extends GuiProfileViewerPage { ); Utils.renderAlignedString( EnumChatFormatting.YELLOW + "Mob Kills (Total) ", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(mobKills, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(mobKills), x, miscTopY + 40, sectionWidth diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java index 3cbd944d..63a4df2c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java @@ -22,10 +22,15 @@ package io.github.moulberry.notenoughupdates.profileviewer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.util.Constants; -import io.github.moulberry.notenoughupdates.util.PronounDB; import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import org.apache.commons.lang3.text.WordUtils; +import org.lwjgl.opengl.GL11; + import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; @@ -34,15 +39,9 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.TimeZone; import java.util.TreeMap; -import net.minecraft.client.Minecraft; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.ResourceLocation; -import org.apache.commons.lang3.text.WordUtils; -import org.lwjgl.opengl.GL11; public class ExtraPage extends GuiProfileViewerPage { @@ -79,14 +78,14 @@ public class ExtraPage extends GuiProfileViewerPage { Utils.renderAlignedString( EnumChatFormatting.GOLD + "Bank Balance", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(bankBalance, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(bankBalance), guiLeft + xStart, guiTop + yStartTop, 76 ); Utils.renderAlignedString( EnumChatFormatting.GOLD + "Purse", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(purseBalance, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(purseBalance), guiLeft + xStart, guiTop + yStartTop + yOffset, 76 @@ -161,7 +160,17 @@ public class ExtraPage extends GuiProfileViewerPage { float totalSlayerCount = 0; float totalSlayerXP = 0; - List skills = Arrays.asList("taming", "mining", "foraging", "enchanting", "farming", "combat", "fishing", "alchemy"); + List skills = Arrays.asList( + "taming", + "mining", + "foraging", + "enchanting", + "farming", + "combat", + "fishing", + "alchemy", + "carpentry" + ); List slayers = Arrays.asList("zombie", "spider", "wolf", "enderman", "blaze"); for (Map.Entry entry : skyblockInfo.entrySet()) { @@ -206,7 +215,7 @@ public class ExtraPage extends GuiProfileViewerPage { Utils.renderAlignedString( EnumChatFormatting.RED + "Total Slayer XP", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(totalSlayerXP, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(totalSlayerXP), guiLeft + xStart, guiTop + yStartBottom + yOffset * 4, 76 @@ -214,11 +223,17 @@ public class ExtraPage extends GuiProfileViewerPage { } float auctions_bids = Utils.getElementAsFloat(Utils.getElement(profileInfo, "stats.auctions_bids"), 0); - float auctions_highest_bid = Utils.getElementAsFloat(Utils.getElement(profileInfo, "stats.auctions_highest_bid"), 0); + float auctions_highest_bid = Utils.getElementAsFloat( + Utils.getElement(profileInfo, "stats.auctions_highest_bid"), + 0 + ); float auctions_won = Utils.getElementAsFloat(Utils.getElement(profileInfo, "stats.auctions_won"), 0); float auctions_created = Utils.getElementAsFloat(Utils.getElement(profileInfo, "stats.auctions_created"), 0); float auctions_gold_spent = Utils.getElementAsFloat(Utils.getElement(profileInfo, "stats.auctions_gold_spent"), 0); - float auctions_gold_earned = Utils.getElementAsFloat(Utils.getElement(profileInfo, "stats.auctions_gold_earned"), 0); + float auctions_gold_earned = Utils.getElementAsFloat( + Utils.getElement(profileInfo, "stats.auctions_gold_earned"), + 0 + ); Utils.renderAlignedString( EnumChatFormatting.DARK_PURPLE + "Auction Bids", @@ -229,7 +244,7 @@ public class ExtraPage extends GuiProfileViewerPage { ); Utils.renderAlignedString( EnumChatFormatting.DARK_PURPLE + "Highest Bid", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(auctions_highest_bid, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(auctions_highest_bid), guiLeft + xStart + xOffset, guiTop + yStartTop + yOffset, 76 @@ -250,14 +265,14 @@ public class ExtraPage extends GuiProfileViewerPage { ); Utils.renderAlignedString( EnumChatFormatting.DARK_PURPLE + "Gold Spent", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(auctions_gold_spent, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(auctions_gold_spent), guiLeft + xStart + xOffset, guiTop + yStartTop + yOffset * 4, 76 ); Utils.renderAlignedString( EnumChatFormatting.DARK_PURPLE + "Gold Earned", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(auctions_gold_earned, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(auctions_gold_earned), guiLeft + xStart + xOffset, guiTop + yStartTop + yOffset * 5, 76 @@ -276,8 +291,14 @@ public class ExtraPage extends GuiProfileViewerPage { Utils.getElement(profileInfo, "slayer_bosses.zombie.boss_kills_tier_4"), 0 ); - float wolf_boss_kills_tier_2 = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.wolf.boss_kills_tier_2"), 0); - float wolf_boss_kills_tier_3 = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.wolf.boss_kills_tier_3"), 0); + float wolf_boss_kills_tier_2 = Utils.getElementAsFloat(Utils.getElement( + profileInfo, + "slayer_bosses.wolf.boss_kills_tier_2" + ), 0); + float wolf_boss_kills_tier_3 = Utils.getElementAsFloat(Utils.getElement( + profileInfo, + "slayer_bosses.wolf.boss_kills_tier_3" + ), 0); float spider_boss_kills_tier_2 = Utils.getElementAsFloat( Utils.getElement(profileInfo, "slayer_bosses.spider.boss_kills_tier_2"), 0 @@ -294,8 +315,14 @@ public class ExtraPage extends GuiProfileViewerPage { Utils.getElement(profileInfo, "slayer_bosses.enderman.boss_kills_tier_3"), 0 ); - float blaze_boss_kills_tier_2 = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.blaze.boss_kills_tier_2"), 0); - float blaze_boss_kills_tier_3 = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.blaze.boss_kills_tier_3"), 0); + float blaze_boss_kills_tier_2 = Utils.getElementAsFloat(Utils.getElement( + profileInfo, + "slayer_bosses.blaze.boss_kills_tier_2" + ), 0); + float blaze_boss_kills_tier_3 = Utils.getElementAsFloat(Utils.getElement( + profileInfo, + "slayer_bosses.blaze.boss_kills_tier_3" + ), 0); Utils.renderAlignedString( EnumChatFormatting.DARK_AQUA + "Revenant T3", @@ -376,15 +403,24 @@ public class ExtraPage extends GuiProfileViewerPage { 76 ); - float pet_milestone_ores_mined = Utils.getElementAsFloat(Utils.getElement(profileInfo, "stats.pet_milestone_ores_mined"), 0); + float pet_milestone_ores_mined = Utils.getElementAsFloat(Utils.getElement( + profileInfo, + "stats.pet_milestone_ores_mined" + ), 0); float pet_milestone_sea_creatures_killed = Utils.getElementAsFloat( Utils.getElement(profileInfo, "stats.pet_milestone_sea_creatures_killed"), 0 ); float items_fished = Utils.getElementAsFloat(Utils.getElement(profileInfo, "stats.items_fished"), 0); - float items_fished_treasure = Utils.getElementAsFloat(Utils.getElement(profileInfo, "stats.items_fished_treasure"), 0); - float items_fished_large_treasure = Utils.getElementAsFloat(Utils.getElement(profileInfo, "stats.items_fished_large_treasure"), 0); + float items_fished_treasure = Utils.getElementAsFloat( + Utils.getElement(profileInfo, "stats.items_fished_treasure"), + 0 + ); + float items_fished_large_treasure = Utils.getElementAsFloat(Utils.getElement( + profileInfo, + "stats.items_fished_large_treasure" + ), 0); Utils.renderAlignedString( EnumChatFormatting.GREEN + "Ores Mined", 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 59373952..0f9d1b4a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -23,6 +23,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.cosmetics.ShaderManager; import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; @@ -283,20 +284,9 @@ public class GuiProfileViewer extends GuiScreen { return levelObj; } + @Deprecated public static String shortNumberFormat(double n, int iteration) { - if (n < 1000) { - if (n % 1 == 0) { - return Integer.toString((int) n); - } else { - return String.format("%.2f", n); - } - } - - double d = ((long) n / 100) / 10.0; - boolean isRound = (d * 10) % 10 == 0; - return d < 1000 ? (isRound || d > 9.99 ? (int) d * 10 / 10 : d + "") + "" + c[iteration] : shortNumberFormat( - d, - iteration + 1 + return StringUtils.shortNumberFormat(n, iteration ); } @@ -1013,9 +1003,9 @@ public class GuiProfileViewer extends GuiScreen { int maxXp = (int) levelObj.maxXpForLevel; levelStr = EnumChatFormatting.DARK_PURPLE + - shortNumberFormat(Math.round((level % 1) * maxXp), 0) + + StringUtils.shortNumberFormat(Math.round((level % 1) * maxXp)) + "/" + - shortNumberFormat(maxXp, 0); + StringUtils.shortNumberFormat(maxXp); } if (totalXpStr != null) { tooltipToDisplay = Utils.createList(levelStr, totalXpStr); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java index 8bba9c76..c98792ee 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java @@ -23,6 +23,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.profileviewer.info.QuiverInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -57,13 +58,15 @@ import static io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewe public class InventoriesPage extends GuiProfileViewerPage { public static final ResourceLocation pv_invs = new ResourceLocation("notenoughupdates:pv_invs.png"); - private static final Pattern DAMAGE_PATTERN = Pattern.compile("^Damage: \\+(\\d+)"); - private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("textures/gui/container/generic_54.png"); - private static final Pattern STRENGTH_PATTERN = Pattern.compile("^Strength: \\+(\\d+)"); - private static final Pattern FISHSPEED_PATTERN = Pattern.compile("^Increases fishing speed by \\+(\\d+)"); + private static final ResourceLocation CHEST_GUI_TEXTURE = + new ResourceLocation("textures/gui/container/generic_54.png"); + private static final Pattern FISHING_SPEED_PATTERN = Pattern.compile("^Fishing Speed: \\+(\\d+)"); private static final LinkedHashMap invNameToDisplayMap = new LinkedHashMap() { { - put("inv_contents", Utils.createItemStack(Item.getItemFromBlock(Blocks.chest), EnumChatFormatting.GRAY + "Inventory")); + put( + "inv_contents", + Utils.createItemStack(Item.getItemFromBlock(Blocks.chest), EnumChatFormatting.GRAY + "Inventory") + ); put( "ender_chest_contents", Utils.createItemStack(Item.getItemFromBlock(Blocks.ender_chest), EnumChatFormatting.GRAY + "Ender Chest") @@ -82,7 +85,9 @@ public class InventoriesPage extends GuiProfileViewerPage { put( "personal_vault_contents", Utils.editItemStackInfo( - NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager.getItemInformation().get("IRON_CHEST")), + NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager + .getItemInformation() + .get("IRON_CHEST")), EnumChatFormatting.GRAY + "Personal Vault", true ) @@ -263,21 +268,18 @@ public class InventoriesPage extends GuiProfileViewerPage { findBestItems( inventoryInfo, 6, - new String[] { "inv_contents", "ender_chest_contents" }, - new String[] { "SWORD", "BOW" }, - DAMAGE_PATTERN, - STRENGTH_PATTERN + new String[]{"inv_contents", "ender_chest_contents"}, + new String[]{"SWORD", "BOW"} ); } if (bestRods == null) { - bestRods = - findBestItems( - inventoryInfo, - 3, - new String[] { "inv_contents", "ender_chest_contents" }, - new String[] { "FISHING ROD" }, - FISHSPEED_PATTERN - ); + bestRods = findBestItems( + inventoryInfo, + 3, + new String[]{"inv_contents", "ender_chest_contents"}, + new String[]{"FISHING ROD", "FISHING WEAPON"}, + FISHING_SPEED_PATTERN + ); } for (int i = 0; i < bestWeapons.length; i++) { @@ -313,21 +315,27 @@ public class InventoriesPage extends GuiProfileViewerPage { } Utils.drawItemStackWithText( - NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager.getItemInformation().get("ARROW")), + NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager + .getItemInformation() + .get("ARROW")), guiLeft + 173, guiTop + 101, - "" + (arrowCount > 999 ? GuiProfileViewer.shortNumberFormat(arrowCount, 0) : arrowCount), + "" + (arrowCount > 999 ? StringUtils.shortNumberFormat(arrowCount) : arrowCount), true ); Utils.drawItemStackWithText( - NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager.getItemInformation().get("GREEN_CANDY")), + NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager + .getItemInformation() + .get("GREEN_CANDY")), guiLeft + 173, guiTop + 119, "" + greenCandyCount, true ); Utils.drawItemStackWithText( - NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager.getItemInformation().get("PURPLE_CANDY")), + NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager + .getItemInformation() + .get("PURPLE_CANDY")), guiLeft + 173, guiTop + 137, "" + purpleCandyCount, @@ -344,7 +352,8 @@ public class InventoriesPage extends GuiProfileViewerPage { } } else if (mouseY < guiTop + 119 + 17) { getInstance().tooltipToDisplay = - Utils.createList(EnumChatFormatting.GREEN + "Green Candy " + EnumChatFormatting.GRAY + "x" + greenCandyCount); + Utils.createList( + EnumChatFormatting.GREEN + "Green Candy " + EnumChatFormatting.GRAY + "x" + greenCandyCount); } else { getInstance().tooltipToDisplay = Utils.createList( @@ -431,11 +440,14 @@ public class InventoriesPage extends GuiProfileViewerPage { if ( getInstance().inventoryTextField.getText() != null && - !getInstance().inventoryTextField.getText().isEmpty() && - ( - stack == null || - !NotEnoughUpdates.INSTANCE.manager.doesStackMatchSearch(stack, getInstance().inventoryTextField.getText()) - ) + !getInstance().inventoryTextField.getText().isEmpty() && + ( + stack == null || + !NotEnoughUpdates.INSTANCE.manager.doesStackMatchSearch( + stack, + getInstance().inventoryTextField.getText() + ) + ) ) { GlStateManager.translate(0, 0, 50); GuiScreen.drawRect( @@ -585,7 +597,12 @@ public class InventoriesPage extends GuiProfileViewerPage { purpleCandyCount = -1; } - private int countItemsInInventory(String internalname, JsonObject inventoryInfo, boolean specific, String... invsToSearch) { + private int countItemsInInventory( + String internalname, + JsonObject inventoryInfo, + boolean specific, + String... invsToSearch + ) { int count = 0; for (String inv : invsToSearch) { JsonArray invItems = inventoryInfo.get(inv).getAsJsonArray(); @@ -594,7 +611,7 @@ public class InventoriesPage extends GuiProfileViewerPage { JsonObject item = invItems.get(i).getAsJsonObject(); if ( (specific && item.get("internalname").getAsString().equals(internalname)) || - (!specific && item.get("internalname").getAsString().contains(internalname)) + (!specific && item.get("internalname").getAsString().contains(internalname)) ) { if (item.has("count")) { count += item.get("count").getAsInt(); @@ -615,7 +632,7 @@ public class InventoriesPage extends GuiProfileViewerPage { Pattern... importantPatterns ) { ItemStack[] bestItems = new ItemStack[numItems]; - TreeMap> map = new TreeMap<>(); + TreeMap> map = new TreeMap<>(); for (String inv : invsToSearch) { JsonArray invItems = inventoryInfo.get(inv).getAsJsonArray(); for (int i = 0; i < invItems.size(); i++) { @@ -623,22 +640,33 @@ public class InventoriesPage extends GuiProfileViewerPage { JsonObject item = invItems.get(i).getAsJsonObject(); JsonArray lore = item.get("lore").getAsJsonArray(); if (Utils.checkItemType(lore, true, typeMatches) >= 0) { - int importance = 0; - for (int j = 0; j < lore.size(); j++) { - String line = lore.get(j).getAsString(); - for (Pattern pattern : importantPatterns) { - Matcher matcher = pattern.matcher(Utils.cleanColour(line)); - if (matcher.find()) { - importance += Integer.parseInt(matcher.group(1)); + long importance = 0; + int id = 0; + if (importantPatterns.length == 0) { + String internalName = item.get("internalname").getAsString(); + importance += NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalName); + importance += ++id; + } else { + for (int j = 0; j < lore.size(); j++) { + String line = lore.get(j).getAsString(); + for (Pattern pattern : importantPatterns) { + Matcher matcher = pattern.matcher(Utils.cleanColour(line)); + if (matcher.find()) { + importance += Integer.parseInt(matcher.group(1)); + } } } } - map.computeIfAbsent(importance, k -> new HashSet<>()).add(NotEnoughUpdates.INSTANCE.manager.jsonToStack(item, false)); + map.computeIfAbsent(importance, k -> new HashSet<>()).add(NotEnoughUpdates.INSTANCE.manager.jsonToStack( + item, + false + )); } } } int i = 0; - outer:for (int key : map.descendingKeySet()) { + outer: + for (long key : map.descendingKeySet()) { Set items = map.get(key); for (ItemStack item : items) { bestItems[i] = item; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java index c4c788e7..c32310b7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java @@ -22,12 +22,9 @@ package io.github.moulberry.notenoughupdates.profileviewer; import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Objects; -import java.util.function.Supplier; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; @@ -39,6 +36,11 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Objects; +import java.util.function.Supplier; + public class MiningPage extends GuiProfileViewerPage { public static final ResourceLocation pv_mining = new ResourceLocation("notenoughupdates:pv_mining.png"); @@ -222,28 +224,28 @@ public class MiningPage extends GuiProfileViewerPage { //Powder Utils.renderAlignedString( EnumChatFormatting.DARK_GREEN + "Mithril Powder", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(mithrilPowder, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(mithrilPowder), guiLeft + xStart, guiTop + yStartTop + 24, 115 ); Utils.renderAlignedString( EnumChatFormatting.LIGHT_PURPLE + "Gemstone Powder", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(gemstonePowder, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(gemstonePowder), guiLeft + xStart, guiTop + yStartTop + 44, 115 ); Utils.renderAlignedString( EnumChatFormatting.DARK_GREEN + "Total Mithril Powder", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(mithrilPowderTotal + mithrilPowder, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(mithrilPowderTotal + mithrilPowder), guiLeft + xStart, guiTop + yStartTop + 34, 115 ); Utils.renderAlignedString( EnumChatFormatting.LIGHT_PURPLE + "Total Gemstone Powder", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(gemstonePowderTotal + gemstonePowder, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(gemstonePowderTotal + gemstonePowder), guiLeft + xStart, guiTop + yStartTop + 54, 115 @@ -300,7 +302,7 @@ public class MiningPage extends GuiProfileViewerPage { ); Utils.renderAlignedString( EnumChatFormatting.BLUE + "Total Placed Crystals:", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(crystalPlacedAmount, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(crystalPlacedAmount), guiLeft + xStart, guiTop + yStartTop + 149, 110 diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java index 4214371c..25751ab8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java @@ -24,17 +24,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; 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.io.IOException; -import java.util.ArrayList; -import java.util.Base64; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; @@ -50,6 +43,15 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import java.awt.*; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Base64; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + public class PetsPage extends GuiProfileViewerPage { public static final ResourceLocation pv_pets = new ResourceLocation("notenoughupdates:pv_pets.png"); @@ -497,21 +499,21 @@ public class PetsPage extends GuiProfileViewerPage { Utils.renderAlignedString( EnumChatFormatting.YELLOW + "Total XP", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(exp, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(exp), guiLeft + 319, guiTop + 125, 98 ); Utils.renderAlignedString( EnumChatFormatting.YELLOW + "Current LVL XP", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat((level % 1) * currentLevelRequirement, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat((level % 1) * currentLevelRequirement), guiLeft + 319, guiTop + 143, 98 ); Utils.renderAlignedString( EnumChatFormatting.YELLOW + "Required LVL XP", - EnumChatFormatting.WHITE + GuiProfileViewer.shortNumberFormat(currentLevelRequirement, 0), + EnumChatFormatting.WHITE + StringUtils.shortNumberFormat(currentLevelRequirement), guiLeft + 319, guiTop + 161, 98 diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java index 3dc97a85..efa94ee5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java @@ -21,16 +21,12 @@ package io.github.moulberry.notenoughupdates.profileviewer.bestiary; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewerPage; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; -import java.awt.*; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -40,6 +36,12 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; +import java.awt.*; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + public class BestiaryPage extends GuiProfileViewerPage { public static final ResourceLocation pv_elements = new ResourceLocation("notenoughupdates:pv_elements.png"); @@ -200,10 +202,10 @@ public class BestiaryPage extends GuiProfileViewerPage { if (level.maxed) { progressStr = EnumChatFormatting.GOLD + "MAXED!"; } else { - progressStr = EnumChatFormatting.AQUA + - GuiProfileViewer.shortNumberFormat(Math.round((levelNum % 1) * level.maxXpForLevel), 0) + + progressStr =EnumChatFormatting.AQUA + + StringUtils.shortNumberFormat(Math.round((levelNum % 1) * level.maxXpForLevel)) + "/" + - GuiProfileViewer.shortNumberFormat(level.maxXpForLevel, 0); + StringUtils.shortNumberFormat(level.maxXpForLevel); } tooltipToDisplay.add(EnumChatFormatting.GRAY + "Progress: " + progressStr); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java index 7d378a03..10bfa6a9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java @@ -25,10 +25,12 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; import java.util.List; +import java.util.Locale; import java.util.NoSuchElementException; public class Calculator { public static BigDecimal calculate(String source) throws CalculatorException { + source = source.toLowerCase(Locale.ROOT); return evaluate(shuntingYard(lex(source))); } diff --git a/src/main/resources/mixins.notenoughupdates.json b/src/main/resources/mixins.notenoughupdates.json index ed1ba55a..0a547b4b 100644 --- a/src/main/resources/mixins.notenoughupdates.json +++ b/src/main/resources/mixins.notenoughupdates.json @@ -40,6 +40,7 @@ "MixinRenderGlobal", "MixinRenderItem", "MixinRenderList", + "MixinSkyclientCosmetics", "MixinTextureManager", "MixinTileEntitySkullRenderer", "MixinTileEntitySpecialRenderer", -- cgit From d1488df319a1d19154d294cb29627b9026deb564 Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Thu, 8 Sep 2022 18:18:21 +0200 Subject: Fix Collections display getting very unresponsive after some time (#261) * Update Gradle wrapper properly * Fix Collections display getting very unresponsive after some time --- gradle/wrapper/gradle-wrapper.jar | Bin 52271 -> 60756 bytes gradle/wrapper/gradle-wrapper.properties | 3 +- gradlew | 298 +++++++++++++-------- gradlew.bat | 65 ++--- .../profileviewer/ProfileViewer.java | 2 + 5 files changed, 223 insertions(+), 145 deletions(-) (limited to 'src/main') diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 30d399d8..249e5832 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index eed1d25a..ae04661e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Mon Sep 14 12:28:28 PDT 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip diff --git a/gradlew b/gradlew index 91a7e269..a69d9cb6 100755 --- a/gradlew +++ b/gradlew @@ -1,79 +1,129 @@ -#!/usr/bin/env bash +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum -warn ( ) { +warn () { echo "$*" -} +} >&2 -die ( ) { +die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -82,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -90,75 +140,101 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 8a0b282a..f127cfd4 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,4 +1,20 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -8,20 +24,23 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,44 +64,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal 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 bcec7526..b6e56743 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -1414,6 +1414,8 @@ public class ProfileViewer { collectionInfo.add("total_amounts", totalAmounts); collectionInfo.add("collection_tiers", collectionTiers); + collectionInfoMap.put(profileName, collectionInfo); + return collectionInfo; } -- cgit