From 0fe7bc903aa544a01f53103e33083c79fc5a411c Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 24 Dec 2024 11:42:16 +0100 Subject: [PATCH 1/6] added comments --- .../skyhanni/features/event/hoppity/NucleusBarriersBox.kt | 1 + src/main/java/at/hannibal2/skyhanni/utils/CircularList.kt | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/NucleusBarriersBox.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/NucleusBarriersBox.kt index 7f769a505751..3d3fed53c8dd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/NucleusBarriersBox.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/NucleusBarriersBox.kt @@ -14,6 +14,7 @@ import net.minecraft.util.AxisAlignedBB import net.minecraft.util.BlockPos import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +// TODO move into mining category and package @SkyHanniModule object NucleusBarriersBox { private val config get() = SkyHanniMod.feature.mining.crystalHighlighter diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CircularList.kt b/src/main/java/at/hannibal2/skyhanni/utils/CircularList.kt index cd7e966706de..adb6e6359368 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CircularList.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CircularList.kt @@ -1,5 +1,13 @@ package at.hannibal2.skyhanni.utils +/** + * A generic, immutable circular list that cycles through its elements infinitely. + * + * @param T The type of elements in the circular list. + * @property items A list of elements to be accessed in a circular manner. + * @constructor Creates a CircularList with the given elements. + * @throws IllegalArgumentException if the list is empty. + */ class CircularList(private val items: List) { constructor(vararg elements: T) : this(elements.asList()) From 5f70fa220bc3a5faab52baee1b0287b051322e7b Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 24 Dec 2024 16:55:56 +0100 Subject: [PATCH 2/6] Backend: More crop reading error data (#3114) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/garden/contest/FarmingContestAPI.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt index 5bdcffa31a69..13745c840d54 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.events.garden.farming.FarmingContestEvent import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc @@ -98,7 +99,19 @@ object FarmingContestAPI { private fun readCurrentCrop(): CropType? { val line = ScoreboardData.sidebarLinesFormatted.nextAfter("§eJacob's Contest") ?: return null return sidebarCropPattern.matchMatcher(line) { - CropType.getByName(group("crop")) + val cropName = group("crop") + try { + CropType.getByName(cropName) + } catch (e: IllegalStateException) { + ScoreboardData.sidebarLinesFormatted + ErrorManager.logErrorWithData( + e, "Farming contest read current crop failed", + "cropName" to cropName, + "line" to line, + "sidebarLinesFormatted" to ScoreboardData.sidebarLinesFormatted, + ) + null + } } } From c4750c0bd893a253bf7e6203ee5ef9a4341af439 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Tue, 24 Dec 2024 17:19:03 -0500 Subject: [PATCH 3/6] Backend: Bump changelog builder (#3120) --- buildSrc/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index f44fde571dbf..0c8f3fc78e50 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -13,5 +13,5 @@ repositories { dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib") - implementation("com.github.SkyHanniStudios:SkyHanniChangelogBuilder:1.0.2") + implementation("com.github.SkyHanniStudios:SkyHanniChangelogBuilder:1.0.3") } From 8347d2a3e44f59de1f1598ce96560b037bf90d15 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Wed, 25 Dec 2024 02:03:59 +0100 Subject: [PATCH 4/6] Fix: Skill progress NumberFormatException (#3105) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/skillprogress/SkillProgress.kt | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt index 658cac0120c7..e46d7ab8841a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt @@ -463,20 +463,28 @@ object SkillProgress { } if (config.showActionLeft.get() && percent != 100f) { - append(" - ") - val gain = skill.lastGain.formatDouble() - val actionLeft = (ceil(currentXpMax.toDouble() - currentXp) / gain).toLong().plus(1).addSeparators() - if (skill.lastGain != "" && !actionLeft.contains("-")) { - append("§6$actionLeft Left") - } else { - append("§6∞ Left") - } + append(" - " + addActionsLeft(skill, currentXpMax, currentXp)) } }, ), ) } + private fun addActionsLeft( + skill: SkillAPI.SkillInfo, + currentXpMax: Long, + currentXp: Long, + ): String { + if (skill.lastGain != "") { + val gain = skill.lastGain.formatDouble() + val actionLeft = (ceil(currentXpMax.toDouble() - currentXp) / gain).toLong().plus(1).addSeparators() + if (skill.lastGain != "" && !actionLeft.contains("-")) { + return "§6$actionLeft Left" + } + } + return "§6∞ Left" + } + private fun updateSkillInfo() { val activeSkill = activeSkill ?: return val xpInfo = skillXPInfoMap.getOrPut(activeSkill) { SkillAPI.SkillXPInfo() } From 960621e2905b4f140d0d02eddf2e7e2cd8c43782 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Wed, 25 Dec 2024 02:04:14 +0100 Subject: [PATCH 5/6] Backend: Contributor Rabbit Name (#3109) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../ChocolateFactoryConfig.java | 5 ++ .../event/hoppity/HoppityCollectionData.kt | 2 +- .../hoppity/ReplaceHoppityWithContributor.kt | 82 +++++++++++++++++++ .../features/misc/ContributorManager.kt | 9 +- 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/event/hoppity/ReplaceHoppityWithContributor.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java index 6446114232b8..7f424b66eb20 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java @@ -91,6 +91,11 @@ public class ChocolateFactoryConfig { @ConfigEditorBoolean public boolean showStackSizes = true; + @Expose + @ConfigOption(name = "Contributor Rabbit Name", desc = "Replaces the rabbit names in the rabbit collection menu with SkyHanni contributor names.") + @ConfigEditorBoolean + public boolean contributorRabbitName = false; + @Expose @ConfigOption(name = "Highlight Upgrades", desc = "Highlight any upgrades that you can afford.\n" + "The upgrade with a star is the most optimal and the lightest color of green is the most optimal you can afford.") diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionData.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionData.kt index b6056451dd66..11b3d305309b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionData.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionData.kt @@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @SkyHanniModule object HoppityCollectionData { - private val rabbitRarities = mutableMapOf() + val rabbitRarities = mutableMapOf() private val rarityBonuses = mutableMapOf() private val specialBonuses = mutableMapOf() diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/ReplaceHoppityWithContributor.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/ReplaceHoppityWithContributor.kt new file mode 100644 index 000000000000..cf4584f90691 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/ReplaceHoppityWithContributor.kt @@ -0,0 +1,82 @@ +package at.hannibal2.skyhanni.features.event.hoppity + +import at.hannibal2.skyhanni.api.event.HandleEvent +import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.events.item.ItemHoverEvent +import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI +import at.hannibal2.skyhanni.features.misc.ContributorManager +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.CircularList +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.allLettersFirstUppercase +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object ReplaceHoppityWithContributor { + + private val config get() = ChocolateFactoryAPI.config + + private val replaceMap = mutableMapOf() + + @HandleEvent(priority = 5) + fun onNeuRepoReload(event: NeuRepositoryReloadEvent) { + update() + } + + @SubscribeEvent(priority = EventPriority.LOW) + fun onRepoReload(event: RepositoryReloadEvent) { + update() + } + + fun update() { + replaceMap.clear() + + val contributors = ContributorManager.contributorNames + val rabbits = HoppityCollectionData.rabbitRarities + + if (contributors.isEmpty()) return + if (rabbits.isEmpty()) return + + val newNames = CircularList(contributors.toList()) + for (internalName in rabbits.map { it.key }.shuffled()) { + val realName = internalName.allLettersFirstUppercase() + val newName = newNames.next() + replaceMap[realName] = newName + } + } + + @HandleEvent(priority = HandleEvent.LOWEST) + fun onTooltip(event: ItemHoverEvent) { + if (!isEnabled()) return + if (!HoppityCollectionStats.inInventory) return + + val itemStack = event.itemStack + val lore = itemStack.getLore() + val last = lore.lastOrNull() ?: return + if (!last.endsWith(" RABBIT")) return + + val realName = itemStack.name + val cleanName = realName.removeColor() + val fakeName = replaceMap[cleanName] ?: return + + val newName = event.toolTip[0].replace(cleanName, fakeName) + event.toolTip[0] = newName + + event.toolTip.add(" ") + event.toolTip.add("§8§oSome might say this rabbit is also known as $realName") + + // TODO find a way to handle non containing entries in a kotlin nullable way instead of checking for -1 + val index = event.toolTip.indexOfFirst { it.contains(" a duplicate") } + if (index == -1) return + val oldLine = event.toolTip[index] + val newLine = oldLine.replace(cleanName, fakeName) + event.toolTip[index] = newLine + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.contributorRabbitName +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt index ff5bdcacb66c..e4f2e54547a1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt @@ -16,11 +16,18 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object ContributorManager { private val config get() = SkyHanniMod.feature.dev + // Key is the lowercase contributor name private var contributors: Map = emptyMap() + // Just the names of the contributors including their proper case + var contributorNames = emptyList() + private set + @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { - contributors = event.getConstant("Contributors").contributors.mapKeys { it.key.lowercase() } + val map = event.getConstant("Contributors").contributors + contributors = map.mapKeys { it.key.lowercase() } + contributorNames = map.map { it.key } } @HandleEvent From a3d2e182d124dea595aa2b3776829c14e75a6653 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Wed, 25 Dec 2024 02:04:36 +0100 Subject: [PATCH 6/6] Backend: Added /shdebugvisualwords (#3112) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../misc/visualwords/ModifyVisualWords.kt | 47 ++++++++++++++++--- .../misc/visualwords/VisualWordGui.kt | 9 ++-- .../hannibal2/skyhanni/utils/LorenzUtils.kt | 16 ++----- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt index ecf57e3f3314..02fb21755da8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt @@ -3,9 +3,11 @@ package at.hannibal2.skyhanni.features.misc.visualwords import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.config.ConfigFileType +import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent import at.hannibal2.skyhanni.config.enums.OutsideSbFeature import at.hannibal2.skyhanni.events.HypixelJoinEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.convertToFormatted import at.hannibal2.skyhanni.utils.TimeLimitedCache @@ -15,11 +17,36 @@ import kotlin.time.Duration.Companion.minutes object ModifyVisualWords { private val config get() = SkyHanniMod.feature.gui.modifyWords - var textCache = TimeLimitedCache(5.minutes) + private val textCache = TimeLimitedCache(5.minutes) - var modifiedWords = mutableListOf() + // Replacements the user added manually via /shwords + var userModifiedWords = mutableListOf() - val reverseRegex = "(§.|^|[\\s:()+-])([^§\\s:()+-]*)".toRegex() + // Replacements the mod added automatically for some features, april jokes, etc + var modModifiedWords = mutableListOf() + private var finalWordsList = listOf() + private var debug = false + + fun update() { + finalWordsList = modModifiedWords + userModifiedWords + textCache.clear() + } + + @HandleEvent + fun onCommandRegistration(event: CommandRegistrationEvent) { + event.register("shdebugvisualwords") { + description = "Prints in the console all replaced words by /shwords" + callback { toggleDebug() } + } + } + + private fun toggleDebug() { + debug = !debug + ChatUtils.chat("Visual Words debug ${if (debug) "enabled" else "disabled"}") + if (debug) { + update() + } + } fun modifyText(originalText: String?): String? { var modifiedText = originalText ?: return null @@ -27,23 +54,29 @@ object ModifyVisualWords { if (!config.enabled) return originalText if (!LorenzUtils.inSkyBlock && !OutsideSbFeature.MODIFY_VISUAL_WORDS.isSelected()) return originalText - if (modifiedWords.isEmpty()) { - modifiedWords.addAll(SkyHanniMod.visualWordsData.modifiedWords) + if (userModifiedWords.isEmpty()) { + userModifiedWords.addAll(SkyHanniMod.visualWordsData.modifiedWords) + update() } return textCache.getOrPut(originalText) { if (originalText.startsWith("§§")) { modifiedText = modifiedText.removePrefix("§§") } else { - for (modifiedWord in modifiedWords) { + for (modifiedWord in finalWordsList) { if (!modifiedWord.enabled) continue val phrase = modifiedWord.phrase.convertToFormatted() if (phrase.isEmpty()) continue + val original = modifiedText + val replacement = modifiedWord.replacement.convertToFormatted() modifiedText = modifiedText.replace( - phrase, modifiedWord.replacement.convertToFormatted(), modifiedWord.isCaseSensitive() + phrase, replacement, modifiedWord.isCaseSensitive(), ) + if (debug && original != modifiedText) { + println("Visual words Change debug: '$original' -> `$modifiedText` (`$phrase` -> `$replacement`)") + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt index 077332e634f8..babcfdd83ed6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt @@ -246,7 +246,7 @@ open class VisualWordGui : GuiScreen() { } if (modifiedWords.size < 1) { - modifiedWords = ModifyVisualWords.modifiedWords + modifiedWords = ModifyVisualWords.userModifiedWords } if (toRemove != null) { @@ -568,9 +568,8 @@ open class VisualWordGui : GuiScreen() { } private fun saveChanges() { - ModifyVisualWords.modifiedWords = modifiedWords - ModifyVisualWords.textCache.clear() - SkyHanniMod.visualWordsData.modifiedWords = modifiedWords + ModifyVisualWords.userModifiedWords = modifiedWords + ModifyVisualWords.update() SkyHanniMod.configManager.saveConfig(ConfigFileType.VISUAL_WORDS, "Updated visual words") } @@ -600,7 +599,7 @@ open class VisualWordGui : GuiScreen() { } if (importedWords > 0 || skippedWords > 0) { chat( - "§aSuccessfully imported §e$importedWords §aand skipped §e$skippedWords §aVisualWords from SkyBlockExtras !" + "§aSuccessfully imported §e$importedWords §aand skipped §e$skippedWords §aVisualWords from SkyBlockExtras !", ) SkyHanniMod.feature.storage.visualWordsImported = true drawImport = false diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index b76f5dc8a35f..12322964a83b 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -76,7 +76,7 @@ object LorenzUtils { val never = SkyHanniMod.feature.dev.debug.neverFunnyTime val result = (!never && (always || itsTime)) if (previousApril != result) { - ModifyVisualWords.textCache.clear() + ModifyVisualWords.update() } previousApril = result return result @@ -261,12 +261,8 @@ object LorenzUtils { fun GuiEditSign.isRancherSign(): Boolean { if (this !is AccessorGuiEditSign) return false - val tileSign = (this as AccessorGuiEditSign).tileSign - return ( - tileSign.signText[1].unformattedText.removeColor() == "^^^^^^" && - tileSign.signText[2].unformattedText.removeColor() == "Set your" && - tileSign.signText[3].unformattedText.removeColor() == "speed cap!" - ) + val signText = (this as AccessorGuiEditSign).tileSign.signText.map { it.unformattedText.removeColor() } + return signText[1] == "^^^^^^" && signText[2] == "Set your" && signText[3] == "speed cap!" } fun IslandType.isInIsland() = inSkyBlock && skyBlockIsland == this @@ -304,8 +300,7 @@ object LorenzUtils { } inline fun > enumValueOf(name: String) = - enumValueOfOrNull(name) - ?: error("Unknown enum constant for ${enumValues().first().name.javaClass.simpleName}: '$name'") + enumValueOfOrNull(name) ?: error("Unknown enum constant for ${enumValues().first().name.javaClass.simpleName}: '$name'") inline fun > enumJoinToPattern(noinline transform: (T) -> CharSequence = { it.name }) = enumValues().joinToString("|", transform = transform) @@ -319,8 +314,7 @@ object LorenzUtils { FMLCommonHandler.instance().handleExit(-1) } - fun inMiningIsland() = IslandType.GOLD_MINES.isInIsland() || - IslandType.DEEP_CAVERNS.isInIsland() || MiningAPI.inAdvancedMiningIsland() + fun inMiningIsland() = IslandType.GOLD_MINES.isInIsland() || IslandType.DEEP_CAVERNS.isInIsland() || MiningAPI.inAdvancedMiningIsland() fun isBetaVersion() = UpdateManager.isCurrentlyBeta()