diff options
author | David Cole <40234707+DavidArthurCole@users.noreply.github.com> | 2024-09-20 17:19:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-20 23:19:57 +0200 |
commit | 62d45680f79c47479fe7d16a651eb8c7081586fe (patch) | |
tree | 432b869cfac4f8e4e99bf3bf7ddbe2f580631e55 /src/main/java/at/hannibal2/skyhanni/features/event | |
parent | e026faba64c611d9b3cb6bde0337d59f02ffce63 (diff) | |
download | skyhanni-62d45680f79c47479fe7d16a651eb8c7081586fe.tar.gz skyhanni-62d45680f79c47479fe7d16a651eb8c7081586fe.tar.bz2 skyhanni-62d45680f79c47479fe7d16a651eb8c7081586fe.zip |
Improvement (?): Descriptive Milestones in Hoppity Collection (#2523)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/event')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt | 85 |
1 files changed, 63 insertions, 22 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt index d513c3bec..378291966 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt @@ -26,13 +26,13 @@ import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatInt +import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat import at.hannibal2.skyhanni.utils.RegexUtils.anyMatches import at.hannibal2.skyhanni.utils.RegexUtils.findMatcher import at.hannibal2.skyhanni.utils.RegexUtils.firstMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables -import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getMinecraftId import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -187,29 +187,14 @@ object HoppityCollectionStats { strayRabbit to HighlightRabbitTypes.STRAYS, ) + private fun missingRabbitStackNeedsFix(stack: ItemStack): Boolean = + stack.item == Items.dye && (stack.metadata == 8 || stack.getLore().any { it.lowercase().contains("milestone") }) + + private val replacementCache: MutableMap<String, ItemStack> = mutableMapOf() + @SubscribeEvent fun replaceItem(event: ReplaceItemEvent) { - if (!config.rarityDyeRecolor || !pagePattern.matches(event.inventory.name)) return - val item = event.originalItem - // The "base" missing rabbits are Gray Dye (minecraft:dye with metadata 8) - if (item.getMinecraftId().toString() != "minecraft:dye" || item.metadata != 8) return - - val rarity = HoppityAPI.rarityByRabbit(item.displayName) - // Add NBT for the dye color itself - val newItemStack = ItemStack(Items.dye, 1, when (rarity) { - LorenzRarity.COMMON -> 7 // Light gray dye - LorenzRarity.UNCOMMON -> 10 // Lime dye - LorenzRarity.RARE -> 4 // Lapis lazuli - LorenzRarity.EPIC -> 5 // Purple dye - LorenzRarity.LEGENDARY -> 14 // Orange dye - LorenzRarity.MYTHIC -> 13 // Magenta dye - LorenzRarity.DIVINE -> 12 // Light blue dye - LorenzRarity.SPECIAL -> 1 // Rose Red - Covering bases for future (?) - else -> return - }) - newItemStack.setLore(item.getLore()) - newItemStack.setStackDisplayName(item.displayName) - event.replace(newItemStack) + replacementCache[event.originalItem.displayName]?.let { event.replace(it) } } @SubscribeEvent @@ -221,6 +206,29 @@ object HoppityCollectionStats { return } + event.inventoryItems.values.filter { it.hasDisplayName() && missingRabbitStackNeedsFix(it) }.forEach { stack -> + val rarity = HoppityAPI.rarityByRabbit(stack.displayName) + // Add NBT for the dye color itself + val newItemStack = if (config.rarityDyeRecolor) ItemStack( + Items.dye, 1, + when (rarity) { + LorenzRarity.COMMON -> 7 // Light gray dye + LorenzRarity.UNCOMMON -> 10 // Lime dye + LorenzRarity.RARE -> 4 // Lapis lazuli + LorenzRarity.EPIC -> 5 // Purple dye + LorenzRarity.LEGENDARY -> 14 // Orange dye + LorenzRarity.MYTHIC -> 13 // Magenta dye + LorenzRarity.DIVINE -> 12 // Light blue dye + LorenzRarity.SPECIAL -> 1 // Rose Red - Covering bases for future (?) + else -> return + }, + ) else ItemStack(Items.dye, 8) + + newItemStack.setLore(buildDescriptiveMilestoneLore(stack)) + newItemStack.setStackDisplayName(stack.displayName) + replacementCache[stack.displayName] = newItemStack + } + inInventory = true if (config.hoppityCollectionStats) { display = buildDisplay(event) @@ -231,6 +239,38 @@ object HoppityCollectionStats { } } + private fun buildDescriptiveMilestoneLore(itemStack: ItemStack): List<String> { + val existingLore = itemStack.getLore().toMutableList() + var replaceIndex: Int? = null + var milestoneType: HoppityEggType = HoppityEggType.BREAKFAST + + if (factoryMilestone.anyMatches(existingLore)) { + milestoneType = HoppityEggType.CHOCOLATE_FACTORY_MILESTONE + replaceIndex = existingLore.indexOfFirst { loreMatch -> factoryMilestone.matches(loreMatch) } + } else if (shopMilestone.anyMatches(existingLore)) { + milestoneType = HoppityEggType.CHOCOLATE_SHOP_MILESTONE + replaceIndex = existingLore.indexOfFirst { loreMatch -> shopMilestone.matches(loreMatch) } + } + + replaceIndex?.let { + ChocolateFactoryAPI.milestoneByRabbit(itemStack.displayName)?.let { + val displayAmount = it.amount.shortFormat() + val operationFormat = when (milestoneType) { + HoppityEggType.CHOCOLATE_SHOP_MILESTONE -> "spending" + HoppityEggType.CHOCOLATE_FACTORY_MILESTONE -> "reaching" + else -> "" // Never happens + } + + //List indexing is weird + existingLore[replaceIndex - 1] = "§7Obtained by $operationFormat §6$displayAmount" + existingLore[replaceIndex] = "§7all-time §6Chocolate." + return existingLore + } + } + + return existingLore + } + private fun filterRabbitToHighlight(stack: ItemStack) { val lore = stack.getLore() @@ -259,6 +299,7 @@ object HoppityCollectionStats { fun onInventoryClose(event: InventoryCloseEvent) { inInventory = false display = emptyList() + replacementCache.clear() } @SubscribeEvent |