aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorJulienraptor01 <julienraptor01@gmail.com>2024-07-18 10:12:11 +0200
committerGitHub <noreply@github.com>2024-07-18 16:12:11 +0800
commite2d64c18fdf3fea60a3d482dfd00bd8f49298f55 (patch)
tree88e1cca448eee8fceb6b33febb26637b8a94fa1e /src/main/java
parentcceaa38e7c1783d0446a50dbb09e42b8287e38d1 (diff)
downloadSkyblocker-e2d64c18fdf3fea60a3d482dfd00bd8f49298f55.tar.gz
Skyblocker-e2d64c18fdf3fea60a3d482dfd00bd8f49298f55.tar.bz2
Skyblocker-e2d64c18fdf3fea60a3d482dfd00bd8f49298f55.zip
make all formatting use static instances of numberformat using US locale (#765)
Co-authored-by: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/calculators/CalculatorCommand.java3
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/calculators/SignCalculator.java3
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java125
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/end/EndHudWidget.java30
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java3
5 files changed, 84 insertions, 80 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/calculators/CalculatorCommand.java b/src/main/java/de/hysky/skyblocker/skyblock/calculators/CalculatorCommand.java
index d103bcdd..4267aca9 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/calculators/CalculatorCommand.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/calculators/CalculatorCommand.java
@@ -15,6 +15,7 @@ import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import java.text.NumberFormat;
+import java.util.Locale;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
@@ -22,7 +23,7 @@ import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.lit
public class CalculatorCommand {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
- private static final NumberFormat FORMATTER = NumberFormat.getInstance();
+ private static final NumberFormat FORMATTER = NumberFormat.getInstance(Locale.US);
public static void init() {
ClientCommandRegistrationCallback.EVENT.register(CalculatorCommand::calculate);
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/calculators/SignCalculator.java b/src/main/java/de/hysky/skyblocker/skyblock/calculators/SignCalculator.java
index 0ddeb121..265073bb 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/calculators/SignCalculator.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/calculators/SignCalculator.java
@@ -8,10 +8,11 @@ import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import java.text.NumberFormat;
+import java.util.Locale;
public class SignCalculator {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
- private static final NumberFormat FORMATTER = NumberFormat.getInstance();
+ private static final NumberFormat FORMATTER = NumberFormat.getInstance(Locale.US);
private static String lastInput;
private static double output;
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java
index cd4db727..04f6536d 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java
@@ -23,8 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.jetbrains.annotations.Nullable;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
+import java.text.NumberFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -40,7 +39,20 @@ public class ChocolateFactorySolver extends ContainerSolver {
private static final Pattern PRESTIGE_REQUIREMENT_PATTERN = Pattern.compile("Chocolate this Prestige: ([\\d,]+) +Requires (\\S+) Chocolate this Prestige!");
private static final Pattern TIME_TOWER_STATUS_PATTERN = Pattern.compile("Status: (ACTIVE|INACTIVE)");
private static final Pattern TIME_TOWER_MULTIPLIER_PATTERN = Pattern.compile("by \\+([\\d.]+)x for \\dh\\.");
+ private static final NumberFormat DECIMAL_FORMAT = NumberFormat.getInstance(Locale.US);
+ //Slots, for ease of maintenance rather than using magic numbers everywhere.
+ private static final byte RABBITS_START = 28;
+ private static final byte RABBITS_END = 34;
+ private static final byte COACH_SLOT = 42;
+ private static final byte CHOCOLATE_SLOT = 13;
+ private static final byte CPS_SLOT = 45;
+ private static final byte PRESTIGE_SLOT = 27;
+ private static final byte TIME_TOWER_SLOT = 39;
+ private static final byte STRAY_RABBIT_START = 0;
+ private static final byte STRAY_RABBIT_END = 26;
+
+ // TODO: Convert to instance fields in #788
private static final ObjectArrayList<Rabbit> cpsIncreaseFactors = new ObjectArrayList<>(8);
private static long totalChocolate = -1L;
private static double totalCps = -1.0;
@@ -53,39 +65,15 @@ public class ChocolateFactorySolver extends ContainerSolver {
private static boolean isTimeTowerActive = false;
private static int bestUpgrade = -1;
private static int bestAffordableUpgrade = -1;
+
private static StraySound ding = StraySound.NONE;
- private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#,###.#", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
+ private static int dingTick = 0;
- @Override
- protected void reset() {
- cpsIncreaseFactors.clear();
- totalChocolate = -1L;
- totalCps = -1.0;
- totalCpsMultiplier = -1.0;
- requiredUntilNextPrestige = -1L;
- canPrestige = false;
- reachedMaxPrestige = false;
- timeTowerMultiplier = -1.0;
- isTimeTowerMaxed = false;
- isTimeTowerActive = false;
- bestUpgrade = -1;
- bestAffordableUpgrade = -1;
- ding = StraySound.NONE;
+ static {
+ DECIMAL_FORMAT.setMinimumFractionDigits(0);
+ DECIMAL_FORMAT.setMaximumFractionDigits(1);
}
- //Slots, for ease of maintenance rather than using magic numbers everywhere.
- private static final byte RABBITS_START = 28;
- private static final byte RABBITS_END = 34;
- private static final byte COACH_SLOT = 42;
- private static final byte CHOCOLATE_SLOT = 13;
- private static final byte CPS_SLOT = 45;
- private static final byte PRESTIGE_SLOT = 27;
- private static final byte TIME_TOWER_SLOT = 39;
- private static final byte STRAY_RABBIT_START = 0;
- private static final byte STRAY_RABBIT_END = 26;
-
- private static int dingTick = 0;
-
public ChocolateFactorySolver() {
super("^Chocolate Factory$"); //There are multiple screens that fit the pattern `^Chocolate Factory`, so the $ is required
ClientTickEvents.START_CLIENT_TICK.register(ChocolateFactorySolver::onTick);
@@ -133,7 +121,7 @@ public class ChocolateFactorySolver extends ContainerSolver {
return highlights;
}
- private static void updateFactoryInfo(Int2ObjectMap<ItemStack> slots) {
+ private void updateFactoryInfo(Int2ObjectMap<ItemStack> slots) {
cpsIncreaseFactors.clear();
for (int i = RABBITS_START; i <= RABBITS_END; i++) { // The 7 rabbits slots are in 28, 29, 30, 31, 32, 33 and 34.
@@ -190,7 +178,7 @@ public class ChocolateFactorySolver extends ContainerSolver {
cpsIncreaseFactors.sort(Comparator.comparingDouble(rabbit -> rabbit.cost() / rabbit.cpsIncrease())); //Ascending order, lower = better
}
- private static Optional<Rabbit> getCoach(ItemStack coachItem) {
+ private Optional<Rabbit> getCoach(ItemStack coachItem) {
if (!coachItem.isOf(Items.PLAYER_HEAD)) return Optional.empty();
String coachLore = ItemUtils.getConcatenatedLore(coachItem);
@@ -213,7 +201,7 @@ public class ChocolateFactorySolver extends ContainerSolver {
return Optional.of(new Rabbit(totalCps / totalCpsMultiplier * (nextCpsMultiplier.getAsDouble() - currentCpsMultiplier.getAsDouble()), cost.getAsLong(), COACH_SLOT));
}
- private static Optional<Rabbit> getRabbit(ItemStack item, int slot) {
+ private Optional<Rabbit> getRabbit(ItemStack item, int slot) {
String lore = ItemUtils.getConcatenatedLore(item);
Matcher cpsMatcher = CPS_INCREASE_PATTERN.matcher(lore);
OptionalInt currentCps = RegexUtils.getIntFromMatcher(cpsMatcher);
@@ -230,13 +218,13 @@ public class ChocolateFactorySolver extends ContainerSolver {
return Optional.of(new Rabbit((nextCps.getAsInt() - currentCps.getAsInt()) * (totalCpsMultiplier < 0 ? 1 : totalCpsMultiplier), cost.getAsLong(), slot));
}
- private static Optional<ColorHighlight> getPrestigeHighlight() {
+ private Optional<ColorHighlight> getPrestigeHighlight() {
if (reachedMaxPrestige) return Optional.empty();
if (canPrestige) return Optional.of(ColorHighlight.green(PRESTIGE_SLOT));
return Optional.of(ColorHighlight.red(PRESTIGE_SLOT));
}
- private static List<ColorHighlight> getStrayRabbitHighlight(Int2ObjectMap<ItemStack> slots) {
+ private List<ColorHighlight> getStrayRabbitHighlight(Int2ObjectMap<ItemStack> slots) {
ding = StraySound.NONE;
final List<ColorHighlight> highlights = new ArrayList<>();
for (byte i = STRAY_RABBIT_START; i <= STRAY_RABBIT_END; i++) {
@@ -251,7 +239,22 @@ public class ChocolateFactorySolver extends ContainerSolver {
return highlights;
}
- private record Rabbit(double cpsIncrease, long cost, int slot) {}
+ @Override
+ protected void reset() {
+ cpsIncreaseFactors.clear();
+ totalChocolate = -1L;
+ totalCps = -1.0;
+ totalCpsMultiplier = -1.0;
+ requiredUntilNextPrestige = -1L;
+ canPrestige = false;
+ reachedMaxPrestige = false;
+ timeTowerMultiplier = -1.0;
+ isTimeTowerMaxed = false;
+ isTimeTowerActive = false;
+ bestUpgrade = -1;
+ bestAffordableUpgrade = -1;
+ ding = StraySound.NONE;
+ }
private enum StraySound {
NONE,
@@ -259,6 +262,8 @@ public class ChocolateFactorySolver extends ContainerSolver {
GOLDEN
}
+ private record Rabbit(double cpsIncrease, long cost, int slot) {}
+
public static final class Tooltip extends TooltipAdder {
public Tooltip() {
super("^Chocolate Factory$", 0); //The priority doesn't really matter here as this is the only tooltip adder for the Chocolate Factory.
@@ -298,59 +303,59 @@ public class ChocolateFactorySolver extends ContainerSolver {
if (shouldAddLine) lines.add(lineIndex, LineSmoothener.createSmoothLine());
}
- private static boolean addUpgradeTimerToLore(List<Text> lines, long cost) {
+ private boolean addUpgradeTimerToLore(List<Text> lines, long cost) {
if (totalChocolate < 0L || totalCps < 0.0) return false;
lines.add(Text.empty()
- .append(Text.literal("Time until upgrade: ").formatted(Formatting.GRAY))
- .append(formatTime((cost - totalChocolate) / totalCps)));
+ .append(Text.literal("Time until upgrade: ").formatted(Formatting.GRAY))
+ .append(formatTime((cost - totalChocolate) / totalCps)));
return true;
}
- private static boolean addPrestigeTimerToLore(List<Text> lines) {
+ private boolean addPrestigeTimerToLore(List<Text> lines) {
if (totalCps < 0.0 || reachedMaxPrestige) return false;
if (requiredUntilNextPrestige > 0 && !canPrestige) {
lines.add(Text.empty()
- .append(Text.literal("Chocolate until next prestige: ").formatted(Formatting.GRAY))
- .append(Text.literal(DECIMAL_FORMAT.format(requiredUntilNextPrestige)).formatted(Formatting.GOLD)));
+ .append(Text.literal("Chocolate until next prestige: ").formatted(Formatting.GRAY))
+ .append(Text.literal(DECIMAL_FORMAT.format(requiredUntilNextPrestige)).formatted(Formatting.GOLD)));
}
lines.add(Text.empty() //Keep this outside of the `if` to match the format of the upgrade tooltips, that say "Time until upgrade: Now" when it's possible
- .append(Text.literal("Time until next prestige: ").formatted(Formatting.GRAY))
- .append(formatTime(requiredUntilNextPrestige / totalCps)));
+ .append(Text.literal("Time until next prestige: ").formatted(Formatting.GRAY))
+ .append(formatTime(requiredUntilNextPrestige / totalCps)));
return true;
}
- private static boolean addTimeTowerStatsToLore(List<Text> lines) {
+ private boolean addTimeTowerStatsToLore(List<Text> lines) {
if (totalCps < 0.0 || totalCpsMultiplier < 0.0 || timeTowerMultiplier < 0.0) return false;
lines.add(Text.literal("Current stats:").formatted(Formatting.GRAY));
lines.add(Text.empty()
- .append(Text.literal(" CPS increase: ").formatted(Formatting.GRAY))
- .append(Text.literal(DECIMAL_FORMAT.format(totalCps / totalCpsMultiplier * timeTowerMultiplier)).formatted(Formatting.GOLD)));
+ .append(Text.literal(" CPS increase: ").formatted(Formatting.GRAY))
+ .append(Text.literal(DECIMAL_FORMAT.format(totalCps / totalCpsMultiplier * timeTowerMultiplier)).formatted(Formatting.GOLD)));
lines.add(Text.empty()
- .append(Text.literal(" CPS when active: ").formatted(Formatting.GRAY))
- .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps : totalCps / totalCpsMultiplier * (timeTowerMultiplier + totalCpsMultiplier))).formatted(Formatting.GOLD)));
+ .append(Text.literal(" CPS when active: ").formatted(Formatting.GRAY))
+ .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps : totalCps / totalCpsMultiplier * (timeTowerMultiplier + totalCpsMultiplier))).formatted(Formatting.GOLD)));
if (!isTimeTowerMaxed) {
lines.add(Text.literal("Stats after upgrade:").formatted(Formatting.GRAY));
lines.add(Text.empty()
- .append(Text.literal(" CPS increase: ").formatted(Formatting.GRAY))
- .append(Text.literal(DECIMAL_FORMAT.format(totalCps / (totalCpsMultiplier) * (timeTowerMultiplier + 0.1))).formatted(Formatting.GOLD)));
+ .append(Text.literal(" CPS increase: ").formatted(Formatting.GRAY))
+ .append(Text.literal(DECIMAL_FORMAT.format(totalCps / (totalCpsMultiplier) * (timeTowerMultiplier + 0.1))).formatted(Formatting.GOLD)));
lines.add(Text.empty()
- .append(Text.literal(" CPS when active: ").formatted(Formatting.GRAY))
- .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps / totalCpsMultiplier * (totalCpsMultiplier + 0.1) : totalCps / totalCpsMultiplier * (timeTowerMultiplier + 0.1 + totalCpsMultiplier))).formatted(Formatting.GOLD)));
+ .append(Text.literal(" CPS when active: ").formatted(Formatting.GRAY))
+ .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps / totalCpsMultiplier * (totalCpsMultiplier + 0.1) : totalCps / totalCpsMultiplier * (timeTowerMultiplier + 0.1 + totalCpsMultiplier))).formatted(Formatting.GOLD)));
}
return true;
}
- private static boolean addRabbitStatsToLore(List<Text> lines, int slot) {
+ private boolean addRabbitStatsToLore(List<Text> lines, int slot) {
if (cpsIncreaseFactors.isEmpty()) return false;
for (Rabbit rabbit : cpsIncreaseFactors) {
if (rabbit.slot == slot) {
lines.add(Text.empty()
- .append(Text.literal("CPS Increase: ").formatted(Formatting.GRAY))
- .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cpsIncrease)).formatted(Formatting.GOLD)));
+ .append(Text.literal("CPS Increase: ").formatted(Formatting.GRAY))
+ .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cpsIncrease)).formatted(Formatting.GOLD)));
lines.add(Text.empty()
- .append(Text.literal("Cost per CPS: ").formatted(Formatting.GRAY))
- .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cost / rabbit.cpsIncrease)).formatted(Formatting.GOLD)));
+ .append(Text.literal("Cost per CPS: ").formatted(Formatting.GRAY))
+ .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cost / rabbit.cpsIncrease)).formatted(Formatting.GOLD)));
if (rabbit.slot == bestUpgrade) {
if (rabbit.cost <= totalChocolate) {
@@ -367,7 +372,7 @@ public class ChocolateFactorySolver extends ContainerSolver {
return false;
}
- private static MutableText formatTime(double seconds) {
+ private MutableText formatTime(double seconds) {
seconds = Math.ceil(seconds);
if (seconds <= 0) return Text.literal("Now").formatted(Formatting.GREEN);
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/end/EndHudWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/end/EndHudWidget.java
index 86e8d23e..a2869447 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/end/EndHudWidget.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/end/EndHudWidget.java
@@ -1,41 +1,34 @@
package de.hysky.skyblocker.skyblock.end;
+import com.mojang.authlib.properties.PropertyMap;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ProfileComponent;
-import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
-import net.minecraft.registry.BuiltinRegistries;
-import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import java.text.NumberFormat;
+import java.util.Locale;
import java.util.Optional;
-import com.mojang.authlib.properties.PropertyMap;
-
public class EndHudWidget extends Widget {
private static final MutableText TITLE = Text.literal("The End").formatted(Formatting.LIGHT_PURPLE, Formatting.BOLD);
public static final EndHudWidget INSTANCE = new EndHudWidget(TITLE, Formatting.DARK_PURPLE.getColorValue());
-
- public EndHudWidget(MutableText title, Integer colorValue) {
- super(title, colorValue);
- this.setX(5);
- this.setY(5);
- this.update();
- }
-
+ private static final NumberFormat DECIMAL_FORMAT = NumberFormat.getInstance(Locale.US);
private static final ItemStack ENDERMAN_HEAD = new ItemStack(Items.PLAYER_HEAD);
private static final ItemStack POPPY = new ItemStack(Items.POPPY);
static {
+ DECIMAL_FORMAT.setMinimumFractionDigits(0);
+ DECIMAL_FORMAT.setMaximumFractionDigits(2);
+
ENDERMAN_HEAD.set(DataComponentTypes.PROFILE, new ProfileComponent(Optional.of("MHF_Enderman"), Optional.empty(), new PropertyMap()));
POPPY.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true);
@@ -43,6 +36,12 @@ public class EndHudWidget extends Widget {
INSTANCE.setY(SkyblockerConfigManager.get().otherLocations.end.y);
}
+ public EndHudWidget(MutableText title, Integer colorValue) {
+ super(title, colorValue);
+ this.setX(5);
+ this.setY(5);
+ this.update();
+ }
@Override
public void updateContent() {
@@ -51,10 +50,7 @@ public class EndHudWidget extends Widget {
addComponent(new IcoTextComponent(ENDERMAN_HEAD, Text.literal("Zealots").formatted(Formatting.BOLD)));
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.zealotsSinceLastEye", TheEnd.zealotsSinceLastEye)));
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.zealotsTotalKills", TheEnd.zealotsKilled)));
- NumberFormat instance = NumberFormat.getInstance();
- instance.setMinimumFractionDigits(0);
- instance.setMaximumFractionDigits(2);
- String avg = TheEnd.eyes == 0 ? "???" : instance.format((float) TheEnd.zealotsKilled / TheEnd.eyes);
+ String avg = TheEnd.eyes == 0 ? "???" : DECIMAL_FORMAT.format((float) TheEnd.zealotsKilled / TheEnd.eyes);
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.avgKillsPerEye", avg)));
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java
index d8f4dad7..7dd332e0 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java
@@ -36,6 +36,7 @@ import java.util.Map;
//TODO: check inventory items, sum all repeated items into one
public class VisitorHelper {
private static final Logger LOGGER = LoggerFactory.getLogger("Skyblocker Visitor Helper");
+ private static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US);
// The pair contains the name of the visitor and the texture if the icon is a player head
private static final Map<Pair<String, String>, Object2IntMap<String>> itemMap = new HashMap<>();
@@ -130,7 +131,7 @@ public class VisitorHelper {
String itemName = splitItemText[0].trim();
if (itemName.isEmpty()) return;
try {
- int amount = splitItemText.length == 2 ? NumberFormat.getInstance(Locale.US).parse(splitItemText[1].trim()).intValue() : 1;
+ int amount = splitItemText.length == 2 ? NUMBER_FORMAT.parse(splitItemText[1].trim()).intValue() : 1;
Pair<String, String> key = Pair.of(visitorName, visitorTexture);
Object2IntMap<String> visitorMap = itemMap.computeIfAbsent(key, _key -> new Object2IntOpenHashMap<>());
visitorMap.put(itemName, amount);