aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorVixid <52578495+VixidDev@users.noreply.github.com>2024-08-31 22:12:21 +0100
committerGitHub <noreply@github.com>2024-08-31 23:12:21 +0200
commit096a4628d9f1baba475a25b3db8a50930b28d8b2 (patch)
treef709e9d45f73f4a8f6c5e125f253a97cbd24fe0e /src/main/java/at
parent755a36d801e29a3c517e9c7abbf4ef6b016b026a (diff)
downloadskyhanni-096a4628d9f1baba475a25b3db8a50930b28d8b2.tar.gz
skyhanni-096a4628d9f1baba475a25b3db8a50930b28d8b2.tar.bz2
skyhanni-096a4628d9f1baba475a25b3db8a50930b28d8b2.zip
Improvement: Enchant Parsing Exceptions (#2254)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Enchant.kt48
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/FormattedEnchant.kt7
3 files changed, 58 insertions, 16 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Enchant.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Enchant.kt
index 697a58ebb..8058fc223 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Enchant.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Enchant.kt
@@ -2,8 +2,13 @@ package at.hannibal2.skyhanni.features.misc.items.enchants
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.features.chroma.ChromaManager
+import at.hannibal2.skyhanni.utils.ItemCategory
+import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull
+import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor
import at.hannibal2.skyhanni.utils.LorenzColor
import com.google.gson.annotations.Expose
+import io.github.notenoughupdates.moulconfig.observer.Property
+import net.minecraft.item.ItemStack
import java.util.TreeSet
open class Enchant : Comparable<Enchant> {
@@ -23,24 +28,57 @@ open class Enchant : Comparable<Enchant> {
private fun isUltimate() = this is Ultimate
private fun isStacking() = this is Stacking
- open fun getFormattedName(level: Int) = getFormat(level) + loreName
+ open fun getFormattedName(level: Int, itemStack: ItemStack?) = getFormat(level, itemStack) + loreName
- open fun getFormat(level: Int): String {
+ open fun getFormat(level: Int, itemStack: ItemStack? = null): String {
val config = SkyHanniMod.feature.inventory.enchantParsing
// TODO change color to string (support for bold)
- val color = when {
+ var color = when {
level >= maxLevel -> config.perfectEnchantColor
level > goodLevel -> config.greatEnchantColor
level == goodLevel -> config.goodEnchantColor
else -> config.poorEnchantColor
}
+ // Exceptions
+ color = checkExceptions(color, level, itemStack)
+
// TODO when chroma is disabled maybe use the neu chroma style instead of gold
if (color.get() == LorenzColor.CHROMA && !(ChromaManager.config.enabled.get() || EnchantParser.isSbaLoaded)) return "§6§l"
return color.get().getChatColor()
}
+ /**
+ * Method to check for certain or unique exceptions that need to be handled explicitly.
+ *
+ * *(There isn't much of a convention to adding exceptions, except try to include relevant exceptions under
+ * a corresponding enchantment conditional, unless the exception is not specific to a certain enchant. i.e.
+ * Efficiency exceptions should be within the `if (this.nbtName == "efficiency")` conditional)*
+ *
+ * @param color The original coloring based on default behaviour, for when no exception is met
+ * @param level The level of the enchant currently being parsed
+ * @param itemStack The ItemStack of the hovered item. Can be null, e.g. when hovering over `/show` items
+ */
+ private fun checkExceptions(color: Property<LorenzColor>, level: Int, itemStack: ItemStack?): Property<LorenzColor> {
+ val config = SkyHanniMod.feature.inventory.enchantParsing
+
+ val itemCategory = itemStack?.getItemCategoryOrNull()
+ val itemName = itemStack?.itemNameWithoutColor
+
+ if (this.nbtName == "efficiency") {
+ // If the item is a Stonk, or a non-mining tool with Efficiency 5 (whilst not being a Promising Shovel),
+ // color the enchant as max
+ if (itemName == "Stonk" ||
+ (itemCategory != null && !ItemCategory.miningTools.contains(itemCategory) && level == 5 && itemName != "Promising Shovel")
+ ) {
+ return config.perfectEnchantColor
+ }
+ }
+
+ return color
+ }
+
override fun toString() = "$nbtName $goodLevel $maxLevel\n"
override fun compareTo(other: Enchant): Int {
@@ -57,7 +95,7 @@ open class Enchant : Comparable<Enchant> {
}
class Ultimate : Enchant() {
- override fun getFormat(level: Int) = "§d§l"
+ override fun getFormat(level: Int, itemStack: ItemStack?) = "§d§l"
}
class Stacking : Enchant() {
@@ -81,6 +119,6 @@ open class Enchant : Comparable<Enchant> {
// Ensures enchants not yet in repo stay as vanilla formatting
// (instead of that stupid dark red lowercase formatting *cough* sba *cough*)
- override fun getFormattedName(level: Int) = "§9$loreName"
+ override fun getFormattedName(level: Int, itemStack: ItemStack?): String = "§9$loreName"
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt
index 83822cf4d..bf7ef24c4 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt
@@ -39,10 +39,11 @@ object EnchantParser {
val patternGroup = RepoPattern.group("misc.items.enchantparsing")
val enchantmentPattern by patternGroup.pattern(
- "enchants.new", "(§9§d§l|§d§l§d§l|§9)(?<enchant>[A-Za-z][A-Za-z '-]+) (?<levelNumeral>[IVXLCDM]+|[0-9]+)(?<stacking>(§r)?§9, |\$| §8\\d{1,3}(,\\d{3})*)"
+ "enchants.new",
+ "(§9§d§l|§d§l§d§l|§9)(?<enchant>[A-Za-z][A-Za-z '-]+) (?<levelNumeral>[IVXLCDM]+|[0-9]+)(?<stacking>(§r)?§9, |\$| §8\\d{1,3}(,\\d{3})*)",
)
private val grayEnchantPattern by patternGroup.pattern(
- "grayenchants", "^(Respiration|Aqua Affinity|Depth Strider|Efficiency).*"
+ "grayenchants", "^(Respiration|Aqua Affinity|Depth Strider|Efficiency).*",
)
private var currentItem: ItemStack? = null
@@ -116,6 +117,8 @@ object EnchantParser {
if (event.getHoverEvent().action != HoverEvent.Action.SHOW_TEXT) return
if (!isEnabled() || !this.enchants.hasEnchantData()) return
+ currentItem = null
+
val lore = event.getHoverEvent().value.formattedText.split("\n").toMutableList()
// Check for any vanilla gray enchants at the top of the tooltip
@@ -281,10 +284,10 @@ object EnchantParser {
// Normal is leaving the formatting as Hypixel provides it
if (config.format.get() == EnchantParsingConfig.EnchantFormat.NORMAL) {
normalFormatting(insertEnchants)
- // Compressed is always forcing 3 enchants per line, except when there is stacking enchant progress visible
+ // Compressed is always forcing 3 enchants per line, except when there is stacking enchant progress visible
} else if (config.format.get() == EnchantParsingConfig.EnchantFormat.COMPRESSED && !shouldBeSingleColumn) {
compressedFormatting(insertEnchants)
- // Stacked is always forcing 1 enchant per line
+ // Stacked is always forcing 1 enchant per line
} else {
stackedFormatting(insertEnchants)
}
@@ -297,7 +300,7 @@ object EnchantParser {
for ((i, orderedEnchant: FormattedEnchant) in orderedEnchants.withIndex()) {
val comma = if (commaFormat == CommaFormat.COPY_ENCHANT) ", " else "§9, "
- builder.append(orderedEnchant.getFormattedString())
+ builder.append(orderedEnchant.getFormattedString(currentItem))
if (i % maxEnchantsPerLine != maxEnchantsPerLine - 1) {
builder.append(comma)
} else {
@@ -320,7 +323,7 @@ object EnchantParser {
for ((i, orderedEnchant: FormattedEnchant) in orderedEnchants.withIndex()) {
val comma = if (commaFormat == CommaFormat.COPY_ENCHANT) ", " else "§9, "
- builder.append(orderedEnchant.getFormattedString())
+ builder.append(orderedEnchant.getFormattedString(currentItem))
if (itemIsBook() && maxEnchantsPerLine == 1) {
insertEnchants.add(builder.toString())
@@ -342,12 +345,12 @@ object EnchantParser {
private fun stackedFormatting(insertEnchants: MutableList<String>) {
if (!config.hideEnchantDescriptions.get() || itemIsBook()) {
for (enchant: FormattedEnchant in orderedEnchants) {
- insertEnchants.add(enchant.getFormattedString())
+ insertEnchants.add(enchant.getFormattedString(currentItem))
insertEnchants.addAll(enchant.getLore())
}
} else {
for (enchant: FormattedEnchant in orderedEnchants) {
- insertEnchants.add(enchant.getFormattedString())
+ insertEnchants.add(enchant.getFormattedString(currentItem))
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/FormattedEnchant.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/FormattedEnchant.kt
index 73cf57e7a..834959fbb 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/FormattedEnchant.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/FormattedEnchant.kt
@@ -1,12 +1,13 @@
package at.hannibal2.skyhanni.features.misc.items.enchants
import at.hannibal2.skyhanni.utils.NumberUtil.toRoman
+import net.minecraft.item.ItemStack
class FormattedEnchant(
private val enchant: Enchant,
private val level: Int,
stacking: String,
- private val isRoman: Boolean
+ private val isRoman: Boolean,
) : Comparable<FormattedEnchant> {
private val stacking: String = stacking
get() = "§8$field"
@@ -18,9 +19,9 @@ class FormattedEnchant(
override fun compareTo(other: FormattedEnchant) = this.enchant.compareTo(other.enchant)
- fun getFormattedString(): String {
+ fun getFormattedString(itemStack: ItemStack?): String {
val builder = StringBuilder()
- builder.append(enchant.getFormattedName(level)).append(" ").append(if (isRoman) level.toRoman() else level)
+ builder.append(enchant.getFormattedName(level, itemStack)).append(" ").append(if (isRoman) level.toRoman() else level)
return if (!stacking.contains("empty")) builder.append(stacking).toString() else builder.toString()
}