From 0e61e3d7bbb65b57a4fc0e02096bf033e8e5c863 Mon Sep 17 00:00:00 2001 From: TakoTheDev <74718793+TakoTheDev@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:23:09 +0200 Subject: [PATCH 1/2] epic --- .../features/impl/misc/ContainerSellValue.kt | 6 +-- .../mixins/hooks/item/ItemStackHook.kt | 46 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ContainerSellValue.kt b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ContainerSellValue.kt index 2595e83ca..799cce2e6 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ContainerSellValue.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ContainerSellValue.kt @@ -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 @@ -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 diff --git a/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt b/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt index 8ef80cea4..6942d4bbf 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt @@ -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() } +val starRegex = Regex("§6${star}+") +val masterStarRegex = Regex("§c(?[${masterStars.joinToString("")}])") fun showEnchantmentGlint(stack: Any, cir: CallbackInfoReturnable) { (stack as ItemStack).apply { @@ -56,30 +57,29 @@ fun showEnchantmentGlint(stack: Any, cir: CallbackInfoReturnable) { fun modifyDisplayName(s: String): String { var displayName = s - if (!Utils.inSkyblock) return displayName + if (!Utils.inSkyblock || Skytils.config.starDisplayType == 0 || !displayName.contains("✪")) 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)}✪" + when (Skytils.config.starDisplayType) { + 1 -> { + masterStarRegex.find(displayName)?.destructured?.let { (tier) -> + val count = masterStars.indexOf(tier) + 1 + + displayName = displayName.replace(masterStarRegex, "") + .replaceFirst("§6" + star.repeat(count), "§c" + "✪".repeat(count) + "§6") } - } 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)) + } + + 2 -> { + masterStarRegex.find(displayName)?.destructured?.let { (tier) -> + val count = masterStars.indexOf(tier) + 1 + 5 + displayName = displayName.replace(starRegex, "").replace(masterStarRegex, "") + "§c$count✪" + }.ifNull { + displayName = displayName.replace(starRegex, "") + "§6${displayName.countMatches(star)}✪" } } } - } catch (ignored: Exception) { - } + } catch (ignored: Exception) { } + return displayName } \ No newline at end of file From a9b4b4a2703c9f9dfc1f635a54c6f891e3d63fca Mon Sep 17 00:00:00 2001 From: TakoTheDev <74718793+TakoTheDev@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:33:09 +0200 Subject: [PATCH 2/2] slight improvement --- .../skytilsmod/mixins/hooks/item/ItemStackHook.kt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt b/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt index 6942d4bbf..0d1b72f7f 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt @@ -55,9 +55,8 @@ fun showEnchantmentGlint(stack: Any, cir: CallbackInfoReturnable) { } } -fun modifyDisplayName(s: String): String { - var displayName = s - if (!Utils.inSkyblock || Skytils.config.starDisplayType == 0 || !displayName.contains("✪")) return displayName +fun modifyDisplayName(displayName: String): String { + if (!Utils.inSkyblock || Skytils.config.starDisplayType == 0 || !displayName.contains(star)) return displayName try { when (Skytils.config.starDisplayType) { @@ -65,18 +64,16 @@ fun modifyDisplayName(s: String): String { masterStarRegex.find(displayName)?.destructured?.let { (tier) -> val count = masterStars.indexOf(tier) + 1 - displayName = displayName.replace(masterStarRegex, "") - .replaceFirst("§6" + star.repeat(count), "§c" + "✪".repeat(count) + "§6") + 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 - displayName = displayName.replace(starRegex, "").replace(masterStarRegex, "") + "§c$count✪" - }.ifNull { - displayName = displayName.replace(starRegex, "") + "§6${displayName.countMatches(star)}✪" - } + return displayName.replace(starRegex, "").replace(masterStarRegex, "") + "§c$count$star" + } ?: return displayName.replace(starRegex, "") + "§6${displayName.countMatches(star)}$star" } } } catch (ignored: Exception) { }