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

fix: Item Stars Display shows incorrect star count #505

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -27,7 +27,7 @@ import gg.skytils.skytilsmod.core.structure.GuiElement
import gg.skytils.skytilsmod.core.tickTimer
import gg.skytils.skytilsmod.events.impl.GuiContainerEvent
import gg.skytils.skytilsmod.features.impl.handlers.AuctionData
import gg.skytils.skytilsmod.mixins.hooks.item.masterStarPattern
import gg.skytils.skytilsmod.mixins.hooks.item.masterStarRegex
import gg.skytils.skytilsmod.mixins.hooks.item.masterStars
import gg.skytils.skytilsmod.utils.*
import gg.skytils.skytilsmod.utils.Utils.inDungeons
Expand Down Expand Up @@ -158,8 +158,8 @@ object ContainerSellValue {
} ?: 0.0

val masterStarCount =
if (itemStack.displayName?.contains("✪") == true) masterStarPattern.find(itemStack.displayName)?.let {
masterStars.indexOf(it.value.last()) + 1
if (itemStack.displayName?.contains("✪") == true) masterStarRegex.find(itemStack.displayName)?.destructured?.let { (tier) ->
masterStars.indexOf(tier) + 1
} ?: 0 else 0
val masterStarValue = if (masterStarCount > 0) (1..masterStarCount).sumOf { i ->
AuctionData.lowestBINs[listOf("FIRST", "SECOND", "THIRD", "FOURTH", "FIFTH")[i - 1] + "_MASTER_STAR"] ?: 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import gg.skytils.skytilsmod.utils.ifNull
import net.minecraft.item.ItemStack
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable

const val starPattern = "§6✪"
val masterStars = ('➊'..'➎').toList()
val masterStarPattern = Regex("§c[${masterStars.joinToString("")}]")
const val star = "✪"
val masterStars = ('➊'..'➎').map { it.toString() }
Sychic marked this conversation as resolved.
Show resolved Hide resolved
val starRegex = Regex("§6${star}+")
val masterStarRegex = Regex("§c(?<tier>[${masterStars.joinToString("")}])")

fun showEnchantmentGlint(stack: Any, cir: CallbackInfoReturnable<Boolean>) {
(stack as ItemStack).apply {
Expand All @@ -54,32 +55,28 @@ fun showEnchantmentGlint(stack: Any, cir: CallbackInfoReturnable<Boolean>) {
}
}

fun modifyDisplayName(s: String): String {
var displayName = s
if (!Utils.inSkyblock) return displayName
fun modifyDisplayName(displayName: String): String {
if (!Utils.inSkyblock || Skytils.config.starDisplayType == 0 || !displayName.contains(star)) return displayName

try {
if (Skytils.config.starDisplayType != 0 && displayName.contains("✪")) {
if (Skytils.config.starDisplayType == 2) {
masterStarPattern.find(displayName)?.let {
val star = it.value.last()
val count = masterStars.indexOf(star) + 1 + 5
displayName = "${
displayName.replace(starPattern, "")
.replace(masterStarPattern, "")
}§c${count}✪"
}.ifNull {
displayName = "${displayName.replace(starPattern, "")}§6${displayName.countMatches(starPattern)}✪"
}
} else if (Skytils.config.starDisplayType == 1) {
masterStarPattern.find(displayName)?.let {
val star = it.value.last()
val count = masterStars.indexOf(star) + 1
displayName = displayName.replace(masterStarPattern, "")
.replaceFirst(starPattern.repeat(count), "§c✪".repeat(count))
when (Skytils.config.starDisplayType) {
1 -> {
masterStarRegex.find(displayName)?.destructured?.let { (tier) ->
val count = masterStars.indexOf(tier) + 1

return displayName.replace(masterStarRegex, "")
.replaceFirst("§6" + star.repeat(count), "§c" + star.repeat(count) + "§6")
}
}

2 -> {
masterStarRegex.find(displayName)?.destructured?.let { (tier) ->
val count = masterStars.indexOf(tier) + 1 + 5
return displayName.replace(starRegex, "").replace(masterStarRegex, "") + "§c$count$star"
} ?: return displayName.replace(starRegex, "") + "§6${displayName.countMatches(star)}$star"
}
}
} catch (ignored: Exception) {
}
} catch (ignored: Exception) { }

return displayName
}
Loading