From 48b7ba4a8d6ca640db84d1e29605a9c9e70b338b Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Thu, 26 Jun 2025 14:21:23 -0400 Subject: Hunting Box Shard Prices --- .../skyblock/item/tooltip/TooltipManager.java | 3 +- .../tooltip/adders/HuntingBoxPriceTooltip.java | 48 ++++++++++++++++++++++ .../java/de/hysky/skyblocker/utils/ItemUtils.java | 11 +++++ .../resources/assets/skyblocker/lang/en_us.json | 2 +- 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/HuntingBoxPriceTooltip.java diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipManager.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipManager.java index 6c0d93ed..97cb0b36 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipManager.java @@ -46,7 +46,8 @@ public class TooltipManager { new MuseumTooltip(11), new ColorTooltip(12), new AccessoryTooltip(13), - new DateCalculatorTooltip(14) + new DateCalculatorTooltip(14), + new HuntingBoxPriceTooltip(15) }; private static final ArrayList currentScreenAdders = new ArrayList<>(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/HuntingBoxPriceTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/HuntingBoxPriceTooltip.java new file mode 100644 index 00000000..4699e0cd --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/HuntingBoxPriceTooltip.java @@ -0,0 +1,48 @@ +package de.hysky.skyblocker.skyblock.item.tooltip.adders; + +import java.util.List; + +import org.jetbrains.annotations.Nullable; + +import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.skyblock.hunting.Attribute; +import de.hysky.skyblocker.skyblock.hunting.Attributes; +import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.info.TooltipInfoType; +import de.hysky.skyblocker.utils.BazaarProduct; +import de.hysky.skyblocker.utils.ItemUtils; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +public class HuntingBoxPriceTooltip extends SimpleTooltipAdder { + public HuntingBoxPriceTooltip(int priority) { + super("^Hunting Box$", priority); + } + + @Override + public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { + Attribute attribute = Attributes.getAttributeFromItemName(stack); + + if (attribute != null && TooltipInfoType.BAZAAR.hasOrNullWarning(attribute.apiId())) { + int count = ItemUtils.getItemCountInHuntingBox(stack).orElse(1); + BazaarProduct product = TooltipInfoType.BAZAAR.getData().get(attribute.apiId()); + boolean holdingShift = Screen.hasShiftDown(); + String shardText = count > 1 ? "Shards" : "Shard"; + + lines.add(Text.literal(shardText + " Sell Price: ") + .formatted(Formatting.GOLD) + .append(product.sellPrice().isEmpty() + ? Text.literal("No data").formatted(Formatting.RED) + : ItemTooltip.getCoinsMessage(product.sellPrice().getAsDouble() * count, holdingShift ? count : 1, true))); + } + } + + @Override + public boolean isEnabled() { + return SkyblockerConfigManager.get().hunting.huntingBox.enabled; + } +} diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java index dc3f3c5a..878d45c9 100644 --- a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java +++ b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java @@ -70,6 +70,7 @@ public final class ItemUtils { private static final Logger LOGGER = LoggerFactory.getLogger(ItemUtils.class); private static final Pattern STORED_PATTERN = Pattern.compile("Stored: ([\\d,]+)/\\S+"); private static final Pattern STASH_COUNT_PATTERN = Pattern.compile("x([\\d,]+)$"); // This is used with Matcher#find, not #matches + private static final Pattern HUNTING_BOX_COUNT_PATTERN = Pattern.compile("Owned: (?\\d+) Shards?"); private static final short LOG_INTERVAL = 1000; private static long lastLog = Util.getMeasuringTimeMs(); @@ -529,4 +530,14 @@ public final class ItemUtils { public static OptionalInt getItemCountInStash(@NotNull Text itemName) { return RegexUtils.findIntFromMatcher(STASH_COUNT_PATTERN.matcher(itemName.getString())); } + + /** + * Finds the number of shards the player owns inside of the hunting box. + */ + @NotNull + public static OptionalInt getItemCountInHuntingBox(@NotNull ItemStack stack) { + Matcher matcher = ItemUtils.getLoreLineIfContainsMatch(stack, HUNTING_BOX_COUNT_PATTERN); + + return matcher != null ? RegexUtils.parseOptionalIntFromMatcher(matcher, "shards") : OptionalInt.empty(); + } } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 132d2796..ff0bc8ff 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -516,7 +516,7 @@ "skyblocker.config.hunting": "Hunting", "skyblocker.config.hunting.huntingBoxHelper": "Enable Hunting Box Helper", - "skyblocker.config.hunting.huntingBoxHelper.@Tooltip": "Highlights shards that you have enough of to syphon and reach the next tier of the attribute in the Hunting Box.", + "skyblocker.config.hunting.huntingBoxHelper.@Tooltip": "Highlights shards that you have enough of to syphon and reach the next tier of the attribute in the Hunting Box. Also displays the sell price of shards in the tooltip.", "skyblocker.config.chat": "Chat", -- cgit