aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-09-04 10:14:25 +0200
committerLorenz <lo.scherf@gmail.com>2022-09-04 10:14:25 +0200
commit7cf59589d03388b63740a9c02d097cc405f82d8d (patch)
tree451a6ae218652f6c498e928a705a1a5bf84747c2
parent05ac31a02857d1baf94c0db26663e33e388b9165 (diff)
downloadNotEnoughUpdates-7cf59589d03388b63740a9c02d097cc405f82d8d.tar.gz
NotEnoughUpdates-7cf59589d03388b63740a9c02d097cc405f82d8d.tar.bz2
NotEnoughUpdates-7cf59589d03388b63740a9c02d097cc405f82d8d.zip
added support for decimal numbers
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java22
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java5
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java29
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java6
4 files changed, 34 insertions, 28 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java
index c362fd15..ff9b4ac7 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java
@@ -188,13 +188,13 @@ public class MinionHelperOverlay {
}
}
- private Map<Minion, Long> getMissing() {
- Map<Minion, Long> prices = new HashMap<>();
+ private Map<Minion, Double> getMissing() {
+ Map<Minion, Double> prices = new HashMap<>();
for (Minion minion : manager.getAllMinions().values()) {
if (!minion.doesMeetRequirements() && showOnlyAvailable) continue;
if (!minion.isCrafted()) {
- long price = manager.getPriceCalculation().calculateUpgradeCosts(minion, true);
+ double price = manager.getPriceCalculation().calculateUpgradeCosts(minion, true);
prices.put(minion, price);
}
}
@@ -247,7 +247,7 @@ public class MinionHelperOverlay {
private LinkedHashMap<String, OverviewLine> getRenderMap() {
if (cacheRenderMap != null) return cacheRenderMap;
- Map<Minion, Long> prices = getMissing();
+ Map<Minion, Double> prices = getMissing();
LinkedHashMap<String, OverviewLine> renderMap = new LinkedHashMap<>();
addTitle(prices, renderMap);
@@ -262,7 +262,7 @@ public class MinionHelperOverlay {
}
private void addNeedToNextSlot(
- Map<Minion, Long> prices,
+ Map<Minion, Double> prices,
LinkedHashMap<String, OverviewLine> renderMap
) {
int neededForNextSlot = manager.getNeedForNextSlot();
@@ -272,9 +272,9 @@ public class MinionHelperOverlay {
return;
}
- long priceNeeded = 0;
+ double priceNeeded = 0;
int index = 0;
- for (Long price : TrophyRewardOverlay.sortByValue(prices).values()) {
+ for (Double price : TrophyRewardOverlay.sortByValue(prices).values()) {
priceNeeded += price;
index++;
if (index == neededForNextSlot) break;
@@ -285,15 +285,15 @@ public class MinionHelperOverlay {
renderMap.put(text, new OverviewText(Collections.emptyList(), () -> {}));
}
- private void addTitle(Map<Minion, Long> prices, LinkedHashMap<String, OverviewLine> renderMap) {
+ private void addTitle(Map<Minion, Double> prices, LinkedHashMap<String, OverviewLine> renderMap) {
String name = "§8" + prices.size() + " " + (showOnlyAvailable ? "craftable" : "total") + " minions";
renderMap.put(name, new OverviewText(Collections.emptyList(), () -> {}));
}
- private void addMinions(Map<Minion, Long> prices, LinkedHashMap<String, OverviewLine> renderMap) {
+ private void addMinions(Map<Minion, Double> prices, LinkedHashMap<String, OverviewLine> renderMap) {
int skipPreviousPages = currentPage * maxPerPage;
int i = 0;
- Map<Minion, Long> sort = TrophyRewardOverlay.sortByValue(prices);
+ Map<Minion, Double> sort = TrophyRewardOverlay.sortByValue(prices);
for (Minion minion : sort.keySet()) {
if (i >= skipPreviousPages) {
String displayName = minion.getDisplayName();
@@ -322,7 +322,7 @@ public class MinionHelperOverlay {
private int getTotalPages() {
if (cacheTotalPages != -1) return cacheTotalPages;
- Map<Minion, Long> prices = getMissing();
+ Map<Minion, Double> prices = getMissing();
int totalPages = (int) ((double) prices.size() / maxPerPage);
if (prices.size() % maxPerPage != 0) {
totalPages++;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java
index b17ae368..903c82a9 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java
@@ -236,9 +236,8 @@ public class MinionHelperOverlayHover {
}
String name = NotEnoughUpdates.INSTANCE.manager.getDisplayName(internalName);
- long price = manager.getPriceCalculation().getPrice(internalName);
- String priceFormat = manager.getPriceCalculation().formatCoins(
- price * amount);
+ double price = manager.getPriceCalculation().getPrice(internalName);
+ String priceFormat = manager.getPriceCalculation().formatCoins(price * amount);
lines.add(" §8- §a" + amount + "§7x §f" + name + " " + priceFormat);
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java
index 28ef0397..495aeaac 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java
@@ -71,7 +71,7 @@ public class MinionHelperPriceCalculation {
}
}
- long costs = calculateUpgradeCosts(minion, upgradeOnly);
+ double costs = calculateUpgradeCosts(minion, upgradeOnly);
String result = formatCoins(costs, !upgradeOnly ? "§o" : "");
if (source instanceof NpcSource) {
@@ -91,7 +91,7 @@ public class MinionHelperPriceCalculation {
return result;
}
- public long calculateUpgradeCosts(Minion minion, boolean upgradeOnly) {
+ public double calculateUpgradeCosts(Minion minion, boolean upgradeOnly) {
MinionSource source = minion.getMinionSource();
if (upgradeOnly) {
@@ -106,7 +106,7 @@ public class MinionHelperPriceCalculation {
} else if (source instanceof NpcSource) {
NpcSource npcSource = (NpcSource) source;
- long upgradeCost = getCosts(minion, upgradeOnly, npcSource.getItems());
+ double upgradeCost = getCosts(minion, upgradeOnly, npcSource.getItems());
long coins = npcSource.getCoins();
upgradeCost += coins;
@@ -116,12 +116,12 @@ public class MinionHelperPriceCalculation {
return 0;
}
- private long getCosts(Minion minion, boolean upgradeOnly, ArrayListMultimap<String, Integer> items) {
- long upgradeCost = 0;
+ private double getCosts(Minion minion, boolean upgradeOnly, ArrayListMultimap<String, Integer> items) {
+ double upgradeCost = 0;
for (Map.Entry<String, Integer> entry : items.entries()) {
String internalName = entry.getKey();
if (internalName.equals("SKYBLOCK_PELT")) continue;
- long price = getPrice(internalName);
+ double price = getPrice(internalName);
int amount = entry.getValue();
upgradeCost += price * amount;
}
@@ -134,7 +134,7 @@ public class MinionHelperPriceCalculation {
return upgradeCost;
}
- public long getPrice(String internalName) {
+ public double getPrice(String internalName) {
//Is minion
if (internalName.contains("_GENERATOR_")) {
return calculateUpgradeCosts(manager.getMinionById(internalName), false);
@@ -147,28 +147,29 @@ public class MinionHelperPriceCalculation {
System.err.println("curr_sell does not exist for '" + internalName + "'");
return 0;
}
- return (long) bazaarInfo.get("curr_sell").getAsDouble();
+ return bazaarInfo.get("curr_sell").getAsDouble();
}
//is ah bin
- long avgBinPrice = (long) NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalName);
+ double avgBinPrice = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalName);
if (avgBinPrice >= 1) return avgBinPrice;
//is ah without bin
JsonObject auctionInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalName);
if (auctionInfo == null) {
//only wood axe and similar useless items
- return 0;
+ return 1;
}
- return (int) (auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat());
+ return (auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat());
}
- public String formatCoins(long coins) {
+ public String formatCoins(double coins) {
return formatCoins(coins, "");
}
- public String formatCoins(long coins, String extraFormat) {
- String format = Utils.shortNumberFormat(coins, 0);
+ public String formatCoins(double coins, String extraFormat) {
+ int i = coins < 3 ? 1 : 0;
+ String format = Utils.shortNumberFormat(coins, i);
return "§6" + extraFormat + format + " coins";
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
index ba1fcafa..a4da47f3 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
@@ -77,6 +77,7 @@ import java.math.BigInteger;
import java.nio.FloatBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -146,6 +147,7 @@ public class Utils {
public static Splitter PATH_SPLITTER = Splitter.on(".").omitEmptyStrings().limit(2);
private static ScaledResolution lastScale = new ScaledResolution(Minecraft.getMinecraft());
private static long startTime = 0;
+ private static DecimalFormat simpleDoubleFormat = new DecimalFormat("0.0");
public static <T> ArrayList<T> createList(T... values) {
ArrayList<T> list = new ArrayList<>();
@@ -328,6 +330,10 @@ public class Utils {
}
public static String shortNumberFormat(double n, int iteration) {
+ if (n < 3 && n > 0) {
+ return simpleDoubleFormat.format(n);
+ }
+
if (n < 1000 && iteration == 0) return "" + (int) n;
double d = ((long) n / 100) / 10.0;
boolean isRound = (d * 10) % 10 == 0;