aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-05-25 09:15:51 +1000
committerGitHub <noreply@github.com>2023-05-25 01:15:51 +0200
commita9b2e710c90b35b13f1a5c32622f91cad29f1e52 (patch)
tree1e9836303a8d175f04880d769d5651544b983cce /src/main/java/at/hannibal2/skyhanni
parent6a2304c0bd2b46b23180c393a1c254296986118a (diff)
downloadskyhanni-a9b2e710c90b35b13f1a5c32622f91cad29f1e52.tar.gz
skyhanni-a9b2e710c90b35b13f1a5c32622f91cad29f1e52.tar.bz2
skyhanni-a9b2e710c90b35b13f1a5c32622f91cad29f1e52.zip
More additions to the farming tooltips (#174)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt34
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt84
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt2
3 files changed, 84 insertions, 36 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt
index 9159c18ee..a4bff0222 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt
@@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getHoeCounter
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -148,6 +149,11 @@ class FarmingFortuneDisplay {
private val collectionPattern = "§7You have §6\\+([\\d]{1,3})☘ Farming Fortune".toRegex()
+ var displayedFortune = 0.0
+ var reforgeFortune = 0.0
+ var itemBaseFortune = 0.0
+ var greenThumbFortune = 0.0
+
fun getToolFortune(tool: ItemStack?): Double {
val internalName = tool?.getInternalName() ?: return 0.0
return if (internalName.startsWith("THEORETICAL_HOE")) {
@@ -190,6 +196,34 @@ class FarmingFortuneDisplay {
return dedicationMultiplier * cropMilestone
}
+ fun getSunderFortune(tool: ItemStack?): Double { return (tool?.getEnchantments()?.get("sunder") ?: 0) * 12.5 }
+ fun getHarvestingFortune(tool: ItemStack?): Double { return (tool?.getEnchantments()?.get("harvesting") ?: 0) * 12.5 }
+ fun getCultivatingFortune(tool: ItemStack?): Double { return (tool?.getEnchantments()?.get("cultivating") ?: 0).toDouble()}
+
+ fun getAbilityFortune(tool: ItemStack?): Double { // add armor ability stuff here
+ val lotusAbilityPattern = "§7Piece Bonus: §6+(?<bonus>.*)☘".toPattern()
+ if (tool?.getInternalName()?.contains("LOTUS") == true) {
+ for (line in tool.getLore()) {
+ lotusAbilityPattern.matchMatcher(line) {
+ return group("bonus").toDouble()
+ }
+ }
+ }
+ return 0.0
+ }
+
+ fun loadFortuneLineData(tool: ItemStack?, enchantmentFortune: Double, match: MatchGroupCollection) {
+ displayedFortune = match[1]!!.value.toDouble()
+ reforgeFortune = match[2]!!.value.toDouble()
+ if (tool != null) {
+ itemBaseFortune = if (tool.getInternalName().contains("LOTUS")) 5.0
+ else displayedFortune - reforgeFortune - enchantmentFortune
+ greenThumbFortune = if (tool.getInternalName().contains("LOTUS")) {
+ displayedFortune - reforgeFortune - itemBaseFortune
+ } else 0.0
+ }
+ }
+
fun getCurrentFarmingFortune(alwaysBaseFortune: Boolean = false): Double {
val upgradeFortune = upgradeFortune ?: 0.0
val accessoryFortune = accessoryFortune ?: 0.0
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt
index 5c3e6d433..668848ce8 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt
@@ -2,9 +2,10 @@ package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
+import at.hannibal2.skyhanni.features.garden.FarmingFortuneDisplay.Companion.getAbilityFortune
import at.hannibal2.skyhanni.features.garden.GardenAPI.getCropType
+import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getFarmingForDummiesCount
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getReforgeName
import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase
@@ -15,30 +16,34 @@ import kotlin.math.roundToInt
class ToolTooltipTweaks {
private val config get() = SkyHanniMod.feature.garden
- private val tooltipFortunePattern = "^§5§o§7Farming Fortune: §a\\+([\\d.]+)(?: §2\\(\\+\\d\\))?(?: §9\\(\\+(\\d+)\\))\$".toRegex()
+ private val tooltipFortunePattern =
+ "^§5§o§7Farming Fortune: §a\\+([\\d.]+)(?: §2\\(\\+\\d\\))?(?: §9\\(\\+(\\d+)\\))\$".toRegex()
private val counterStartLine = setOf("§5§o§6Logarithmic Counter", "§5§o§6Collection Analysis")
-
private val reforgeEndLine = setOf("§5§o", "§5§o§7chance for multiple crops.")
+ private val statFormatter = DecimalFormat("0.##")
@SubscribeEvent
fun onTooltip(event: LorenzToolTipEvent) {
if (!LorenzUtils.inSkyBlock) return
- val crop = event.itemStack.getCropType() ?: return
- val toolFortune = FarmingFortuneDisplay.getToolFortune(event.itemStack)
- val counterFortune = FarmingFortuneDisplay.getCounterFortune(event.itemStack)
- val collectionFortune = FarmingFortuneDisplay.getCollectionFortune(event.itemStack)
- val turboCropFortune = FarmingFortuneDisplay.getTurboCropFortune(event.itemStack, crop)
- val dedicationFortune = FarmingFortuneDisplay.getDedicationFortune(event.itemStack, crop)
-
- val reforgeName = event.itemStack.getReforgeName()?.firstLetterUppercase()
- val enchantments = event.itemStack.getEnchantments() ?: emptyMap()
- val sunderFortune = (enchantments["sunder"] ?: 0) * 12.5
- val harvestingFortune = (enchantments["harvesting"] ?: 0) * 12.5
- val cultivatingFortune = (enchantments["cultivating"] ?: 0).toDouble()
-
- val ffdFortune = event.itemStack.getFarmingForDummiesCount()?.toDouble() ?: 0.0
- val cropFortune = (toolFortune + counterFortune + collectionFortune + turboCropFortune + dedicationFortune)
+ val itemStack = event.itemStack
+ val crop = itemStack.getCropType()
+ val toolFortune = FarmingFortuneDisplay.getToolFortune(itemStack)
+ val counterFortune = FarmingFortuneDisplay.getCounterFortune(itemStack)
+ val collectionFortune = FarmingFortuneDisplay.getCollectionFortune(itemStack)
+ val turboCropFortune = FarmingFortuneDisplay.getTurboCropFortune(itemStack, crop)
+ val dedicationFortune = FarmingFortuneDisplay.getDedicationFortune(itemStack, crop)
+
+ val reforgeName = itemStack.getReforgeName()?.firstLetterUppercase()
+
+ val sunderFortune = FarmingFortuneDisplay.getSunderFortune(itemStack)
+ val harvestingFortune = FarmingFortuneDisplay.getHarvestingFortune(itemStack)
+ val cultivatingFortune = FarmingFortuneDisplay.getCultivatingFortune(itemStack)
+ val abilityFortune = getAbilityFortune(itemStack)
+
+ val ffdFortune = itemStack.getFarmingForDummiesCount() ?: 0
+ val hiddenFortune =
+ (toolFortune + counterFortune + collectionFortune + turboCropFortune + dedicationFortune + abilityFortune)
val iterator = event.toolTip.listIterator()
var removingFarmhandDescription = false
@@ -48,13 +53,21 @@ class ToolTooltipTweaks {
for (line in iterator) {
val match = tooltipFortunePattern.matchEntire(line)?.groups
if (match != null) {
- val displayedFortune = match[1]!!.value.toDouble()
- val reforgeFortune = match[2]!!.value.toDouble()
- val totalFortune = displayedFortune + cropFortune
+ val enchantmentFortune = sunderFortune + harvestingFortune + cultivatingFortune
+
+ FarmingFortuneDisplay.loadFortuneLineData(itemStack, enchantmentFortune, match)
+
+ val displayedFortune = FarmingFortuneDisplay.displayedFortune
+ val reforgeFortune = FarmingFortuneDisplay.reforgeFortune
+ val baseFortune = FarmingFortuneDisplay.itemBaseFortune
+ val greenThumbFortune = FarmingFortuneDisplay.greenThumbFortune
+
+ val totalFortune = displayedFortune + hiddenFortune
- val ffdString = if (ffdFortune != 0.0) " §2(+${ffdFortune.formatStat()})" else ""
+
+ val ffdString = if (ffdFortune != 0) " §2(+${ffdFortune.formatStat()})" else ""
val reforgeString = if (reforgeFortune != 0.0) " §9(+${reforgeFortune.formatStat()})" else ""
- val cropString = if (cropFortune != 0.0) " §6[+${cropFortune.roundToInt()}]" else ""
+ val cropString = if (hiddenFortune != 0.0) " §6[+${hiddenFortune.roundToInt()}]" else ""
val fortuneLine = when (config.cropTooltipFortune) {
0 -> "§7Farming Fortune: §a+${displayedFortune.formatStat()}$ffdString$reforgeString"
@@ -64,12 +77,15 @@ class ToolTooltipTweaks {
iterator.set(fortuneLine)
if (Keyboard.isKeyDown(config.fortuneTooltipKeybind)) {
+ iterator.addStat(" §7Base: §a+", baseFortune)
+ iterator.addStat(" §7Tool: §6+", toolFortune)
+ iterator.addStat(" $reforgeName: §9+", reforgeFortune)
+ iterator.addStat(" §7Ability: §a+", abilityFortune)
+ iterator.addStat(" §7Green Thumb: §a+", greenThumbFortune)
iterator.addStat(" §7Sunder: §a+", sunderFortune)
iterator.addStat(" §7Harvesting: §a+", harvestingFortune)
iterator.addStat(" §7Cultivating: §a+", cultivatingFortune)
iterator.addStat(" §7Farming for Dummies: §2+", ffdFortune)
- iterator.addStat(" §7$reforgeName: §9+", reforgeFortune)
- iterator.addStat(" §7Tool: §6+", toolFortune)
iterator.addStat(" §7Counter: §6+", counterFortune)
iterator.addStat(" §7Collection: §6+", collectionFortune)
iterator.addStat(" §7Dedication: §6+", dedicationFortune)
@@ -98,21 +114,19 @@ class ToolTooltipTweaks {
}
if (line == "§5§o§9Bountiful Bonus") removingReforgeDescription = true
}
-
}
- }
- companion object {
- private fun Double.formatStat(): String {
- val formatter = DecimalFormat("0.##")
- return formatter.format(this)
+ // Fixing a hypixel bug. TODO remove once hypixel fixes it.
+ if (itemStack.getInternalName().contains("LOTUS")) {
+ event.toolTip.replaceAll { it.replace("Kills:", "Visitors:") }
}
+ }
+ private fun Number.formatStat() = statFormatter.format(this)
- private fun MutableListIterator<String>.addStat(description: String, value: Double) {
- if (value != 0.0) {
- this.add("$description${value.formatStat()}")
- }
+ private fun MutableListIterator<String>.addStat(description: String, value: Number) {
+ if (value.toDouble() != 0.0) {
+ add("$description${value.formatStat()}")
}
}
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index b13dbc59a..62ab4330d 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -9,7 +9,7 @@ object StringUtils {
fun String.firstLetterUppercase(): String {
if (isEmpty()) return this
- val lowercase = this.lowercase()
+ val lowercase = lowercase()
val first = lowercase[0].uppercase()
return first + lowercase.substring(1)
}