aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2024-07-27 15:44:40 +0800
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2024-07-27 15:44:40 +0800
commita5cad9ed535562b8deeb1511c4ff42630ebb30b7 (patch)
treee96670f9c075a1c532632477fac859ad7c129721 /src/main/java
parent7704d0d36585c5a1e8b6fc22bdfe77417af12c20 (diff)
downloadSkyblocker-a5cad9ed535562b8deeb1511c4ff42630ebb30b7.tar.gz
Skyblocker-a5cad9ed535562b8deeb1511c4ff42630ebb30b7.tar.bz2
Skyblocker-a5cad9ed535562b8deeb1511c4ff42630ebb30b7.zip
Clean up id mess and begin to add tests
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/hysky/skyblocker/mixins/ItemStackMixin.java130
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/ChestValue.java6
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java3
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusProfit.java4
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java3
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java40
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java2
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/ItemUtils.java184
8 files changed, 188 insertions, 184 deletions
diff --git a/src/main/java/de/hysky/skyblocker/mixins/ItemStackMixin.java b/src/main/java/de/hysky/skyblocker/mixins/ItemStackMixin.java
index 1493cf26..2377f6aa 100644
--- a/src/main/java/de/hysky/skyblocker/mixins/ItemStackMixin.java
+++ b/src/main/java/de/hysky/skyblocker/mixins/ItemStackMixin.java
@@ -1,13 +1,9 @@
package de.hysky.skyblocker.mixins;
-import com.google.gson.JsonParser;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
-import com.mojang.serialization.JsonOps;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.injected.SkyblockerStack;
-import de.hysky.skyblocker.skyblock.PetCache.PetInfo;
-import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip;
import de.hysky.skyblocker.skyblock.profileviewer.ProfileViewerScreen;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.Utils;
@@ -17,8 +13,6 @@ import net.minecraft.component.ComponentHolder;
import net.minecraft.component.type.ItemEnchantmentsComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipAppender;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.nbt.NbtElement;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
@@ -29,9 +23,6 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-import java.util.Locale;
-import java.util.Optional;
-
@Mixin(ItemStack.class)
public abstract class ItemStackMixin implements ComponentHolder, SkyblockerStack {
@@ -132,14 +123,14 @@ public abstract class ItemStackMixin implements ComponentHolder, SkyblockerStack
@Nullable
public String getSkyblockId() {
if (skyblockId != null && !skyblockId.isEmpty()) return skyblockId;
- return skyblockId = skyblocker$getSkyblockId(true);
+ return skyblockId = ItemUtils.getSkyblockApiId((ItemStack) (Object) this, true);
}
@Override
@Nullable
public String getSkyblockApiId() {
if (skyblockApiId != null && !skyblockApiId.isEmpty()) return skyblockApiId;
- return skyblockApiId = skyblocker$getSkyblockId(false);
+ return skyblockApiId = ItemUtils.getSkyblockApiId((ItemStack) (Object) this, false);
}
@Override
@@ -152,121 +143,6 @@ public abstract class ItemStackMixin implements ComponentHolder, SkyblockerStack
if (apiId.startsWith("ISSHINY_")) apiId = id;
- return neuName = ItemTooltip.getNeuName(id, apiId);
- }
-
- @Unique
- private String skyblocker$getSkyblockId(boolean internalIDOnly) {
- NbtCompound customData = ItemUtils.getCustomData((ItemStack) (Object) this);
-
- if (customData == null || !customData.contains(ItemUtils.ID, NbtElement.STRING_TYPE)) {
- return null;
- }
- String customDataString = customData.getString(ItemUtils.ID);
-
- if (internalIDOnly) {
- return customDataString;
- }
-
- // Transformation to API format.
- //TODO future - remove this and just handle it directly for the NEU id conversion because this whole system is confusing and hard to follow
- if (customData.contains("is_shiny")) {
- return "ISSHINY_" + customDataString;
- }
-
- switch (customDataString) {
- case "ENCHANTED_BOOK" -> {
- if (customData.contains("enchantments")) {
- NbtCompound enchants = customData.getCompound("enchantments");
- Optional<String> firstEnchant = enchants.getKeys().stream().findFirst();
- String enchant = firstEnchant.orElse("");
- return "ENCHANTMENT_" + enchant.toUpperCase(Locale.ENGLISH) + "_" + enchants.getInt(enchant);
- }
- }
-
- case "PET" -> {
- if (customData.contains("petInfo")) {
- PetInfo petInfo = PetInfo.CODEC.parse(JsonOps.INSTANCE, JsonParser.parseString(customData.getString("petInfo"))).getOrThrow();
- return "LVL_1_" + petInfo.tier() + "_" + petInfo.type();
- }
- }
-
- case "POTION" -> {
- String enhanced = customData.contains("enhanced") ? "_ENHANCED" : "";
- String extended = customData.contains("extended") ? "_EXTENDED" : "";
- String splash = customData.contains("splash") ? "_SPLASH" : "";
- if (customData.contains("potion") && customData.contains("potion_level")) {
- return (customData.getString("potion") + "_" + customDataString + "_" + customData.getInt("potion_level")
- + enhanced + extended + splash).toUpperCase(Locale.ENGLISH);
- }
- }
-
- case "RUNE" -> {
- if (customData.contains("runes")) {
- NbtCompound runes = customData.getCompound("runes");
- Optional<String> firstRunes = runes.getKeys().stream().findFirst();
- String rune = firstRunes.orElse("");
- return rune.toUpperCase(Locale.ENGLISH) + "_RUNE_" + runes.getInt(rune);
- }
- }
-
- case "ATTRIBUTE_SHARD" -> {
- if (customData.contains("attributes")) {
- NbtCompound shards = customData.getCompound("attributes");
- Optional<String> firstShards = shards.getKeys().stream().findFirst();
- String shard = firstShards.orElse("");
- return customDataString + "-" + shard.toUpperCase(Locale.ENGLISH) + "_" + shards.getInt(shard);
- }
- }
-
- case "NEW_YEAR_CAKE" -> {
- return customDataString + "_" + customData.getInt("new_years_cake");
- }
-
- case "PARTY_HAT_CRAB", "PARTY_HAT_CRAB_ANIMATED", "BALLOON_HAT_2024" -> {
- return customDataString + "_" + customData.getString("party_hat_color").toUpperCase(Locale.ENGLISH);
- }
-
- case "PARTY_HAT_SLOTH" -> {
- return customDataString + "_" + customData.getString("party_hat_emoji").toUpperCase(Locale.ENGLISH);
- }
-
- case "CRIMSON_HELMET", "CRIMSON_CHESTPLATE", "CRIMSON_LEGGINGS", "CRIMSON_BOOTS" -> {
- NbtCompound attributes = customData.getCompound("attributes");
-
- if (attributes.contains("magic_find") && attributes.contains("veteran")) {
- return customDataString + "-MAGIC_FIND-VETERAN";
- }
- }
-
- case "AURORA_HELMET", "AURORA_CHESTPLATE", "AURORA_LEGGINGS", "AURORA_BOOTS" -> {
- NbtCompound attributes = customData.getCompound("attributes");
-
- if (attributes.contains("mana_pool") && attributes.contains("mana_regeneration")) {
- return customDataString + "-MANA_POOL-MANA_REGENERATION";
- }
- }
-
- case "TERROR_HELMET", "TERROR_CHESTPLATE", "TERROR_LEGGINGS", "TERROR_BOOTS" -> {
- NbtCompound attributes = customData.getCompound("attributes");
-
- if (attributes.contains("lifeline") && attributes.contains("mana_pool")) {
- return customDataString + "-LIFELINE-MANA_POOL";
- }
- }
-
- case "MIDAS_SWORD" -> {
- if (customData.getInt("winning_bid") >= 50000000) {
- return customDataString + "_50M";
- }
- }
-
- case "MIDAS_STAFF" -> {
- if (customData.getInt("winning_bid") >= 100000000) {
- return customDataString + "_100M";
- }
- }
- }
- return customDataString;
+ return neuName = ItemUtils.getNeuId(id, apiId);
}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/ChestValue.java b/src/main/java/de/hysky/skyblocker/skyblock/ChestValue.java
index 908525e1..b352bead 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/ChestValue.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/ChestValue.java
@@ -79,11 +79,11 @@ public class ChestValue {
}
String name = stack.getName().getString();
- String id = stack.getSkyblockApiId();
+ String skyblockApiId = stack.getSkyblockApiId();
//Regular item price
- if (id != null) {
- DoubleBooleanPair priceData = ItemUtils.getItemPrice(id);
+ if (skyblockApiId != null) {
+ DoubleBooleanPair priceData = ItemUtils.getItemPrice(skyblockApiId);
if (!priceData.rightBoolean()) hasIncompleteData = true;
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java
index b690baa1..e16a81fc 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java
@@ -7,7 +7,6 @@ import de.hysky.skyblocker.skyblock.auction.widgets.AuctionTypeWidget;
import de.hysky.skyblocker.skyblock.auction.widgets.CategoryTabWidget;
import de.hysky.skyblocker.skyblock.auction.widgets.RarityWidget;
import de.hysky.skyblocker.skyblock.auction.widgets.SortWidget;
-import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip;
import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.render.gui.AbstractCustomHypixelGUI;
@@ -302,7 +301,7 @@ public class AuctionBrowserScreen extends AbstractCustomHypixelGUI<AuctionHouseS
if (name.startsWith("ISSHINY_")) {
neuName = internalID;
}
- JsonElement jsonElement = TooltipInfoType.THREE_DAY_AVERAGE.getData().get(ItemTooltip.getNeuName(internalID, neuName));
+ JsonElement jsonElement = TooltipInfoType.THREE_DAY_AVERAGE.getData().get(ItemUtils.getNeuId(internalID, neuName));
if (jsonElement == null) break;
else {
isSlotHighlighted.put(slotId, jsonElement.getAsDouble() > parsed);
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusProfit.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusProfit.java
index 82acc3f2..12954118 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusProfit.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusProfit.java
@@ -105,12 +105,12 @@ public class CroesusProfit extends SimpleContainerSolver {
private double getItemPrice(String itemDisplayName) {
- return ItemUtils.getItemPrice(dungeonDropsNameToId.get(itemDisplayName)).leftDouble();
+ return ItemUtils.getItemPrice(dungeonDropsNameToApiId.get(itemDisplayName)).leftDouble();
}
// I did a thing :(
- private final Map<String, String> dungeonDropsNameToId = Util.make(new HashMap<>(), map -> {
+ private final Map<String, String> dungeonDropsNameToApiId = Util.make(new HashMap<>(), map -> {
map.put("Enchanted Book (Ultimate Jerry I)", "ENCHANTMENT_ULTIMATE_JERRY_1"); // ultimate books start
map.put("Enchanted Book (Ultimate Jerry II)", "ENCHANTMENT_ULTIMATE_JERRY_2");
map.put("Enchanted Book (Ultimate Jerry III)", "ENCHANTMENT_ULTIMATE_JERRY_3");
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java
index 84013f0b..6dd0c39b 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java
@@ -1,7 +1,6 @@
package de.hysky.skyblocker.skyblock.garden;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
-import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip;
import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
@@ -64,7 +63,7 @@ public class FarmingHudWidget extends Widget {
ItemStack farmingToolStack = client.player.getMainHandStack();
if (farmingToolStack == null) return;
String cropItemId = FARMING_TOOLS.get(ItemUtils.getItemId(farmingToolStack));
- ItemStack cropStack = ItemRepository.getItemStack(ItemTooltip.getNeuName(cropItemId, cropItemId)); // The cropItemId is being used as the api id in the second parameter because the skyblock id and api id are the same for all crops.
+ ItemStack cropStack = ItemRepository.getItemStack(ItemUtils.getNeuId(cropItemId, cropItemId)); // The cropItemId is being used as the api id in the second parameter because the skyblock id and api id are the same for all crops.
String counterText = FarmingHud.counterText();
String counterNumber = FarmingHud.NUMBER_FORMAT.format(FarmingHud.counter());
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java
index 955ebc87..7a8db9f6 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java
@@ -4,12 +4,12 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.config.configs.GeneralConfig;
import de.hysky.skyblocker.skyblock.item.tooltip.adders.CraftPriceTooltip;
import de.hysky.skyblocker.utils.Constants;
+import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
-import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -25,43 +25,11 @@ public class ItemTooltip {
private static volatile boolean sentNullWarning = false;
/**
- * Gets the NEU id from an id and an api id.
- * @param id the id of the skyblock item, gotten from {@link de.hysky.skyblocker.utils.ItemUtils#getItemId(net.minecraft.item.ItemStack) ItemUtils#getItemId(ItemStack)} or {@link net.minecraft.item.ItemStack#getSkyblockId() ItemStack#getSkyblockId()}
- * @param apiId the api id of the skyblock item, matching the id of the item on the Skyblocker api, gotten from {@link net.minecraft.item.ItemStack#getSkyblockApiId() ItemStack#getSkyblockApiId()}
- * @return the NEU id of the skyblock item, matching the id of the item gotten from {@link io.github.moulberry.repo.data.NEUItem#getSkyblockItemId() NEUItem#getSkyblockItemId()} or {@link net.minecraft.item.ItemStack#getNeuName() ItemStack#getNeuName()},
- * or an empty string if either id or apiId is null
+ * @deprecated Use {@link ItemUtils#getNeuId(String, String)} instead
*/
- @NotNull
+ @Deprecated(since = "1.22")
public static String getNeuName(String id, String apiId) {
- if (id == null || apiId == null) return "";
- switch (id) {
- case "PET" -> {
- apiId = apiId.replaceAll("LVL_\\d*_", "");
- String[] parts = apiId.split("_");
- String type = parts[0];
- apiId = apiId.replaceAll(type + "_", "");
- apiId = apiId + "-" + type;
- apiId = apiId.replace("UNCOMMON", "1")
- .replace("COMMON", "0")
- .replace("RARE", "2")
- .replace("EPIC", "3")
- .replace("LEGENDARY", "4")
- .replace("MYTHIC", "5")
- .replace("-", ";");
- }
- case "RUNE" -> apiId = apiId.replaceAll("_(?!.*_)", ";");
- case "POTION" -> apiId = "";
- case "ATTRIBUTE_SHARD" ->
- apiId = id + "+" + apiId.replace("SHARD-", "").replaceAll("_(?!.*_)", ";");
- case "NEW_YEAR_CAKE" -> apiId = id + "+" + apiId.replace("NEW_YEAR_CAKE_", "");
- case "PARTY_HAT_CRAB_ANIMATED" -> apiId = "PARTY_HAT_CRAB_" + apiId.replace("PARTY_HAT_CRAB_ANIMATED_", "") + "_ANIMATED";
- case "CRIMSON_HELMET", "CRIMSON_CHESTPLATE", "CRIMSON_LEGGINGS", "CRIMSON_BOOTS",
- "AURORA_HELMET", "AURORA_CHESTPLATE", "AURORA_LEGGINGS", "AURORA_BOOTS",
- "TERROR_HELMET", "TERROR_CHESTPLATE", "TERROR_LEGGINGS", "TERROR_BOOTS" -> apiId = id;
- case "MIDAS_SWORD", "MIDAS_STAFF" -> apiId = id;
- default -> apiId = apiId.replace(":", "-");
- }
- return apiId;
+ return ItemUtils.getNeuId(id, apiId);
}
public static void nullWarning() {
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java
index 4dca91d6..5196901c 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java
@@ -119,7 +119,7 @@ public class ItemRepository {
}
/**
- * @param neuId the NEU item id gotten through {@link NEUItem#getSkyblockItemId()}, {@link ItemStack#getNeuName()}, or {@link de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip#getNeuName(String, String) ItemTooltip#getNeuName(String, String)}
+ * @param neuId the NEU item id gotten through {@link NEUItem#getSkyblockItemId()}, {@link ItemStack#getNeuName()}, or {@link ItemUtils#getNeuId(String, String) ItemTooltip#getNeuName(String, String)}
*/
@Nullable
public static ItemStack getItemStack(String neuId) {
diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
index 894ef8ec..3b671c60 100644
--- a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
+++ b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
@@ -11,6 +11,7 @@ import com.mojang.serialization.Codec;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import de.hysky.skyblocker.SkyblockerMod;
+import de.hysky.skyblocker.skyblock.PetCache;
import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType;
import de.hysky.skyblocker.skyblock.item.tooltip.adders.ObtainedDateTooltip;
import it.unimi.dsi.fastutil.doubles.DoubleBooleanPair;
@@ -27,6 +28,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
+import net.minecraft.nbt.NbtElement;
import net.minecraft.registry.Registries;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.text.Text;
@@ -36,6 +38,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
+import java.util.Locale;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Matcher;
@@ -78,7 +81,7 @@ public final class ItemUtils {
* Gets the Skyblock item id of the item stack.
*
* @param stack the item stack to get the internal name from
- * @return an optional containing the internal name of the item stack
+ * @return an optional containing the Skyblock item id of the item stack
*/
public static @NotNull Optional<String> getItemIdOptional(@NotNull ItemStack stack) {
NbtCompound customData = getCustomData(stack);
@@ -89,7 +92,7 @@ public final class ItemUtils {
* Gets the Skyblock item id of the item stack.
*
* @param stack the item stack to get the internal name from
- * @return the internal name of the item stack, or an empty string if the item stack is null or does not have an internal name
+ * @return the Skyblock item id of the item stack, or an empty string if the item stack does not have a Skyblock id
*/
public static @NotNull String getItemId(@NotNull ItemStack stack) {
return getCustomData(stack).getString(ID);
@@ -110,42 +113,201 @@ public final class ItemUtils {
* Gets the UUID of the item stack.
*
* @param stack the item stack to get the UUID from
- * @return the UUID of the item stack, or an empty string if the item stack is null or does not have a UUID
+ * @return the UUID of the item stack, or an empty string if the item stack does not have a UUID
*/
public static @NotNull String getItemUuid(@NotNull ComponentHolder stack) {
return getCustomData(stack).getString(UUID);
}
/**
+ * Gets the Skyblock api id of the item stack.
+ * @return the Skyblock api id if of the item stack, or null if the item stack does not have a Skyblock id.
+ */
+ @Nullable
+ public static String getSkyblockApiId(@NotNull ItemStack itemStack, boolean itemIdOnly) {
+ NbtCompound customData = getCustomData(itemStack);
+
+ if (customData == null || !customData.contains(ID, NbtElement.STRING_TYPE)) {
+ return null;
+ }
+ String customDataString = customData.getString(ID);
+
+ if (itemIdOnly) {
+ return customDataString;
+ }
+
+ // Transformation to API format.
+ //TODO future - remove this and just handle it directly for the NEU id conversion because this whole system is confusing and hard to follow
+ if (customData.contains("is_shiny")) {
+ return "ISSHINY_" + customDataString;
+ }
+
+ switch (customDataString) {
+ case "ENCHANTED_BOOK" -> {
+ if (customData.contains("enchantments")) {
+ NbtCompound enchants = customData.getCompound("enchantments");
+ Optional<String> firstEnchant = enchants.getKeys().stream().findFirst();
+ String enchant = firstEnchant.orElse("");
+ return "ENCHANTMENT_" + enchant.toUpperCase(Locale.ENGLISH) + "_" + enchants.getInt(enchant);
+ }
+ }
+
+ case "PET" -> {
+ if (customData.contains("petInfo")) {
+ PetCache.PetInfo petInfo = PetCache.PetInfo.CODEC.parse(JsonOps.INSTANCE, JsonParser.parseString(customData.getString("petInfo"))).getOrThrow();
+ return "LVL_1_" + petInfo.tier() + "_" + petInfo.type();
+ }
+ }
+
+ case "POTION" -> {
+ String enhanced = customData.contains("enhanced") ? "_ENHANCED" : "";
+ String extended = customData.contains("extended") ? "_EXTENDED" : "";
+ String splash = customData.contains("splash") ? "_SPLASH" : "";
+ if (customData.contains("potion") && customData.contains("potion_level")) {
+ return (customData.getString("potion") + "_" + customDataString + "_" + customData.getInt("potion_level")
+ + enhanced + extended + splash).toUpperCase(Locale.ENGLISH);
+ }
+ }
+
+ case "RUNE" -> {
+ if (customData.contains("runes")) {
+ NbtCompound runes = customData.getCompound("runes");
+ Optional<String> firstRunes = runes.getKeys().stream().findFirst();
+ String rune = firstRunes.orElse("");
+ return rune.toUpperCase(Locale.ENGLISH) + "_RUNE_" + runes.getInt(rune);
+ }
+ }
+
+ case "ATTRIBUTE_SHARD" -> {
+ if (customData.contains("attributes")) {
+ NbtCompound shards = customData.getCompound("attributes");
+ Optional<String> firstShards = shards.getKeys().stream().findFirst();
+ String shard = firstShards.orElse("");
+ return customDataString + "-" + shard.toUpperCase(Locale.ENGLISH) + "_" + shards.getInt(shard);
+ }
+ }
+
+ case "NEW_YEAR_CAKE" -> {
+ return customDataString + "_" + customData.getInt("new_years_cake");
+ }
+
+ case "PARTY_HAT_CRAB", "PARTY_HAT_CRAB_ANIMATED", "BALLOON_HAT_2024" -> {
+ return customDataString + "_" + customData.getString("party_hat_color").toUpperCase(Locale.ENGLISH);
+ }
+
+ case "PARTY_HAT_SLOTH" -> {
+ return customDataString + "_" + customData.getString("party_hat_emoji").toUpperCase(Locale.ENGLISH);
+ }
+
+ case "CRIMSON_HELMET", "CRIMSON_CHESTPLATE", "CRIMSON_LEGGINGS", "CRIMSON_BOOTS" -> {
+ NbtCompound attributes = customData.getCompound("attributes");
+
+ if (attributes.contains("magic_find") && attributes.contains("veteran")) {
+ return customDataString + "-MAGIC_FIND-VETERAN";
+ }
+ }
+
+ case "AURORA_HELMET", "AURORA_CHESTPLATE", "AURORA_LEGGINGS", "AURORA_BOOTS" -> {
+ NbtCompound attributes = customData.getCompound("attributes");
+
+ if (attributes.contains("mana_pool") && attributes.contains("mana_regeneration")) {
+ return customDataString + "-MANA_POOL-MANA_REGENERATION";
+ }
+ }
+
+ case "TERROR_HELMET", "TERROR_CHESTPLATE", "TERROR_LEGGINGS", "TERROR_BOOTS" -> {
+ NbtCompound attributes = customData.getCompound("attributes");
+
+ if (attributes.contains("lifeline") && attributes.contains("mana_pool")) {
+ return customDataString + "-LIFELINE-MANA_POOL";
+ }
+ }
+
+ case "MIDAS_SWORD" -> {
+ if (customData.getInt("winning_bid") >= 50000000) {
+ return customDataString + "_50M";
+ }
+ }
+
+ case "MIDAS_STAFF" -> {
+ if (customData.getInt("winning_bid") >= 100000000) {
+ return customDataString + "_100M";
+ }
+ }
+ }
+ return customDataString;
+ }
+
+ /**
+ * Gets the NEU id from an id and an api id.
+ * @param id the id of the skyblock item, gotten from {@link ItemUtils#getItemId(ItemStack) ItemUtils#getItemId(ItemStack)} or {@link ItemStack#getSkyblockId() ItemStack#getSkyblockId()}
+ * @param apiId the api id of the skyblock item, matching the id of the item on the Skyblocker api, gotten from {@link ItemStack#getSkyblockApiId() ItemStack#getSkyblockApiId()}
+ * @return the NEU id of the skyblock item, matching the id of the item gotten from {@link io.github.moulberry.repo.data.NEUItem#getSkyblockItemId() NEUItem#getSkyblockItemId()} or {@link ItemStack#getNeuName() ItemStack#getNeuName()},
+ * or an empty string if either id or apiId is null
+ */
+ @NotNull
+ public static String getNeuId(String id, String apiId) {
+ if (id == null || apiId == null) return "";
+ switch (id) {
+ case "PET" -> {
+ apiId = apiId.replaceAll("LVL_\\d*_", "");
+ String[] parts = apiId.split("_");
+ String type = parts[0];
+ apiId = apiId.replaceAll(type + "_", "");
+ apiId = apiId + "-" + type;
+ apiId = apiId.replace("UNCOMMON", "1")
+ .replace("COMMON", "0")
+ .replace("RARE", "2")
+ .replace("EPIC", "3")
+ .replace("LEGENDARY", "4")
+ .replace("MYTHIC", "5")
+ .replace("-", ";");
+ }
+ case "RUNE" -> apiId = apiId.replaceAll("_(?!.*_)", ";");
+ case "POTION" -> apiId = "";
+ case "ATTRIBUTE_SHARD" ->
+ apiId = id + "+" + apiId.replace("SHARD-", "").replaceAll("_(?!.*_)", ";");
+ case "NEW_YEAR_CAKE" -> apiId = id + "+" + apiId.replace("NEW_YEAR_CAKE_", "");
+ case "PARTY_HAT_CRAB_ANIMATED" -> apiId = "PARTY_HAT_CRAB_" + apiId.replace("PARTY_HAT_CRAB_ANIMATED_", "") + "_ANIMATED";
+ case "CRIMSON_HELMET", "CRIMSON_CHESTPLATE", "CRIMSON_LEGGINGS", "CRIMSON_BOOTS",
+ "AURORA_HELMET", "AURORA_CHESTPLATE", "AURORA_LEGGINGS", "AURORA_BOOTS",
+ "TERROR_HELMET", "TERROR_CHESTPLATE", "TERROR_LEGGINGS", "TERROR_BOOTS" -> apiId = id;
+ case "MIDAS_SWORD", "MIDAS_STAFF" -> apiId = id;
+ default -> apiId = apiId.replace(":", "-");
+ }
+ return apiId;
+ }
+
+ /**
* Gets the bazaar sell price or the lowest bin based on the id of the item stack.
*
* @return An {@link LongBooleanPair} with the {@code left long} representing the item's price,
* and the {@code right boolean} indicating if the price was based on complete data.
*/
public static @NotNull DoubleBooleanPair getItemPrice(@NotNull ItemStack stack) {
- return getItemPrice(getItemId(stack));
+ return getItemPrice(stack.getSkyblockApiId());
}
/**
- * Gets the bazaar sell price or the lowest bin of the item with the specified id.
+ * Gets the bazaar sell price or the lowest bin of the item with the specified skyblock api id.
*
* @return An {@link LongBooleanPair} with the {@code left long} representing the item's price,
* and the {@code right boolean} indicating if the price was based on complete data.
*/
- public static @NotNull DoubleBooleanPair getItemPrice(@Nullable String id) {
+ public static @NotNull DoubleBooleanPair getItemPrice(@Nullable String skyblockApiId) {
JsonObject bazaarPrices = TooltipInfoType.BAZAAR.getData();
JsonObject lowestBinPrices = TooltipInfoType.LOWEST_BINS.getData();
- if (id == null || id.isEmpty() || bazaarPrices == null || lowestBinPrices == null) return DoubleBooleanPair.of(0, false);
+ if (skyblockApiId == null || skyblockApiId.isEmpty() || bazaarPrices == null || lowestBinPrices == null) return DoubleBooleanPair.of(0, false);
- if (bazaarPrices.has(id)) {
- JsonElement sellPrice = bazaarPrices.get(id).getAsJsonObject().get("sellPrice");
+ if (bazaarPrices.has(skyblockApiId)) {
+ JsonElement sellPrice = bazaarPrices.get(skyblockApiId).getAsJsonObject().get("sellPrice");
boolean isPriceNull = sellPrice.isJsonNull();
return DoubleBooleanPair.of(isPriceNull ? 0 : sellPrice.getAsDouble(), !isPriceNull);
}
- if (lowestBinPrices.has(id)) {
- return DoubleBooleanPair.of(lowestBinPrices.get(id).getAsDouble(), true);
+ if (lowestBinPrices.has(skyblockApiId)) {
+ return DoubleBooleanPair.of(lowestBinPrices.get(skyblockApiId).getAsDouble(), true);
}
return DoubleBooleanPair.of(0, false);