Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Enchant Parsing SBA Convert Roman Numerals and NEU Inventories compat #1717

Merged
merged 8 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ package at.hannibal2.skyhanni.events.item
import at.hannibal2.skyhanni.events.LorenzEvent
import net.minecraft.item.ItemStack

class ItemHoverEvent(val itemStack: ItemStack, val toolTip: List<String>) : LorenzEvent()
class ItemHoverEvent(val itemStack: ItemStack, private val toolTip0: MutableList<String>) : LorenzEvent() {
var toolTip
set(value) {
toolTip0.clear()
toolTip0.addAll(value)
}
get() = toolTip0
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import at.hannibal2.skyhanni.config.features.inventory.EnchantParsingConfig
import at.hannibal2.skyhanni.config.features.inventory.EnchantParsingConfig.CommaFormat
import at.hannibal2.skyhanni.events.ChatHoverEvent
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.events.item.ItemHoverEvent
import at.hannibal2.skyhanni.mixins.hooks.GuiChatHook
import at.hannibal2.skyhanni.utils.ConditionalUtils
import at.hannibal2.skyhanni.utils.ItemCategory
Expand All @@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import java.lang.NumberFormatException
import net.minecraft.event.HoverEvent
import net.minecraft.item.ItemStack
import net.minecraft.util.ChatComponentText
Expand All @@ -33,7 +34,7 @@ object EnchantParser {

val patternGroup = RepoPattern.group("misc.items.enchantparsing")
val enchantmentPattern by patternGroup.pattern(
"enchants", "(?<enchant>[A-Za-z][A-Za-z -]+) (?<levelNumeral>[IVXLCDM]+)(?<stacking>, |\$| \\d{1,3}(,\\d{3})*)"
"enchants", "(§9§d§l|§d§l§d§l|§9)(?<enchant>[A-Za-z][A-Za-z -]+) (?<levelNumeral>[IVXLCDM]+|[0-9]+)(?<stacking>§9, |\$| §8\\d{1,3}(,\\d{3})*)"
)
private val grayEnchantPattern by patternGroup.pattern(
"grayenchants", "^(Respiration|Aqua Affinity|Depth Strider|Efficiency).*"
Expand Down Expand Up @@ -84,7 +85,7 @@ object EnchantParser {
}

@SubscribeEvent
fun onTooltipEvent(event: LorenzToolTipEvent) {
fun onTooltipEvent(event: ItemHoverEvent) {
// If enchants doesn't have any enchant data then we have no data to parse enchants correctly
if (!isEnabled() || !this.enchants.hasEnchantData()) return

Expand Down Expand Up @@ -201,7 +202,7 @@ object EnchantParser {
val strippedLine = loreList[i].removeColor()

if (startEnchant == -1) {
if (this.enchants.containsEnchantment(enchants, strippedLine)) startEnchant = i
if (this.enchants.containsEnchantment(enchants, loreList[i])) startEnchant = i
} else if (strippedLine.trim().isEmpty() && endEnchant == -1) endEnchant = i - 1
}

Expand All @@ -213,22 +214,27 @@ object EnchantParser {
var lastEnchant: FormattedEnchant? = null

for (i in startEnchant..endEnchant) {
val unformattedLine = loreList[i].removeColor()
val matcher = enchantmentPattern.matcher(unformattedLine)
val matcher = enchantmentPattern.matcher(loreList[i])
var containsEnchant = false
var enchantsOnThisLine = 0
var isRoman = true

while (matcher.find()) {
// Pull enchant, enchant level and stacking amount if applicable
val enchant = this.enchants.getFromLore(matcher.group("enchant"))
val level = matcher.group("levelNumeral").romanToDecimal()
val stacking = if (matcher.group("stacking").trimStart().matches("[\\d,]+\$".toRegex())) {
val level = try{
// If one enchant is not a roman numeral we assume all are not roman numerals (idk a situation where this wouldn't be the case)
matcher.group("levelNumeral").toInt().also { isRoman = false }
} catch (e: NumberFormatException) {
matcher.group("levelNumeral").romanToDecimal()
}
val stacking = if (matcher.group("stacking").trimStart().removeColor().matches("[\\d,]+\$".toRegex())) {
shouldBeSingleColumn = true
matcher.group("stacking")
} else "empty"

// Last found enchant
lastEnchant = FormattedEnchant(enchant, level, stacking)
lastEnchant = FormattedEnchant(enchant, level, stacking, isRoman)

if (!orderedEnchants.add(lastEnchant)) {
for (e: FormattedEnchant in orderedEnchants) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class FormattedEnchant(
private val enchant: Enchant,
private val level: Int,
stacking: String,
private val isRoman: Boolean
) : Comparable<FormattedEnchant> {
private val stacking: String = stacking
get() = "§8$field"
Expand All @@ -19,7 +20,7 @@ class FormattedEnchant(

fun getFormattedString(): String {
val builder = StringBuilder()
builder.append(enchant.getFormattedName(level)).append(" ").append(level.toRoman())
builder.append(enchant.getFormattedName(level)).append(" ").append(if (isRoman) level.toRoman() else level)

return if (!stacking.contains("empty")) builder.append(stacking).toString() else builder.toString()
}
Expand Down
Loading