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: Flowstate helper #2561

Merged
merged 31 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a16e2ba
init flowstate helper
martimavocado Sep 21, 2024
25be3b0
revamp gui look
martimavocado Sep 21, 2024
ef2168a
add pickoniumbus support
martimavocado Sep 21, 2024
6b36db7
fix config
martimavocado Sep 21, 2024
68cdf6a
remove gethelditem
martimavocado Sep 21, 2024
773c923
cache some values
martimavocado Sep 21, 2024
7170948
fix list building, finish caching stuff
martimavocado Sep 21, 2024
c47871a
add pickobulus todo
martimavocado Sep 21, 2024
c36de06
turn gui into a draggablelist
martimavocado Sep 21, 2024
9796dca
Merge remote-tracking branch 'hannibal002/beta' into feature/flowstat…
martimavocado Sep 21, 2024
5ea502f
misc fixes
martimavocado Sep 22, 2024
ff4b6fb
add default location, reset on islandchange
martimavocado Sep 22, 2024
36fee90
add cal's suggestions
martimavocado Sep 22, 2024
a347749
Merge remote-tracking branch 'hannibal002/beta' into feature/flowstat…
martimavocado Sep 23, 2024
300b53b
hanni's review
martimavocado Sep 23, 2024
761ae63
add colorful timer
martimavocado Sep 23, 2024
dce3f4a
try adding autohide
martimavocado Sep 23, 2024
9360865
fix autohide
martimavocado Sep 23, 2024
d8bd59f
move and rename enum
martimavocado Sep 24, 2024
9f57a53
Merge remote-tracking branch 'hannibal002/beta' into feature/flowstat…
martimavocado Sep 29, 2024
e246ec9
add compact gui element
martimavocado Oct 2, 2024
17b4f5d
Merge remote-tracking branch 'hannibal002/beta' into feature/flowstat…
martimavocado Oct 11, 2024
8b65b11
hi empa
martimavocado Oct 11, 2024
063cac6
Merge branch 'refs/heads/beta' into fork/martimavocado/feature/flowst…
hannibal002 Oct 13, 2024
6e21e55
code cleanup
hannibal002 Oct 13, 2024
2977375
cleanup, show gui if active and not holding
martimavocado Oct 13, 2024
5d6230b
autohide improvements
martimavocado Oct 13, 2024
c0fdbb4
remove autohide on max
martimavocado Oct 13, 2024
7dfabbd
hi empa
martimavocado Oct 13, 2024
5a5644f
Merge branch 'refs/heads/beta' into fork/martimavocado/feature/flowst…
hannibal002 Oct 13, 2024
f35b97c
removed comment, changed default value
hannibal002 Oct 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package at.hannibal2.skyhanni.config.features.mining;

import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.config.core.config.Position;
import at.hannibal2.skyhanni.features.mining.FlowstateElements;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider;
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
import io.github.notenoughupdates.moulconfig.annotations.SearchTag;

import java.util.List;

public class FlowstateHelperConfig {
@Expose
@ConfigOption(name = "Enabled", desc = "Shows stats for the Flowstate enchantment on Mining Tools.")
@ConfigEditorBoolean
@FeatureToggle
public boolean enabled = false;

@Expose
@ConfigOption(name = "Appearance", desc = "Drag text to change the appearance.")
@ConfigEditorDraggableList()
public List<FlowstateElements> appearance = FlowstateElements.defaultOption;

@Expose
@ConfigOption(name = "Dynamic Color", desc = "Makes the timer's color dynamic.")
@ConfigEditorBoolean
public boolean colorfulTimer = false;

@Expose
@ConfigOption(name = "Auto Hide", desc = "Automatically hides the GUI after being idle or having the max bonus, in seconds.")
@SearchTag("autohide")
@ConfigEditorSlider(
minValue = -1,
maxValue = 30,
minStep = 1
)
public int autoHide = 5;

@Expose
@ConfigLink(owner = FlowstateHelperConfig.class, field = "enabled")
public Position position = new Position(-110 , 9);
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public class MiningConfig {
@Accordion
public CrystalHighlighterConfig crystalHighlighter = new CrystalHighlighterConfig();

@Expose
@ConfigOption(name = "Flowstate Helper", desc = "")
@Accordion
public FlowstateHelperConfig flowstateHelper = new FlowstateHelperConfig();

@Expose
@ConfigOption(name = "Highlight Commission Mobs", desc = "Highlight mobs that are part of active commissions.")
@ConfigEditorBoolean
Expand Down
217 changes: 217 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/features/mining/FlowstateHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
package at.hannibal2.skyhanni.features.mining

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.MiningAPI
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.events.ItemInHandChangeEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.mining.OreMinedEvent
import at.hannibal2.skyhanni.features.mining.FlowstateHelper.blockBreakStreak
import at.hannibal2.skyhanni.features.mining.FlowstateHelper.getSpeedBonus
import at.hannibal2.skyhanni.features.mining.FlowstateHelper.getStreakColor
import at.hannibal2.skyhanni.features.mining.FlowstateHelper.getTimerColor
import at.hannibal2.skyhanni.features.mining.FlowstateHelper.streakEndTimer
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments
import at.hannibal2.skyhanni.utils.TimeUnit
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

@SkyHanniModule
object FlowstateHelper {
private val config get() = SkyHanniMod.feature.mining.flowstateHelper

var streakEndTimer = SimpleTimeMark.farPast()
private set
var blockBreakStreak = 0
private set

private var display: List<Renderable> = emptyList()
private var displayDirty = false
private var displayHibernating = true
private var timeSinceHibernation = SimpleTimeMark.farPast()
private var timeSinceMax = SimpleTimeMark.farPast()
private var displayMaxed = false

private var flowstateCache: Int? = null

@HandleEvent(onlyOnSkyblock = true)
fun onBlockMined(event: OreMinedEvent) {
if (!MiningAPI.inCustomMiningIsland()) return
if (flowstateCache == null) return

displayHibernating = false
streakEndTimer = 10.seconds.fromNow()
blockBreakStreak += event.extraBlocks.values.sum()
displayDirty = true
createDisplay()
}

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!MiningAPI.inCustomMiningIsland()) return

attemptClearDisplay()
}
martimavocado marked this conversation as resolved.
Show resolved Hide resolved

private fun attemptClearDisplay() {
if (streakEndTimer.isInFuture()) return
blockBreakStreak = 0
timeSinceMax = SimpleTimeMark.farPast()
displayMaxed = false
displayDirty = true
if (!displayHibernating) timeSinceHibernation = SimpleTimeMark.now()
displayHibernating = true
createDisplay()
}

@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
if (!MiningAPI.inCustomMiningIsland() || !config.enabled) return
if (flowstateCache == null && !streakEndTimer.isInFuture()) return

if (shouldAutoHide()) return
if (display.isEmpty() || streakEndTimer.isInFuture()) {
createDisplay()
}

config.position.renderRenderables(display, extraSpace = 1, "Flowstate Helper")
}

private fun shouldAutoHide(): Boolean {
if (config.autoHide < 0) return false
val autoHide = config.autoHide.seconds
if (streakEndTimer.minus(10.seconds - autoHide).isInPast()) return true
if (displayMaxed && timeSinceMax.passedSince() > autoHide) return true
return false
}

private fun createDisplay() {
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
if (displayDirty) {
displayDirty = false
FlowstateElements.STREAK.create()
FlowstateElements.SPEED.create()
}
if (!displayHibernating) {
FlowstateElements.TIMER.create()
FlowstateElements.COMPACT.create()
}
display = config.appearance.map { it.renderable }
}

fun getSpeedBonus(): Int {
val flowstateLevel = flowstateCache ?: 0

return if (blockBreakStreak >= 200) {
if (!displayMaxed) {
displayMaxed = true
timeSinceMax = SimpleTimeMark.now()
}
200 * flowstateLevel
} else blockBreakStreak * flowstateLevel
}

@SubscribeEvent
fun onChangeItem(event: ItemInHandChangeEvent) {
hasFlowstate()
}

@SubscribeEvent
fun onIslandChange(event: IslandChangeEvent) {
streakEndTimer = SimpleTimeMark.farPast()
attemptClearDisplay()
}

fun getTimerColor(timeRemaining: Duration): String {
if (!config.colorfulTimer) return "§b"
return when (timeRemaining) {
in 0.seconds..2.seconds -> "§c"
in 2.seconds..4.seconds -> "§#§e§c§7§b§3§6§/"
in 4.seconds..6.seconds -> "§e"
in 6.seconds..8.seconds -> "§a"
in 8.seconds..10.seconds -> "§2"
else -> "§6"
}
}

fun getStreakColor(streak: Int = blockBreakStreak): String = if (streak < 200) "§e" else "§a"

private fun hasFlowstate() {
val enchantList = InventoryUtils.getItemInHand()?.getEnchantments() ?: run {
flowstateCache = null
return
}
if ("ultimate_flowstate" !in enchantList) {
flowstateCache = null
return
}
flowstateCache = enchantList.getValue("ultimate_flowstate")
}
}

enum class FlowstateElements(val label: String, var renderable: Renderable = Renderable.string("")) {
TITLE("§d§lFlowstate Helper", Renderable.string("§d§lFlowstate Helper")),
TIMER("§fTime Remaining: §b9.71"),
STREAK("§7Streak: §f123/200"),
SPEED("§6+600⸕"),
COMPACT("§7x40 §6+120⸕ §b(9.71)"),
;

override fun toString() = label

fun create() {
if (this !in config.appearance) return

renderable = when (this) {
TIMER -> {
val timeRemaining = streakEndTimer.timeUntil().coerceAtLeast(0.seconds)

Renderable.string("§7Time Remaining: ${timeRemaining.formatTime()}")
}

STREAK -> {
val textColor = getStreakColor()
val string = "§7Streak: $textColor$blockBreakStreak"
Renderable.string(string + if (blockBreakStreak < 200) "§8/200" else "")
}

SPEED -> {
Renderable.string("§6+${getSpeedBonus()}⸕")
}

COMPACT -> {
val timeRemaining = streakEndTimer.timeUntil().coerceAtLeast(0.seconds)

Renderable.string(
"§7x${getStreakColor()}$blockBreakStreak " +
"§6+${getSpeedBonus()}⸕ " +
timeRemaining.formatTime(),
)
}

else -> return
}
}

companion object {
private val config get() = SkyHanniMod.feature.mining.flowstateHelper

private fun Duration.formatTime(): String {
return getTimerColor(this) + format(TimeUnit.SECOND, true, maxUnits = 2, showSmallerUnits = true)
}

@JvmField
val defaultOption = listOf(
TITLE, TIMER, STREAK, SPEED,
)
}
}
Loading