Skip to content

Commit

Permalink
Backend: SpecialColor translation (hannibal002#2854)
Browse files Browse the repository at this point in the history
Co-authored-by: Cal <cwolfson58@gmail.com>
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 952f09e commit f411297
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.RenderUtils.drawString
import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.SkullTextureHolder
import at.hannibal2.skyhanni.utils.SpecialColor
import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColor
import at.hannibal2.skyhanni.utils.getLorenzVec
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.init.Blocks
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color

@SkyHanniModule
object ThunderSparksHighlight {
Expand All @@ -43,8 +42,7 @@ object ThunderSparksHighlight {
fun onRenderWorld(event: LorenzRenderWorldEvent) {
if (!isEnabled()) return

val special = config.color
val color = Color(SpecialColor.specialToChromaRGB(special), true)
val color = config.color.toSpecialColor()

for (spark in sparks) {
if (spark.isDead) continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RenderUtils.drawFilledBoundingBoxNea
import at.hannibal2.skyhanni.utils.SpecialColor
import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColor
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.EnumParticleTypes
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color

@SkyHanniModule
object GeyserFishing {
Expand All @@ -40,7 +39,7 @@ object GeyserFishing {

geyserBox = AxisAlignedBB(
potentialGeyser.x - 2, 118.0 - 0.1, potentialGeyser.z - 2,
potentialGeyser.x + 2, 118.0 - 0.09, potentialGeyser.z + 2
potentialGeyser.x + 2, 118.0 - 0.09, potentialGeyser.z + 2,
)

if (config.hideParticles && FishingAPI.bobber != null) {
Expand All @@ -63,7 +62,7 @@ object GeyserFishing {
if (!IslandType.CRIMSON_ISLE.isInIsland()) return
if (config.onlyWithRod && !FishingAPI.holdingLavaRod) return

val color = Color(SpecialColor.specialToChromaRGB(config.boxColor), true)
val color = config.boxColor.toSpecialColor()
event.drawFilledBoundingBoxNea(geyserBox, color)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.drawString
import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SpecialColor
import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColor
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.getLorenzVec
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
Expand All @@ -60,7 +60,6 @@ import net.minecraft.init.Blocks
import net.minecraftforge.event.entity.player.PlayerInteractEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color

@SkyHanniModule
object MinionFeatures {
Expand All @@ -75,21 +74,35 @@ object MinionFeatures {
private var coinsPerDay = ""

private val patternGroup = RepoPattern.group("minion")

/**
* REGEX-TEST: §aYou have upgraded your Minion to Tier V
*/
private val minionUpgradePattern by patternGroup.pattern(
"chat.upgrade",
"§aYou have upgraded your Minion to Tier (?<tier>.*)"
"§aYou have upgraded your Minion to Tier (?<tier>.*)",
)

/**
* REGEX-TEST: §aYou received §r§64 coins§r§a!
* REGEX-TEST: §aYou received §r§610.5 coins§r§a!
*/
private val minionCoinPattern by patternGroup.pattern(
"chat.coin",
"§aYou received §r§6.* coins§r§a!"
"§aYou received §r§6.* coins§r§a!",
)

/**
* REGEX-TEST: Redstone Minion IV
* REGEX-TEST: Chicken Minion XI
*/
private val minionTitlePattern by patternGroup.pattern(
"title",
"Minion [^➜]"
"Minion [^➜]",
)
private val minionCollectItemPattern by patternGroup.pattern(
"item.collect",
"^§aCollect All$"
"^§aCollect All$",
)

var lastMinion: LorenzVec? = null
Expand Down Expand Up @@ -143,8 +156,7 @@ object MinionFeatures {
if (!enableWithHub()) return
if (!config.lastClickedMinion.display) return

val special = config.lastClickedMinion.color
val color = Color(SpecialColor.specialToChromaRGB(special), true)
val color = config.lastClickedMinion.color.toSpecialColor()

val loc = lastMinion
if (loc != null) {
Expand All @@ -156,7 +168,7 @@ object MinionFeatures {
true,
extraSize = -0.25,
extraSizeTopY = 0.2,
extraSizeBottomY = 0.0
extraSizeBottomY = 0.0,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import at.hannibal2.skyhanni.events.RenderEntityOutlineEvent
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.SpecialColor
import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColorInt
import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraft.entity.Entity
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
Expand All @@ -30,6 +30,6 @@ object PartyMemberOutlines {
private fun getEntityOutlineColor(entity: Entity): Int? {
if (entity !is EntityOtherPlayerMP || !PartyAPI.partyMembers.contains(entity.name)) return null

return SpecialColor.specialToChromaRGB(config.outlineColor)
return config.outlineColor.toSpecialColorInt()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.RenderUtils
import at.hannibal2.skyhanni.utils.RenderUtils.expandBlock
import at.hannibal2.skyhanni.utils.SpecialColor
import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColor
import at.hannibal2.skyhanni.utils.toLorenzVec
import net.minecraft.init.Blocks
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.BlockPos
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color

@SkyHanniModule
object SulphurSkitterBox {
Expand Down Expand Up @@ -78,14 +77,14 @@ object SulphurSkitterBox {
}

private fun drawBox(axis: AxisAlignedBB, partialTicks: Float) {
val color = Color(SpecialColor.specialToChromaRGB(config.boxColor), true)
val color = config.boxColor.toSpecialColor()
when (config.boxType) {
SulphurSkitterBoxConfig.BoxType.FULL -> {
RenderUtils.drawFilledBoundingBoxNea(
axis,
color,
partialTicks = partialTicks,
renderRelativeToCamera = false
renderRelativeToCamera = false,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
import at.hannibal2.skyhanni.utils.RenderUtils.exactLocation
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SkullTextureHolder
import at.hannibal2.skyhanni.utils.SpecialColor
import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColor
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.compat.getStandHelmet
import net.minecraft.client.Minecraft
Expand All @@ -22,7 +22,6 @@ import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

Expand Down Expand Up @@ -67,17 +66,17 @@ object VoltHighlighter {
VoltState.DOING_LIGHTNING -> 0x800000FF.toInt()
VoltState.HOSTILE -> 0x80FF0000.toInt()
else -> 0
}
},
) { config.voltMoodMeter }
if (state == VoltState.DOING_LIGHTNING && config.voltRange) {
RenderUtils.drawCylinderInWorld(
Color(SpecialColor.specialToChromaRGB(config.voltColour), true),
config.voltColour.toSpecialColor(),
entity.posX,
entity.posY - 4f,
entity.posZ,
radius = LIGHTNING_DISTANCE,
partialTicks = event.partialTicks,
height = 20F
height = 20F,
)
val dischargingSince = chargingSince.getOrDefault(entity, SimpleTimeMark.farPast())
val dischargeTimeLeft = CHARGE_TIME - dischargingSince.passedSince()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.SoundUtils.playSound
import at.hannibal2.skyhanni.utils.SpecialColor
import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColor
import at.hannibal2.skyhanni.utils.TimeUnit
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.Renderable.Companion.horizontalContainer
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color
import kotlin.math.ceil
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -115,7 +114,7 @@ object SkillProgress {
maxWidth = 182
Renderable.progressBar(
percent = factor.toDouble(),
startColor = Color(SpecialColor.specialToChromaRGB(barConfig.barStartColor)),
startColor = barConfig.barStartColor.toSpecialColor(),
texture = barConfig.texturedBar.usedTexture.get(),
useChroma = barConfig.useChroma.get(),
)
Expand All @@ -125,8 +124,8 @@ object SkillProgress {
val factor = skillExpPercentage.coerceAtMost(1.0)
Renderable.progressBar(
percent = factor,
startColor = Color(SpecialColor.specialToChromaRGB(barConfig.barStartColor)),
endColor = Color(SpecialColor.specialToChromaRGB(barConfig.barStartColor)),
startColor = barConfig.barStartColor.toSpecialColor(),
endColor = barConfig.barStartColor.toSpecialColor(),
width = maxWidth,
height = barConfig.regularBar.height,
useChroma = barConfig.useChroma.get(),
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColor
import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColorInt
import java.awt.Color

object ColorUtils {

/** Transfer string colors from the config to [Color] */
fun String.toChromaColor() = Color(toChromaColorInt(), true)
fun String.toChromaColorInt() = SpecialColor.specialToChromaRGB(this)
@Deprecated("Use toSpecialColor() instead", ReplaceWith("this.toSpecialColor()"))
fun String.toChromaColor() = this.toSpecialColor()

@Deprecated("Use toSpecialColorInt() instead", ReplaceWith("this.toSpecialColorInt()"))
fun String.toChromaColorInt() = this.toSpecialColorInt()

fun String.getFirstColorCode() = takeIf { it.firstOrNull() == '§' }?.getOrNull(1)

Expand Down
72 changes: 0 additions & 72 deletions src/main/java/at/hannibal2/skyhanni/utils/SpecialColor.java

This file was deleted.

31 changes: 31 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/SpecialColor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package at.hannibal2.skyhanni.utils

import java.awt.Color

/**
* Taken from NotEnoughUpdates,
* translated to Kotlin and modified.
*/
object SpecialColor {
private const val MIN_CHROMA_SECS = 1
private const val MAX_CHROMA_SECS = 60
private var startTime = SimpleTimeMark.farPast()

fun String.toSpecialColor() = Color(toSpecialColorInt(), true)

fun String.toSpecialColorInt(): Int {
if (startTime.isFarPast()) startTime = SimpleTimeMark.now()

val (chroma, alpha, red, green, blue) = decompose(this)
val (hue, sat, bri) = Color.RGBtoHSB(red, green, blue, null)

val adjustedHue = if (chroma > 0) (hue + (startTime.passedSince().inWholeMilliseconds / 1000f / chromaSpeed(chroma) % 1)).let {
if (it < 0) it + 1f else it
} else hue

return (alpha and 0xFF) shl 24 or (Color.HSBtoRGB(adjustedHue, sat, bri) and 0x00FFFFFF)
}

private fun decompose(csv: String) = csv.split(":").mapNotNull { it.toIntOrNull() }.toIntArray()
private fun chromaSpeed(speed: Int) = (255 - speed) / 254f * (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + MIN_CHROMA_SECS
}
3 changes: 0 additions & 3 deletions versions/1.8.9/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@
<ID>RepoPatternRegexTest:MaxwellAPI.kt$MaxwellAPI$by patternGroup.pattern( "gui.noselectedpower", "(?:§.)*Visit Maxwell in the Hub to learn", )</ID>
<ID>RepoPatternRegexTest:MaxwellAPI.kt$MaxwellAPI$by patternGroup.pattern( "gui.thaumaturgy.data", "§(?&lt;color&gt;.)\\+(?&lt;amount&gt;[^ ]+)(?&lt;icon&gt;.) (?&lt;name&gt;.+)", )</ID>
<ID>RepoPatternRegexTest:MinionCraftHelper.kt$MinionCraftHelper$by RepoPattern.pattern( "bingo.minion.name", "(?&lt;name&gt;.*) Minion (?&lt;number&gt;.*)" )</ID>
<ID>RepoPatternRegexTest:MinionFeatures.kt$MinionFeatures$by patternGroup.pattern( "chat.coin", "§aYou received §r§6.* coins§r§a!" )</ID>
<ID>RepoPatternRegexTest:MinionFeatures.kt$MinionFeatures$by patternGroup.pattern( "chat.upgrade", "§aYou have upgraded your Minion to Tier (?&lt;tier&gt;.*)" )</ID>
<ID>RepoPatternRegexTest:MinionFeatures.kt$MinionFeatures$by patternGroup.pattern( "title", "Minion [^➜]" )</ID>
<ID>RepoPatternRegexTest:MobFilter.kt$MobFilter$by repoGroup.pattern( "filter.dojo", "^(?:(?&lt;points&gt;\\d+) pts|(?&lt;empty&gt;\\w+))$", )</ID>
<ID>RepoPatternRegexTest:MobFilter.kt$MobFilter$by repoGroup.pattern( "filter.summon", "^(?&lt;owner&gt;\\w+)'s (?&lt;name&gt;.*) \\d+.*", )</ID>
<ID>RepoPatternRegexTest:MobFilter.kt$MobFilter$by repoGroup.pattern( "jerry", "(?:\\[\\w+(?&lt;level&gt;\\d+)\\] )?(?&lt;owner&gt;\\w+)'s (?&lt;name&gt;\\w+ Jerry) \\d+ Hits", )</ID>
Expand Down

0 comments on commit f411297

Please sign in to comment.