Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Flare Display #1803

Merged
merged 12 commits into from
May 24, 2024
Prev Previous commit
Next Next commit
allow showing multiple flare outlines of the same type
  • Loading branch information
hannibal002 committed May 24, 2024
commit fe19eb1410e74db32190da53b295b829a4c807a4
47 changes: 31 additions & 16 deletions src/main/java/at/hannibal2/skyhanni/features/combat/FlareDisplay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor
import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.EntityUtils.hasSkullTexture
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RenderUtils
import at.hannibal2.skyhanni.utils.RenderUtils.drawSphereInWorld
import at.hannibal2.skyhanni.utils.RenderUtils.drawSphereWireframeInWorld
Expand All @@ -28,7 +29,10 @@ object FlareDisplay {

private val config get() = SkyHanniMod.feature.combat.flare
private var display = emptyList<Renderable>()
private var flareList = mutableMapOf<FlareType, EntityArmorStand>()
private var flareList = mutableListOf<Flare>()

class Flare(val type: FlareType, val entity: EntityArmorStand, val location: LorenzVec = entity.getLorenzVec())

private val MAX_FLARE_TIME = 3.minutes

private val flares = mapOf(
Expand All @@ -49,28 +53,27 @@ object FlareDisplay {
@SubscribeEvent
fun onSecondsPassed(event: SecondPassedEvent) {
if (!isEnabled()) return
flareList.values.removeIf { !it.isEntityAlive }
flareList.removeIf { !it.entity.isEntityAlive }
for (entity in EntityUtils.getAllEntities().filterIsInstance<EntityArmorStand>()) {
if (entity.ticksExisted.ticks > MAX_FLARE_TIME) continue
for ((texture, flareType) in flares) {
if (flareList.contains(flareType)) continue
if (entity.hasSkullTexture(texture)) {
flareList[flareType] = entity
}
if (isAlreadyKnownFlare(entity)) continue
getFlareTypeForTexuture(entity)?.let {
flareList.add(Flare(it, entity))
}
}
var newDisplay: List<Renderable>? = null
for (flare in FlareType.entries) {
val entity = flareList[flare] ?: continue
for (type in FlareType.entries) {
val flare = getFlareForType(type) ?: continue
val entity = flare.entity
val aliveTime = entity.ticksExisted.ticks
val remainingTime = (MAX_FLARE_TIME - aliveTime)

val name = flare.displayName
val name = type.displayName
if (newDisplay == null) {
newDisplay = buildList {
add(Renderable.string("$name: §b${remainingTime.format()}"))
if (config.showManaBuff) {
flare.manaBuff?.let {
type.manaBuff?.let {
add(Renderable.string(" §b$it §7mana regen"))
}
}
Expand Down Expand Up @@ -98,6 +101,14 @@ object FlareDisplay {
display = newDisplay ?: emptyList()
}

private fun getFlareForType(type: FlareType): Flare? = flareList.firstOrNull { it.type == type }

private fun getFlareTypeForTexuture(entity: EntityArmorStand): FlareType? =
flares.entries.firstOrNull { entity.hasSkullTexture(it.key) }?.value

private fun isAlreadyKnownFlare(entity: EntityArmorStand): Boolean =
flareList.any { it.entity.entityId == entity.entityId }

@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
flareList.clear()
Expand All @@ -107,28 +118,32 @@ object FlareDisplay {
@SubscribeEvent
fun onRender(event: LorenzRenderWorldEvent) {
if (!isEnabled()) return
for ((flare, entity) in flareList) {
if (config.outlineType == FlareConfig.OutlineType.NONE) return

val color = when (flare) {
for (flare in flareList) {
val entity = flare.entity
val location = flare.location

val color = when (flare.type) {
FlareType.WARNING -> config.warningColor
FlareType.ALERT -> config.alertColor
FlareType.SOS -> config.sosColor
}.toChromaColor()

when (config.outlineType) {
FlareConfig.OutlineType.FILLED -> {
event.drawSphereInWorld(color, entity.getLorenzVec(), 40f)
event.drawSphereInWorld(color, location, 40f)
}

FlareConfig.OutlineType.WIREFRAME -> {
event.drawSphereWireframeInWorld(color, entity.getLorenzVec(), 40f)
event.drawSphereWireframeInWorld(color, location, 40f)
}

FlareConfig.OutlineType.CIRCLE -> {
RenderUtils.drawCircle(entity, event.partialTicks, 40.0, color)
}

else -> return
else -> {}
}
}
}
Expand Down