Skip to content

Commit

Permalink
Merge branch 'beta' into sh-word
Browse files Browse the repository at this point in the history
  • Loading branch information
NopoTheGamer authored Dec 25, 2024
2 parents 27744f6 + a3d2e18 commit 20be841
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 34 deletions.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule

@SkyHanniModule
object HoppityCollectionData {
private val rabbitRarities = mutableMapOf<String, RabbitCollectionRarity>()
val rabbitRarities = mutableMapOf<String, RabbitCollectionRarity>()
private val rarityBonuses = mutableMapOf<RabbitCollectionRarity, ChocolateBonuses>()
private val specialBonuses = mutableMapOf<String, ChocolateBonuses>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String>()

@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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ContributorJsonEntry> = emptyMap()

// Just the names of the contributors including their proper case
var contributorNames = emptyList<String>()
private set

@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
contributors = event.getConstant<ContributorsJson>("Contributors").contributors.mapKeys { it.key.lowercase() }
val map = event.getConstant<ContributorsJson>("Contributors").contributors
contributors = map.mapKeys { it.key.lowercase() }
contributorNames = map.map { it.key }
}

@HandleEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,33 +17,40 @@ import kotlin.time.Duration.Companion.minutes
object ModifyVisualWords {

private val config get() = SkyHanniMod.feature.gui.modifyWords
var textCache = TimeLimitedCache<String, String>(5.minutes)
private val textCache = TimeLimitedCache<String, String>(5.minutes)

var modifiedWords = mutableListOf<VisualWord>()
// Replacements the user added manually via /shwords
var userModifiedWords = mutableListOf<VisualWord>()

fun modifyText(originalText: String?): String? {
var modifiedText = originalText ?: return null
if (!LorenzUtils.onHypixel) return originalText
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`)")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ open class VisualWordGui : GuiScreen() {
}

if (modifiedWords.size < 1) {
modifiedWords = ModifyVisualWords.modifiedWords
modifiedWords = ModifyVisualWords.userModifiedWords
}

if (toRemove != null) {
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/CircularList.kt
Original file line number Diff line number Diff line change
@@ -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<T>(private val items: List<T>) {

constructor(vararg elements: T) : this(elements.asList())
Expand Down
16 changes: 5 additions & 11 deletions src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -304,8 +300,7 @@ object LorenzUtils {
}

inline fun <reified T : Enum<T>> enumValueOf(name: String) =
enumValueOfOrNull<T>(name)
?: error("Unknown enum constant for ${enumValues<T>().first().name.javaClass.simpleName}: '$name'")
enumValueOfOrNull<T>(name) ?: error("Unknown enum constant for ${enumValues<T>().first().name.javaClass.simpleName}: '$name'")

inline fun <reified T : Enum<T>> enumJoinToPattern(noinline transform: (T) -> CharSequence = { it.name }) =
enumValues<T>().joinToString("|", transform = transform)
Expand All @@ -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()

Expand Down

0 comments on commit 20be841

Please sign in to comment.