diff options
| author | appable <enzospiacitelli@gmail.com> | 2023-07-27 02:31:02 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-27 11:31:02 +0200 |
| commit | 8c317b7b1905cb886fd3af50caa0d3b3149d1d86 (patch) | |
| tree | ae8b9277a846f1a26bb58fc47dcf489b16ad7a35 /src/main/java/at/hannibal2/skyhanni/features/fishing | |
| parent | b01b49fd741d4d87b3ced3503e93408e26af18e5 (diff) | |
| download | skyhanni-8c317b7b1905cb886fd3af50caa0d3b3149d1d86.tar.gz skyhanni-8c317b7b1905cb886fd3af50caa0d3b3149d1d86.tar.bz2 skyhanni-8c317b7b1905cb886fd3af50caa0d3b3149d1d86.zip | |
Merge pull request #337
* trophy fillet tooltip; trophy info tooltip in chat
* add new config options for trophy
* fix up some settings
* Merge remote-tracking branch 'upstream/beta' into trophy-data
* using TrophyFishJson to load repo data
* fixed missing separators for total number
* fixed trophy fish sack display
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/fishing')
5 files changed, 178 insertions, 47 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishFillet.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishFillet.kt new file mode 100644 index 000000000..32d31595b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishFillet.kt @@ -0,0 +1,34 @@ +package at.hannibal2.skyhanni.features.fishing + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Keyboard + +class TrophyFishFillet { + + @SubscribeEvent + fun onTooltip(event: LorenzToolTipEvent) { + if (!isEnabled()) return + if (event.slot.inventory.name.contains("Sack")) return + val internalName = event.itemStack.getInternalName() + val trophyFishName = internalName.substringBeforeLast("_") + .replace("_", "").lowercase() + val trophyRarityName = internalName.substringAfterLast("_") + val info = TrophyFishManager.getInfo(trophyFishName) ?: return + val rarity = TrophyRarity.getByName(trophyRarityName) ?: return + val multiplier = if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) event.itemStack.stackSize else 1 + val filletValue = info.getFilletValue(rarity) * multiplier + val filletPrice = filletValue * NEUItems.getPrice("MAGMA_FISH") + event.toolTip.add("§7Fillet: §8${filletValue.addSeparators()} Magmafish §7(§6${NumberUtil.format(filletPrice)}§7)") + } + + private fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.fishing.trophyFilletTooltip + +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishInfo.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishInfo.kt new file mode 100644 index 000000000..104a71a07 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishInfo.kt @@ -0,0 +1,48 @@ +package at.hannibal2.skyhanni.features.fishing + +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.StringUtils.splitLines +import com.google.gson.annotations.Expose +import net.minecraft.event.HoverEvent +import net.minecraft.util.ChatComponentText +import net.minecraft.util.ChatStyle + +data class TrophyFishInfo( + @Expose + val displayName: String, + @Expose + private val description: String, + @Expose + private val rate: Int?, + @Expose + private val fillet: Map<TrophyRarity, Int> +) { + + // Credit to NotEnoughUpdates (Trophy Fish profile viewer page) for the format. + fun getTooltip(counts: Map<TrophyRarity, Int>): ChatStyle { + val bestFishObtained = counts.keys.maxOrNull() ?: TrophyRarity.BRONZE + val display = """ + |$displayName §8[§7$rate%§8] + |${description.splitLines(150)} + | + |${TrophyRarity.DIAMOND.formattedString}: ${formatCount(counts, TrophyRarity.DIAMOND)} + |${TrophyRarity.GOLD.formattedString}: ${formatCount(counts, TrophyRarity.GOLD)} + |${TrophyRarity.SILVER.formattedString}: ${formatCount(counts, TrophyRarity.SILVER)} + |${TrophyRarity.BRONZE.formattedString}: ${formatCount(counts, TrophyRarity.BRONZE)} + | + |§7Total: ${bestFishObtained.formatCode}${counts.values.sum().addSeparators()} + """.trimMargin() + return ChatStyle().setChatHoverEvent( + HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText(display)) + ) + } + + fun getFilletValue(rarity: TrophyRarity): Int { + return fillet.getOrDefault(rarity, -1) + } + + private fun formatCount(counts: Map<TrophyRarity, Int>, rarity: TrophyRarity): String { + val count = counts.getOrDefault(rarity, 0) + return if (count > 0) "§6${count.addSeparators()}" else "§c✖" + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishManager.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishManager.kt new file mode 100644 index 000000000..df8c95d57 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishManager.kt @@ -0,0 +1,62 @@ +package at.hannibal2.skyhanni.features.fishing + +import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent +import at.hannibal2.skyhanni.events.ProfileJoinEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.jsonobjects.TrophyFishJson +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + + +class TrophyFishManager { + + @SubscribeEvent + fun onProfileJoin(event: ProfileJoinEvent) { + hasLoadedTrophyFish = false + } + + @SubscribeEvent + fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) { + if (hasLoadedTrophyFish) return + val trophyFishes = fishes ?: return + val profileData = event.profileData + trophyFishes.clear() + for ((rawName, value) in profileData["trophy_fish"].asJsonObject.entrySet()) { + val rarity = TrophyRarity.getByName(rawName) ?: continue + val text = rawName.replace("_", "") + val displayName = text.substring(0, text.length - rarity.name.length) + + val amount = value.asInt + val rarities = trophyFishes.getOrPut(displayName) { mutableMapOf() } + rarities[rarity] = amount + hasLoadedTrophyFish = true + } + } + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + try { + val json = event.getConstant<TrophyFishJson>("TrophyFish") + ?: error("Could not read repo data from TrophyFish.json") + trophyFishInfo = json.trophy_fish + LorenzUtils.debug("Loaded trophy fish from repo") + } catch (e: Exception) { + e.printStackTrace() + LorenzUtils.error("error in RepositoryReloadEvent") + } + } + + companion object { + private var hasLoadedTrophyFish = false + + val fishes: MutableMap<String, MutableMap<TrophyRarity, Int>>? + get() = ProfileStorageData.profileSpecific?.crimsonIsle?.trophyFishes + + private var trophyFishInfo = mapOf<String, TrophyFishInfo>() + + fun getInfo(internalName: String) = trophyFishInfo[internalName] + + fun getInfoByName(name: String) = trophyFishInfo.values.find { it.displayName == name } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt index bdefdebf6..b655c9893 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt @@ -1,10 +1,8 @@ package at.hannibal2.skyhanni.features.fishing import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent -import at.hannibal2.skyhanni.events.ProfileJoinEvent +import at.hannibal2.skyhanni.features.fishing.TrophyFishManager.Companion.fishes import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut import at.hannibal2.skyhanni.utils.LorenzUtils.sumAllValues @@ -16,54 +14,29 @@ import net.minecraft.util.ChatComponentText import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class TrophyFishMessages { - private var hasLoadedTrophyFish = false - private val fishes get() = ProfileStorageData.profileSpecific?.crimsonIsle?.trophyFishes private val trophyFishPattern = Regex("§6§lTROPHY FISH! §r§bYou caught an? §r(?<displayName>§[0-9a-f](?:§k)?[\\w -]+)§r§r§r §r§l§r(?<displayRarity>§[0-9a-f]§l\\w+)§r§b\\.") private val config get() = SkyHanniMod.feature.fishing @SubscribeEvent - fun onProfileJoin(event: ProfileJoinEvent) { - hasLoadedTrophyFish = false - } - - @SubscribeEvent - fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) { - if (hasLoadedTrophyFish) return - val trophyFishes = fishes ?: return - val profileData = event.profileData - trophyFishes.clear() - for ((rawName, value) in profileData["trophy_fish"].asJsonObject.entrySet()) { - val rarity = getByName(rawName) ?: continue - val text = rawName.replace("_", "") - val displayName = text.substring(0, text.length - rarity.name.length) - - val amount = value.asInt - val rarities = trophyFishes.getOrPut(displayName) { mutableMapOf() } - rarities[rarity] = amount - hasLoadedTrophyFish = true - } - } - - @SubscribeEvent fun onStatusBar(event: LorenzChatEvent) { - if (!LorenzUtils.inSkyBlock || !config.trophyCounter) return + if (!LorenzUtils.inSkyBlock) return val match = trophyFishPattern.matchEntire(event.message)?.groups ?: return val displayName = match["displayName"]!!.value.replace("§k", "") val displayRarity = match["displayRarity"]!!.value - val fishName = displayName.replace("Obfuscated", "Obfuscated Fish") + val internalName = displayName.replace("Obfuscated", "Obfuscated Fish") .replace("[- ]".toRegex(), "").lowercase().removeColor() val rawRarity = displayRarity.lowercase().removeColor() - val rarity = getByName(rawRarity) ?: return + val rarity = TrophyRarity.getByName(rawRarity) ?: return val trophyFishes = fishes ?: return - val rarities = trophyFishes.getOrPut(fishName) { mutableMapOf() } - val amount = rarities.addOrPut(rarity, 1) + val trophyFishCounts = trophyFishes.getOrPut(internalName) { mutableMapOf() } + val amount = trophyFishCounts.addOrPut(rarity, 1) event.blockedReason = "trophy_fish" - if (config.trophyDesign == 0 && amount == 1) { + if (config.trophyCounter && config.trophyDesign == 0 && amount == 1) { LorenzUtils.chat("§6§lTROPHY FISH! §c§lFIRST §r$displayRarity $displayName") return } @@ -71,23 +44,26 @@ class TrophyFishMessages { if (config.trophyFishBronzeHider && rarity == TrophyRarity.BRONZE && amount != 1) return if (config.trophyFishSilverHider && rarity == TrophyRarity.SILVER && amount != 1) return val totalText = if (config.trophyFishTotalAmount) { - val total = rarities.sumAllValues() + val total = trophyFishCounts.sumAllValues() " §7(${total.addSeparators()}. total)" } else "" - val trophyMessage = "§6§lTROPHY FISH! " + when (config.trophyDesign) { - 0 -> "§7$amount. §r$displayRarity $displayName$totalText" - 1 -> "§bYou caught a $displayName $displayRarity§b. §7(${amount.addSeparators()})$totalText" - else -> "§bYou caught your ${amount.addSeparators()}${amount.ordinal()} $displayRarity $displayName§b.$totalText" + val component = ChatComponentText(if (config.trophyCounter) { + "§6§lTROPHY FISH! " + when (config.trophyDesign) { + 0 -> "§7$amount. §r$displayRarity $displayName$totalText" + 1 -> "§bYou caught a $displayName $displayRarity§b. §7(${amount.addSeparators()})$totalText" + else -> "§bYou caught your ${amount.addSeparators()}${amount.ordinal()} $displayRarity $displayName§b.$totalText" + } + } else event.message) + + if (config.trophyFishTooltip) { + TrophyFishManager.getInfo(internalName)?.let { + component.chatStyle = it.getTooltip(trophyFishCounts) + } } Minecraft.getMinecraft().ingameGUI.chatGUI.printChatMessageWithOptionalDeletion( - ChatComponentText(trophyMessage), - if (config.trophyFishDuplicateHider) (fishName + rarity).hashCode() else 0 + component, if (config.trophyFishDuplicateHider) (internalName + rarity).hashCode() else 0 ) } - - fun getByName(rawName: String) = TrophyRarity.values().firstOrNull { rawName.uppercase().endsWith(it.name) } - - data class TrophyFish(val rarities: MutableMap<TrophyRarity, Int> = mutableMapOf()) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt index b87d3d60e..d4df5f2eb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt @@ -1,5 +1,16 @@ package at.hannibal2.skyhanni.features.fishing -enum class TrophyRarity { - BRONZE, SILVER, GOLD, DIAMOND; +import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase + +enum class TrophyRarity(val formatCode: String) { + BRONZE("§8"), + SILVER("§7"), + GOLD("§6"), + DIAMOND("§b"); + + val formattedString get() = "$formatCode${name.firstLetterUppercase()}" + + companion object { + fun getByName(rawName: String) = values().firstOrNull { rawName.uppercase().endsWith(it.name) } + } }
\ No newline at end of file |
