diff options
| author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-09-08 17:00:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-08 17:00:49 +0200 |
| commit | d3805f080af87eb2bc7d2a2eac6c3f8db539324f (patch) | |
| tree | 2aaf95a14d1cb82096c1c2d675ebe6b7147dab48 /src/main/java/io | |
| parent | 827acac6fcf836c1dba5bea338f726694951d18e (diff) | |
| download | NotEnoughUpdates-d3805f080af87eb2bc7d2a2eac6c3f8db539324f.tar.gz NotEnoughUpdates-d3805f080af87eb2bc7d2a2eac6c3f8db539324f.tar.bz2 NotEnoughUpdates-d3805f080af87eb2bc7d2a2eac6c3f8db539324f.zip | |
0.14 - Finished :) (#233)
Co-authored-by: nopo <noahogno@gmail.com>
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 <lulonaut@tutanota.de>
Diffstat (limited to 'src/main/java/io')
37 files changed, 1563 insertions, 178 deletions
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 <https://www.gnu.org/licenses/>. + */ + +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<String> 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 <https://www.gnu.org/licenses/>. + */ + +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<String, Integer> dungeonData = new LinkedHashMap<>(); + private final Map<String, LinkedHashMap<String, Integer>> 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<String> 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<String> 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") || + !levelin |
