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

Backend: Remove renderSingleLineWithItems #3065

Open
wants to merge 12 commits into
base: beta
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.RenderUtils.renderSingleLineWithItems
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SkyBlockTime
import at.hannibal2.skyhanni.utils.SoundUtils
Expand All @@ -29,7 +29,7 @@ object Year300RaffleEvent {
private var lastTimerReceived = SimpleTimeMark.farPast()
private var lastTimeAlerted = SimpleTimeMark.farPast()

private var overlay: List<Any>? = null
private var overlay: Renderable? = null

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
Expand All @@ -43,10 +43,7 @@ object Year300RaffleEvent {

@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
config.activeTimerPosition.renderSingleLineWithItems(
overlay ?: return,
posLabel = "300þ Anniversary Active Timer"
)
config.activeTimerPosition.renderRenderable(overlay, posLabel = "300þ Anniversary Active Timer")
}

@SubscribeEvent
Expand All @@ -65,9 +62,11 @@ object Year300RaffleEvent {
SoundUtils.centuryActiveTimerAlert.playSound()
lastTimeAlerted = SimpleTimeMark.now()
}
overlay = listOf(
Renderable.itemStack(displayItem),
Renderable.string("§eTime Left: ${timeLeft.format()}")
overlay = Renderable.verticalContainer(
listOf(
Renderable.itemStack(displayItem),
Renderable.string("§eTime Left: ${timeLeft.format()}")
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.CollectionUtils.addItemStack
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.addItemIcon
import at.hannibal2.skyhanni.utils.RenderUtils.renderSingleLineWithItems
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.minutes
Expand All @@ -25,9 +27,9 @@ object JyrreTimer {
private val config get() = SkyHanniMod.feature.event.winter.jyrreTimer
private val drankBottlePattern by RepoPattern.pattern(
"event.winter.drank.jyrre",
"§aYou drank a §r§6Refined Bottle of Jyrre §r§aand gained §r§b\\+300✎ Intelligence §r§afor §r§b60 minutes§r§a!"
"§aYou drank a §r§6Refined Bottle of Jyrre §r§aand gained §r§b\\+300✎ Intelligence §r§afor §r§b60 minutes§r§a!",
)
private var display = emptyList<Any>()
private var display: Renderable? = null
private var duration = 0.seconds

@HandleEvent
Expand All @@ -36,8 +38,8 @@ object JyrreTimer {
}

private fun resetDisplay() {
if (display.isEmpty()) return
display = if (config.showInactive) drawDisplay() else emptyList()
if (display == null) return
display = if (config.showInactive) drawDisplay() else null
duration = 0.seconds
}

Expand All @@ -50,14 +52,14 @@ object JyrreTimer {
@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
if (!isEnabled()) return
config.pos.renderSingleLineWithItems(display, posLabel = "Refined Jyrre Timer")
config.pos.renderRenderable(display, posLabel = "Refined Jyrre Timer")
}

@SubscribeEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (!isEnabled()) return

if (display.isNotEmpty() && !config.showInactive && duration <= 0.seconds) {
if (display != null && !config.showInactive && duration <= 0.seconds) {
resetDisplay()
return
}
Expand All @@ -67,20 +69,21 @@ object JyrreTimer {

private val displayIcon by lazy { "REFINED_BOTTLE_OF_JYRRE".toInternalName().getItemStack() }

fun drawDisplay(): MutableList<Any> {
fun drawDisplay(): Renderable {
duration -= 1.seconds

return mutableListOf<Any>().apply {
addItemIcon(displayIcon)
add("§aJyrre Boost: ")
return Renderable.horizontalContainer(
buildList {
addItemStack(displayIcon)
addString("§aJyrre Boost: ")

if (duration <= 0.seconds && config.showInactive) {
add("§cInactive!")
} else {
val format = duration.format()
add("§b$format")
}
}
if (duration <= 0.seconds && config.showInactive) {
addString("§cInactive!")
} else {
addString("§b${duration.format()}")
}
},
)
}

private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.RenderUtils.addItemIcon
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getCultivatingCounter
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getHoeCounter
import at.hannibal2.skyhanni.utils.renderables.Renderable
Expand Down Expand Up @@ -172,16 +171,7 @@ object GardenAPI {

fun readCounter(itemStack: ItemStack): Long = itemStack.getHoeCounter() ?: itemStack.getCultivatingCounter() ?: -1L

@Deprecated("use renderable list instead", ReplaceWith(""))
fun MutableList<Any>.addCropIcon(
crop: CropType,
scale: Double = NEUItems.itemFontSize,
highlight: Boolean = false,
) =
addItemIcon(crop.icon.copy(), highlight, scale = scale)

// TODO rename to addCropIcon
fun MutableList<Renderable>.addCropIconRenderable(
fun MutableList<Renderable>.addCropIcon(
crop: CropType,
scale: Double = NEUItems.itemFontSize,
highlight: Boolean = false,
Expand Down
Loading
Loading