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 | |
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')
3 files changed, 84 insertions, 23 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/HoppityEggLocationsJson.kt b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/HoppityEggLocationsJson.kt index 4ad81b06a..ead4eb83c 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/HoppityEggLocationsJson.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/HoppityEggLocationsJson.kt @@ -23,6 +23,13 @@ data class HoppityEggLocationsJson( @Expose val maxRabbits: Int, @Expose val maxPrestige: Int, @Expose val chocolateMilestones: TreeSet<Long>, + @Expose val chocolateShopMilestones: List<MilestoneJson>, + @Expose val chocolateFactoryMilestones: List<MilestoneJson>, @Expose val apiEggLocations: Map<IslandType, Map<String, LorenzVec>>, @Expose val specialRabbits: List<String>, ) + +data class MilestoneJson( + @Expose val amount: Long, + @Expose val rabbit: String, +) 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 diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt index 40cd700c4..112e8a7a7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.config.features.inventory.chocolatefactory.Chocolat import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage.ChocolateFactoryStorage import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.data.jsonobjects.repo.HoppityEggLocationsJson +import at.hannibal2.skyhanni.data.jsonobjects.repo.MilestoneJson import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.event.hoppity.HoppityCollectionStats @@ -80,7 +81,9 @@ object ChocolateFactoryAPI { var shrineIndex = 41 var coachRabbitIndex = 42 var maxRabbits = 395 - var chocolateMilestones = TreeSet<Long>() + private var chocolateMilestones = TreeSet<Long>() + private var chocolateFactoryMilestones: MutableList<MilestoneJson> = mutableListOf() + private var chocolateShopMilestones: MutableList<MilestoneJson> = mutableListOf() private var maxPrestige = 5 var inChocolateFactory = false @@ -143,6 +146,8 @@ object ChocolateFactoryAPI { maxRabbits = data.maxRabbits maxPrestige = data.maxPrestige chocolateMilestones = data.chocolateMilestones + chocolateFactoryMilestones = data.chocolateFactoryMilestones.toMutableList() + chocolateShopMilestones = data.chocolateShopMilestones.toMutableList() specialRabbitTextures = data.specialRabbits ChocolateFactoryUpgrade.updateIgnoredSlots() @@ -226,4 +231,12 @@ object ChocolateFactoryAPI { val basePerSecond = rawChocolatePerSecond * baseMultiplier return (needed / basePerSecond + secondsUntilTowerExpires).seconds } + + fun milestoneByRabbit(rabbitName: String): MilestoneJson? { + return chocolateFactoryMilestones.firstOrNull { + it.rabbit.removeColor() == rabbitName.removeColor() + } ?: chocolateShopMilestones.firstOrNull { + it.rabbit.removeColor() == rabbitName.removeColor() + } + } } |