From 868141524e82639f6aaf5e577e2b9441925617d0 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 3 Aug 2023 19:46:38 +0200 Subject: moving trophy fishing classes into own package --- .../skyhanni/features/fishing/OdgerWaypoint.kt | 55 ----------------- .../skyhanni/features/fishing/TrophyFishFillet.kt | 33 ----------- .../skyhanni/features/fishing/TrophyFishInfo.kt | 53 ----------------- .../skyhanni/features/fishing/TrophyFishManager.kt | 62 ------------------- .../features/fishing/TrophyFishMessages.kt | 69 ---------------------- .../skyhanni/features/fishing/TrophyRarity.kt | 16 ----- .../features/fishing/trophy/OdgerWaypoint.kt | 55 +++++++++++++++++ .../features/fishing/trophy/TrophyFishFillet.kt | 33 +++++++++++ .../features/fishing/trophy/TrophyFishInfo.kt | 53 +++++++++++++++++ .../features/fishing/trophy/TrophyFishManager.kt | 62 +++++++++++++++++++ .../features/fishing/trophy/TrophyFishMessages.kt | 69 ++++++++++++++++++++++ .../features/fishing/trophy/TrophyRarity.kt | 16 +++++ .../skyhanni/features/inventory/SackDisplay.kt | 4 +- 13 files changed, 290 insertions(+), 290 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/OdgerWaypoint.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishFillet.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishInfo.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishManager.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/OdgerWaypoint.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishFillet.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishInfo.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyRarity.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/OdgerWaypoint.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/OdgerWaypoint.kt deleted file mode 100644 index bfcb94908..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/OdgerWaypoint.kt +++ /dev/null @@ -1,55 +0,0 @@ -package at.hannibal2.skyhanni.features.fishing - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled -import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzVec -import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText -import net.minecraftforge.client.event.RenderWorldLastEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class OdgerWaypoint { - private val location = LorenzVec(-373, 207, -808) - - private var hasLavaRodInHand = false - private var trophyFishInInv = false - - @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - if (!isEnabled()) return - - if (event.isMod(10)) { - hasLavaRodInHand = isLavaFishingRod() - - trophyFishInInv = InventoryUtils.getItemsInOwnInventory().map { it.getLore() } - .any { it.isNotEmpty() && it.last().endsWith("TROPHY FISH") } - } - } - - private fun isLavaFishingRod(): Boolean { - val heldItem = InventoryUtils.getItemInHand() ?: return false - val isRod = heldItem.name?.contains("Rod") ?: return false - if (!isRod) return false - - return heldItem.getLore().any { it.contains("Lava Rod") } - } - - @SubscribeEvent - fun onRenderWorld(event: RenderWorldLastEvent) { - if (!isEnabled()) return - if (hasLavaRodInHand) return - if (!trophyFishInInv) return - - event.drawWaypointFilled(location, LorenzColor.WHITE.toColor()) - event.drawDynamicText(location, "Odger", 1.5) - } - - fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.fishing.odgerLocation && - LorenzUtils.skyBlockIsland == IslandType.CRIMSON_ISLE -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishFillet.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishFillet.kt deleted file mode 100644 index 69e1a0efc..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishFillet.kt +++ /dev/null @@ -1,33 +0,0 @@ -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.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 deleted file mode 100644 index 395fea310..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishInfo.kt +++ /dev/null @@ -1,53 +0,0 @@ -package at.hannibal2.skyhanni.features.fishing - -import at.hannibal2.skyhanni.test.command.CopyErrorCommand -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 -) { - - // Credit to NotEnoughUpdates (Trophy Fish profile viewer page) for the format. - fun getTooltip(counts: Map): 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 { - if (fillet == null) { - CopyErrorCommand.logError(Error("fillet is null for '$displayName'"), "Error trying to read trophy fish info") - return -1 - } - return fillet.getOrDefault(rarity, -1) - } - - private fun formatCount(counts: Map, 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 deleted file mode 100644 index df8c95d57..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishManager.kt +++ /dev/null @@ -1,62 +0,0 @@ -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("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>? - get() = ProfileStorageData.profileSpecific?.crimsonIsle?.trophyFishes - - private var trophyFishInfo = mapOf() - - 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 deleted file mode 100644 index b655c9893..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt +++ /dev/null @@ -1,69 +0,0 @@ -package at.hannibal2.skyhanni.features.fishing - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.LorenzChatEvent -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 -import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.NumberUtil.ordinal -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraft.client.Minecraft -import net.minecraft.util.ChatComponentText -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class TrophyFishMessages { - private val trophyFishPattern = - Regex("§6§lTROPHY FISH! §r§bYou caught an? §r(?§[0-9a-f](?:§k)?[\\w -]+)§r§r§r §r§l§r(?§[0-9a-f]§l\\w+)§r§b\\.") - private val config get() = SkyHanniMod.feature.fishing - - @SubscribeEvent - fun onStatusBar(event: LorenzChatEvent) { - 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 internalName = displayName.replace("Obfuscated", "Obfuscated Fish") - .replace("[- ]".toRegex(), "").lowercase().removeColor() - val rawRarity = displayRarity.lowercase().removeColor() - val rarity = TrophyRarity.getByName(rawRarity) ?: return - - val trophyFishes = fishes ?: return - val trophyFishCounts = trophyFishes.getOrPut(internalName) { mutableMapOf() } - val amount = trophyFishCounts.addOrPut(rarity, 1) - event.blockedReason = "trophy_fish" - - if (config.trophyCounter && config.trophyDesign == 0 && amount == 1) { - LorenzUtils.chat("§6§lTROPHY FISH! §c§lFIRST §r$displayRarity $displayName") - return - } - - 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 = trophyFishCounts.sumAllValues() - " §7(${total.addSeparators()}. total)" - } else "" - - 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( - component, if (config.trophyFishDuplicateHider) (internalName + rarity).hashCode() else 0 - ) - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt deleted file mode 100644 index d4df5f2eb..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt +++ /dev/null @@ -1,16 +0,0 @@ -package at.hannibal2.skyhanni.features.fishing - -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 diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/OdgerWaypoint.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/OdgerWaypoint.kt new file mode 100644 index 000000000..4202d2600 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/OdgerWaypoint.kt @@ -0,0 +1,55 @@ +package at.hannibal2.skyhanni.features.fishing.trophy + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText +import net.minecraftforge.client.event.RenderWorldLastEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class OdgerWaypoint { + private val location = LorenzVec(-373, 207, -808) + + private var hasLavaRodInHand = false + private var trophyFishInInv = false + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!isEnabled()) return + + if (event.isMod(10)) { + hasLavaRodInHand = isLavaFishingRod() + + trophyFishInInv = InventoryUtils.getItemsInOwnInventory().map { it.getLore() } + .any { it.isNotEmpty() && it.last().endsWith("TROPHY FISH") } + } + } + + private fun isLavaFishingRod(): Boolean { + val heldItem = InventoryUtils.getItemInHand() ?: return false + val isRod = heldItem.name?.contains("Rod") ?: return false + if (!isRod) return false + + return heldItem.getLore().any { it.contains("Lava Rod") } + } + + @SubscribeEvent + fun onRenderWorld(event: RenderWorldLastEvent) { + if (!isEnabled()) return + if (hasLavaRodInHand) return + if (!trophyFishInInv) return + + event.drawWaypointFilled(location, LorenzColor.WHITE.toColor()) + event.drawDynamicText(location, "Odger", 1.5) + } + + fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.fishing.odgerLocation && + LorenzUtils.skyBlockIsland == IslandType.CRIMSON_ISLE +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishFillet.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishFillet.kt new file mode 100644 index 000000000..69c65aa15 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishFillet.kt @@ -0,0 +1,33 @@ +package at.hannibal2.skyhanni.features.fishing.trophy + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +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/trophy/TrophyFishInfo.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishInfo.kt new file mode 100644 index 000000000..8fd402fee --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishInfo.kt @@ -0,0 +1,53 @@ +package at.hannibal2.skyhanni.features.fishing.trophy + +import at.hannibal2.skyhanni.test.command.CopyErrorCommand +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 +) { + + // Credit to NotEnoughUpdates (Trophy Fish profile viewer page) for the format. + fun getTooltip(counts: Map): 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 { + if (fillet == null) { + CopyErrorCommand.logError(Error("fillet is null for '$displayName'"), "Error trying to read trophy fish info") + return -1 + } + return fillet.getOrDefault(rarity, -1) + } + + private fun formatCount(counts: Map, 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/trophy/TrophyFishManager.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt new file mode 100644 index 000000000..c2f8c508d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt @@ -0,0 +1,62 @@ +package at.hannibal2.skyhanni.features.fishing.trophy + +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("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>? + get() = ProfileStorageData.profileSpecific?.crimsonIsle?.trophyFishes + + private var trophyFishInfo = mapOf() + + 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/trophy/TrophyFishMessages.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt new file mode 100644 index 000000000..423a393f1 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt @@ -0,0 +1,69 @@ +package at.hannibal2.skyhanni.features.fishing.trophy + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager.Companion.fishes +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut +import at.hannibal2.skyhanni.utils.LorenzUtils.sumAllValues +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.ordinal +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraft.client.Minecraft +import net.minecraft.util.ChatComponentText +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class TrophyFishMessages { + private val trophyFishPattern = + Regex("§6§lTROPHY FISH! §r§bYou caught an? §r(?§[0-9a-f](?:§k)?[\\w -]+)§r§r§r §r§l§r(?§[0-9a-f]§l\\w+)§r§b\\.") + private val config get() = SkyHanniMod.feature.fishing + + @SubscribeEvent + fun onStatusBar(event: LorenzChatEvent) { + 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 internalName = displayName.replace("Obfuscated", "Obfuscated Fish") + .replace("[- ]".toRegex(), "").lowercase().removeColor() + val rawRarity = displayRarity.lowercase().removeColor() + val rarity = TrophyRarity.getByName(rawRarity) ?: return + + val trophyFishes = fishes ?: return + val trophyFishCounts = trophyFishes.getOrPut(internalName) { mutableMapOf() } + val amount = trophyFishCounts.addOrPut(rarity, 1) + event.blockedReason = "trophy_fish" + + if (config.trophyCounter && config.trophyDesign == 0 && amount == 1) { + LorenzUtils.chat("§6§lTROPHY FISH! §c§lFIRST §r$displayRarity $displayName") + return + } + + 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 = trophyFishCounts.sumAllValues() + " §7(${total.addSeparators()}. total)" + } else "" + + 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( + component, if (config.trophyFishDuplicateHider) (internalName + rarity).hashCode() else 0 + ) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyRarity.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyRarity.kt new file mode 100644 index 000000000..2e61e1e80 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyRarity.kt @@ -0,0 +1,16 @@ +package at.hannibal2.skyhanni.features.fishing.trophy + +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 diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt index ef2d9b359..2b24ab1f1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt @@ -5,8 +5,8 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi -import at.hannibal2.skyhanni.features.fishing.TrophyFishManager -import at.hannibal2.skyhanni.features.fishing.TrophyRarity +import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager +import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name -- cgit