Skip to content

Commit

Permalink
Added a feature to replace Roman Numerals in tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikecraft1224 committed May 6, 2024
1 parent a87b85a commit 1aa6167
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ import at.hannibal2.skyhanni.features.misc.PetItemDisplay
import at.hannibal2.skyhanni.features.misc.PocketSackInASackDisplay
import at.hannibal2.skyhanni.features.misc.PrivateIslandNoPickaxeAbility
import at.hannibal2.skyhanni.features.misc.QuickModMenuSwitch
import at.hannibal2.skyhanni.features.misc.ReplaceRomanNumerals
import at.hannibal2.skyhanni.features.misc.RestorePieceOfWizardPortalLore
import at.hannibal2.skyhanni.features.misc.ServerRestartTitle
import at.hannibal2.skyhanni.features.misc.SkyBlockKickDuration
Expand Down Expand Up @@ -721,6 +722,7 @@ class SkyHanniMod {
loadModule(TpsCounter())
loadModule(ParticleHider())
loadModule(MiscFeatures())
loadModule(ReplaceRomanNumerals())
loadModule(GardenPlotMenuHighlighting())
loadModule(SkyMartCopperPrice())
loadModule(GardenVisitorFeatures)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ public class MiscConfig {
@FeatureToggle
public boolean fixGhostEntities = true;

@Expose
@ConfigOption(name = "Replace Roman Numerals", desc = "Replaces Roman Numerals with Arabic Numerals on any item.")
@ConfigEditorBoolean
@FeatureToggle
public boolean replaceRomanNumerals = true;

@ConfigOption(name = "Hide Far Entities", desc = "")
@Accordion
@Expose
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package at.hannibal2.skyhanni.features.misc

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.ChatHoverEvent
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.mixins.hooks.GuiChatHook
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
import at.hannibal2.skyhanni.utils.StringUtils.isRoman
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraft.event.HoverEvent
import net.minecraft.util.ChatComponentText
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class ReplaceRomanNumerals {
@SubscribeEvent(priority = EventPriority.LOWEST)
fun onTooltip(event: LorenzToolTipEvent) {
if (!isEnabled()) return

event.toolTip.replaceAll { it.transformLine() }
}

@SubscribeEvent(priority = EventPriority.LOWEST)
fun onChatHover(event: ChatHoverEvent) {
if (event.getHoverEvent().action != HoverEvent.Action.SHOW_TEXT) return
if (!isEnabled()) return

val lore = event.getHoverEvent().value.formattedText.split("\n").toMutableList()
lore.replaceAll { it.transformLine() }

val chatComponentText = ChatComponentText(lore.joinToString("\n"))
val hoverEvent = HoverEvent(event.component.chatStyle.chatHoverEvent.action, chatComponentText)

GuiChatHook.replaceOnlyHoverEvent(hoverEvent)
}

private fun String.transformLine() = split(" ").joinToString(" ") {
it.takeIf { it.isValidRomanNumeral() }?.coloredRomanToDecimal() ?: it
}

private fun String.removeFormatting() = removeColor().replace(",", "")

private fun String.isValidRomanNumeral() = removeFormatting()
.let { it.isRoman() && it.isNotEmpty() }

private fun String.coloredRomanToDecimal() = removeFormatting()
.let { replace(it, it.romanToDecimal().toString()) }

private fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.misc.replaceRomanNumerals
}

0 comments on commit 1aa6167

Please sign in to comment.