aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevin <92656833+kevinthegreat1@users.noreply.github.com>2025-01-09 11:07:50 -0500
committerGitHub <noreply@github.com>2025-01-10 00:07:50 +0800
commitf239c9e6661cbecda5e079dd2f365d0fae2ea8d2 (patch)
tree72e7967effe8c4885258c3d050c903bb53a71658 /src
parenteb962b9cfda4d989c819f6d784da61baa0e0477a (diff)
downloadSkyblocker-f239c9e6661cbecda5e079dd2f365d0fae2ea8d2.tar.gz
Skyblocker-f239c9e6661cbecda5e079dd2f365d0fae2ea8d2.tar.bz2
Skyblocker-f239c9e6661cbecda5e079dd2f365d0fae2ea8d2.zip
Random fixes (#1120)
* Refactor bazaar and roman numerals * Revert name from api * Fix neu id * Fix roman numerals * Apply suggestions from code review * Fix level type * Fix import --------- Co-authored-by: Rime <81419447+Emirlol@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/item/ItemPrice.java4
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java12
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/searchoverlay/SearchOverManager.java94
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/BazaarProduct.java3
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/RomanNumerals.java34
-rw-r--r--src/test/java/de/hysky/skyblocker/utils/RomanNumeralsTest.java18
6 files changed, 91 insertions, 74 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/ItemPrice.java b/src/main/java/de/hysky/skyblocker/skyblock/item/ItemPrice.java
index 12d688cb..42f6310e 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/item/ItemPrice.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/item/ItemPrice.java
@@ -6,7 +6,6 @@ import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip;
import de.hysky.skyblocker.skyblock.item.tooltip.info.DataTooltipInfoType;
import de.hysky.skyblocker.skyblock.item.tooltip.info.TooltipInfoType;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
-import de.hysky.skyblocker.skyblock.searchoverlay.SearchOverManager;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
@@ -16,6 +15,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
+import org.apache.commons.text.WordUtils;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
@@ -64,7 +64,7 @@ public class ItemPrice {
// Handle Enchanted Books
if (itemName.equals("Enchanted Book")) {
- itemName = SearchOverManager.capitalizeFully(skyblockApiId.replace("ENCHANTMENT_", "").replaceAll("_\\d+", ""));
+ itemName = WordUtils.capitalizeFully(skyblockApiId.replace("ENCHANTMENT_", "").replaceAll("_\\d+", ""));
}
// Search up the item in the bazaar or auction house
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java
index 41709767..12566f25 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java
@@ -6,6 +6,7 @@ import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.skyblock.profileviewer.ProfileViewerPage;
import de.hysky.skyblocker.skyblock.profileviewer.ProfileViewerScreen;
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
+import de.hysky.skyblocker.utils.RomanNumerals;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
@@ -43,7 +44,6 @@ public class GenericCategory implements ProfileViewerPage {
private final Map<String, IntList> tierRequirementsMap;
private final Map<String, String> ICON_TRANSLATION = Map.ofEntries(
Map.entry("MUSHROOM_COLLECTION", "RED_MUSHROOM"));
- private final String[] ROMAN_NUMERALS = {"-", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX"};
public GenericCategory(JsonObject hProfile, JsonObject pProfile, String collection) {
collectionsMap = ProfileViewerScreen.getCollections();
@@ -63,7 +63,7 @@ public class GenericCategory implements ProfileViewerPage {
ItemStack itemStack = ItemRepository.getItemStack(ICON_TRANSLATION.getOrDefault(collection, collection).replace(':', '-'));
itemStack = itemStack == null ? Ico.BARRIER.copy() : itemStack.copy();
- if (itemStack.getItem().getName().getString().equals("Barrier")) {
+ if (itemStack.getItem().getName().getString().equals("Barrier")) {
itemStack.set(DataComponentTypes.CUSTOM_NAME, Text.of(collection));
System.out.println(collection);
System.out.println(this.category);
@@ -91,7 +91,7 @@ public class GenericCategory implements ProfileViewerPage {
if (hProfile.get("members").getAsJsonObject().keySet().size() > 1) {
lore.add(Text.literal("Personal: " + COMMA_FORMATTER.format(personalColl)).setStyle(style).formatted(Formatting.GOLD));
- lore.add(Text.literal("Co-op: " + COMMA_FORMATTER.format(totalCollection-personalColl)).setStyle(style).formatted(Formatting.AQUA));
+ lore.add(Text.literal("Co-op: " + COMMA_FORMATTER.format(totalCollection - personalColl)).setStyle(style).formatted(Formatting.AQUA));
}
lore.add(Text.literal("Collection: " + COMMA_FORMATTER.format(totalCollection)).setStyle(style).formatted(Formatting.YELLOW));
@@ -133,7 +133,7 @@ public class GenericCategory implements ProfileViewerPage {
Color colour = itemStack.hasGlint() ? Color.MAGENTA : Color.darkGray;
//DO NOT CHANGE THIS METHOD CALL! Aaron's Mod mixes in here to provide chroma text for max collections
//and changing the method called here will break that! Consult Aaron before making any changes :)
- context.drawText(textRenderer, Text.literal(toRomanNumerals(cTier)), x + 9 - (textRenderer.getWidth(toRomanNumerals(cTier)) / 2), y + 21, colour.getRGB(), false);
+ context.drawText(textRenderer, Text.literal(RomanNumerals.decimalToRoman(cTier)), x + 9 - (textRenderer.getWidth(RomanNumerals.decimalToRoman(cTier)) / 2), y + 21, colour.getRGB(), false);
}
break;
}
@@ -145,8 +145,4 @@ public class GenericCategory implements ProfileViewerPage {
}
}
}
-
- private String toRomanNumerals(int number) {
- return number <= ROMAN_NUMERALS.length ? ROMAN_NUMERALS[number] : "Err";
- }
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/searchoverlay/SearchOverManager.java b/src/main/java/de/hysky/skyblocker/skyblock/searchoverlay/SearchOverManager.java
index 31a698ae..d663ca7a 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/searchoverlay/SearchOverManager.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/searchoverlay/SearchOverManager.java
@@ -8,6 +8,7 @@ import de.hysky.skyblocker.config.configs.UIAndVisualsConfig;
import de.hysky.skyblocker.skyblock.item.tooltip.info.TooltipInfoType;
import de.hysky.skyblocker.utils.BazaarProduct;
import de.hysky.skyblocker.utils.NEURepoManager;
+import de.hysky.skyblocker.utils.RomanNumerals;
import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import io.github.moulberry.repo.data.NEUItem;
import io.github.moulberry.repo.util.NEUId;
@@ -30,7 +31,6 @@ import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
@@ -39,15 +39,8 @@ public class SearchOverManager {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
private static final Logger LOGGER = LoggerFactory.getLogger("Skyblocker Search Overlay");
- private static final Pattern BAZAAR_ENCHANTMENT_PATTERN = Pattern.compile("ENCHANTMENT_(\\D*)_(\\d+)");
+ private static final Pattern BAZAAR_ENCHANTMENT_PATTERN = Pattern.compile("Enchantment (\\D*) (\\d+)");
private static final String PET_NAME_START = "[Lvl {LVL}] ";
- /**
- * converts index (in array) +1 to a roman numeral
- */
- private static final String[] ROMAN_NUMERALS = new String[]{
- "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI",
- "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX"
- };
private static @Nullable SignBlockEntity sign = null;
private static boolean signFront = true;
@@ -63,7 +56,7 @@ public class SearchOverManager {
private static HashSet<String> auctionItems = new HashSet<>();
private static HashSet<String> auctionPets = new HashSet<>();
private static HashSet<String> starableItems = new HashSet<>();
- private static HashMap<String, String> namesToId = new HashMap<>();
+ private static HashMap<String, String> namesToNeuId = new HashMap<>();
public static String[] suggestionsArray = {};
@@ -97,7 +90,7 @@ public class SearchOverManager {
HashSet<String> auctionItems = new HashSet<>();
HashSet<String> auctionPets = new HashSet<>();
HashSet<String> starableItems = new HashSet<>();
- HashMap<String, String> namesToId = new HashMap<>();
+ HashMap<String, String> namesToNeuId = new HashMap<>();
//get bazaar items
try {
@@ -106,36 +99,32 @@ public class SearchOverManager {
Object2ObjectMap<String, BazaarProduct> products = TooltipInfoType.BAZAAR.getData();
for (Map.Entry<String, BazaarProduct> entry : products.entrySet()) {
BazaarProduct product = entry.getValue();
- String id = product.id();
- int sellVolume = product.sellVolume();
- if (sellVolume == 0)
- continue; //do not add items that do not sell e.g. they are not actual in the bazaar
- Matcher matcher = BAZAAR_ENCHANTMENT_PATTERN.matcher(id);
- if (matcher.matches()) {//format enchantments
- //remove ultimate if in name
- String name = matcher.group(1);
- if (!name.contains("WISE")) { //only way found to remove ultimate from everything but ultimate wise
- name = name.replace("ULTIMATE_", "");
- }
- name = name.replace("_", " ");
- name = capitalizeFully(name);
- int enchantLevel = Integer.parseInt(matcher.group(2));
- String level = "";
- if (enchantLevel > 0) {
- level = ROMAN_NUMERALS[enchantLevel - 1];
- }
- bazaarItems.add(name + " " + level);
- namesToId.put(name + " " + level, matcher.group(1) + ";" + matcher.group(2));
- continue;
- }
- //look up id for name
- NEUItem neuItem = NEURepoManager.NEU_REPO.getItems().getItemBySkyblockId(id);
- if (neuItem != null) {
- String name = Formatting.strip(neuItem.getDisplayName());
- bazaarItems.add(name);
- namesToId.put(name, id);
- continue;
- }
+ String id = product.id();
+ String name = product.name();
+ int sellVolume = product.sellVolume();
+ if (sellVolume == 0)
+ continue; //do not add items that do not sell e.g. they are not actual in the bazaar
+ Matcher matcher = BAZAAR_ENCHANTMENT_PATTERN.matcher(name);
+ if (matcher.matches()) {//format enchantments
+ name = matcher.group(1);
+ if (!name.contains("Ultimate Wise")) {
+ name = name.replace("Ultimate ", "");
+ }
+
+ String level = matcher.group(2);
+ name += " " + RomanNumerals.decimalToRoman(Integer.parseInt(level));
+ bazaarItems.add(name);
+ namesToNeuId.put(name, id.substring(0, id.lastIndexOf('_')).replace("ENCHANTMENT_", "") + ";" + level);
+ continue;
+ }
+ //look up id for name
+ NEUItem neuItem = NEURepoManager.NEU_REPO.getItems().getItemBySkyblockId(id);
+ if (neuItem != null) {
+ name = Formatting.strip(neuItem.getDisplayName());
+ bazaarItems.add(name);
+ namesToNeuId.put(name, id);
+ continue;
+ }
}
} catch (Exception e) {
LOGGER.error("[Skyblocker] Failed to load bazaar item list! ", e);
@@ -164,7 +153,7 @@ public class SearchOverManager {
starableItems.add(name.toLowerCase());
}
auctionItems.add(name);
- namesToId.put(name, id);
+ namesToNeuId.put(name, id);
}
}
} catch (Exception e) {
@@ -175,22 +164,7 @@ public class SearchOverManager {
SearchOverManager.auctionItems = auctionItems;
SearchOverManager.auctionPets = auctionPets;
SearchOverManager.starableItems = starableItems;
- SearchOverManager.namesToId = namesToId;
- }
-
- /**
- * Capitalizes the first letter off every word in a string
- *
- * @param str string to capitalize
- */
- public static String capitalizeFully(String str) {
- if (str == null || str.isEmpty()) {
- return str;
- }
-
- return Arrays.stream(str.split("\\s+"))
- .map(t -> t.substring(0, 1).toUpperCase() + t.substring(1).toLowerCase())
- .collect(Collectors.joining(" "));
+ SearchOverManager.namesToNeuId = namesToNeuId;
}
/**
@@ -265,7 +239,7 @@ public class SearchOverManager {
}
protected static String getSuggestionId(int index) {
- return namesToId.get(getSuggestion(index));
+ return namesToNeuId.get(getSuggestion(index));
}
/**
@@ -287,7 +261,7 @@ public class SearchOverManager {
}
protected static String getHistoryId(int index) {
- return namesToId.get(getHistory(index));
+ return namesToNeuId.get(getHistory(index));
}
/**
diff --git a/src/main/java/de/hysky/skyblocker/utils/BazaarProduct.java b/src/main/java/de/hysky/skyblocker/utils/BazaarProduct.java
index 58701fe6..da54b14f 100644
--- a/src/main/java/de/hysky/skyblocker/utils/BazaarProduct.java
+++ b/src/main/java/de/hysky/skyblocker/utils/BazaarProduct.java
@@ -7,9 +7,10 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
-public record BazaarProduct(String id, OptionalDouble buyPrice, OptionalDouble sellPrice, int buyVolume, int sellVolume) {
+public record BazaarProduct(String id, String name, OptionalDouble buyPrice, OptionalDouble sellPrice, int buyVolume, int sellVolume) {
private static final Codec<BazaarProduct> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.STRING.fieldOf("id").forGetter(BazaarProduct::id),
+ Codec.STRING.fieldOf("name").forGetter(BazaarProduct::name),
CodecUtils.optionalDouble(Codec.DOUBLE.lenientOptionalFieldOf("buyPrice")).forGetter(BazaarProduct::buyPrice),
CodecUtils.optionalDouble(Codec.DOUBLE.lenientOptionalFieldOf("sellPrice")).forGetter(BazaarProduct::sellPrice),
Codec.INT.fieldOf("buyVolume").forGetter(BazaarProduct::buyVolume),
diff --git a/src/main/java/de/hysky/skyblocker/utils/RomanNumerals.java b/src/main/java/de/hysky/skyblocker/utils/RomanNumerals.java
index d6291d75..281c600b 100644
--- a/src/main/java/de/hysky/skyblocker/utils/RomanNumerals.java
+++ b/src/main/java/de/hysky/skyblocker/utils/RomanNumerals.java
@@ -1,7 +1,17 @@
package de.hysky.skyblocker.utils;
+import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
+import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
+import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
+import org.jetbrains.annotations.NotNull;
+
public class RomanNumerals {
- private RomanNumerals() {}
+ private static final Int2ObjectMap<String> ROMAN_NUMERALS = Int2ObjectMaps.unmodifiable(new Int2ObjectLinkedOpenHashMap<>(
+ new int[]{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1},
+ new String[]{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}
+ ));
+
+ private RomanNumerals() {}
private static int getDecimalValue(char romanChar) {
return switch (romanChar) {
@@ -19,6 +29,7 @@ public class RomanNumerals {
/**
* Checks if a string is a valid roman numeral.
* It's the caller's responsibility to clean up the string before calling this method (such as trimming it).
+ *
* @param romanNumeral The roman numeral to check.
* @return True if the string is a valid roman numeral, false otherwise.
* @implNote This will only check if the string contains valid roman numeral characters. It won't check if the numeral is well-formed.
@@ -51,4 +62,25 @@ public class RomanNumerals {
}
return decimal;
}
+
+ /**
+ * Converts a decimal number to a roman numeral.
+ *
+ * @param decimal The decimal number to convert.
+ * @return The roman numeral, or an empty string if the number is out of range.
+ */
+ @NotNull
+ public static String decimalToRoman(int decimal) {
+ if (decimal <= 0 || decimal >= 4000) return "";
+ StringBuilder roman = new StringBuilder();
+ for (Int2ObjectMap.Entry<String> entry : ROMAN_NUMERALS.int2ObjectEntrySet()) {
+ int value = entry.getIntKey();
+ String numeral = entry.getValue();
+ while (decimal >= value) {
+ roman.append(numeral);
+ decimal -= value;
+ }
+ }
+ return roman.toString();
+ }
}
diff --git a/src/test/java/de/hysky/skyblocker/utils/RomanNumeralsTest.java b/src/test/java/de/hysky/skyblocker/utils/RomanNumeralsTest.java
index 35bd76ee..ac6861b9 100644
--- a/src/test/java/de/hysky/skyblocker/utils/RomanNumeralsTest.java
+++ b/src/test/java/de/hysky/skyblocker/utils/RomanNumeralsTest.java
@@ -5,11 +5,11 @@ import org.junit.jupiter.api.Test;
class RomanNumeralsTest {
@Test
- void testToRoman() {
+ void testRomanToDecimal() {
// Test the first 50 numbers
String[] expected = new String[]{"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX", "XXI", "XXII", "XXIII", "XXIV", "XXV", "XXVI", "XXVII", "XXVIII", "XXIX", "XXX", "XXXI", "XXXII", "XXXIII", "XXXIV", "XXXV", "XXXVI", "XXXVII", "XXXVIII", "XXXIX", "XL", "XLI", "XLII", "XLIII", "XLIV", "XLV", "XLVI", "XLVII", "XLVIII", "XLIX", "L"};
for (int i = 1; i <= 50; i++) {
- Assertions.assertEquals(i, RomanNumerals.romanToDecimal(expected[i-1]));
+ Assertions.assertEquals(i, RomanNumerals.romanToDecimal(expected[i - 1]));
}
Assertions.assertEquals(100, RomanNumerals.romanToDecimal("C"));
Assertions.assertEquals(400, RomanNumerals.romanToDecimal("CD"));
@@ -32,4 +32,18 @@ class RomanNumeralsTest {
Assertions.assertFalse(RomanNumerals.isValidRomanNumeral(null));
Assertions.assertFalse(RomanNumerals.isValidRomanNumeral(""));
}
+
+ @Test
+ void testDecimalToRoman() {
+ String[] expected = new String[]{"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX", "XXI", "XXII", "XXIII", "XXIV", "XXV", "XXVI", "XXVII", "XXVIII", "XXIX", "XXX", "XXXI", "XXXII", "XXXIII", "XXXIV", "XXXV", "XXXVI", "XXXVII", "XXXVIII", "XXXIX", "XL", "XLI", "XLII", "XLIII", "XLIV", "XLV", "XLVI", "XLVII", "XLVIII", "XLIX", "L"};
+ for (int i = 1; i <= 50; i++) {
+ Assertions.assertEquals(expected[i - 1], RomanNumerals.decimalToRoman(i));
+ }
+ Assertions.assertEquals("C", RomanNumerals.decimalToRoman(100));
+ Assertions.assertEquals("CD", RomanNumerals.decimalToRoman(400));
+ Assertions.assertEquals("D", RomanNumerals.decimalToRoman(500));
+ Assertions.assertEquals("CM", RomanNumerals.decimalToRoman(900));
+ Assertions.assertEquals("M", RomanNumerals.decimalToRoman(1000));
+ Assertions.assertEquals("MCMXCIX", RomanNumerals.decimalToRoman(1999));
+ }
}