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 18 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,44 @@
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.FlowstateHelper;
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 java.util.List;

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

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

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

@Expose
@ConfigOption(name = "Autohide", desc = "Automatically hides the GUI after a certain time idle, in seconds.")
@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 @@ -73,6 +73,11 @@ public class MiningConfig {
@Accordion
public MineshaftPityDisplayConfig mineshaftPityDisplay = new MineshaftPityDisplayConfig();

@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
180 changes: 180 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,180 @@
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.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 at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
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
private var streakEndTimer = SimpleTimeMark.farPast()
private var blockBreakStreak = 0

private var display: List<Renderable>? = null
private var displayDirty = false
private var displayHibernating = true
private var timeSinceHibernation = SimpleTimeMark.farPast()

private var flowstateCache: Int? = null

private val pickobulusPattern by RepoPattern.pattern(
"mining.pickobulus.blockdestroy",
"§7Your §r§aPickobulus §r§7destroyed §r§e(?<amount>\\d+) §r§7blocks!"
)

enum class GUIElements(val label: String, var renderable: Renderable = Renderable.string("")) {
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
TITLE("§d§lFlowstate Helper", Renderable.string("§d§lFlowstate Helper")),
TIMER("Time Remaining: §b6.71"),
STREAK("Streak: §7234"),
SPEED("§6+600⸕"),
;

override fun toString() = label

fun create() {
when (this) {
TIMER -> {
var timeRemaining = streakEndTimer.minus(SimpleTimeMark.now())
if (timeRemaining < 0.seconds) timeRemaining = 0.seconds

renderable = Renderable.string(
"Time Remaining: ${getTimerColor(timeRemaining)}${
timeRemaining.format(
TimeUnit.SECOND, true, maxUnits = 2, showSmallerUnits = true
)
}")
}
STREAK -> {
val textColor = if (blockBreakStreak < 200) "§7" else "§f"
renderable = Renderable.string("Streak: $textColor$blockBreakStreak")
}
SPEED -> renderable = Renderable.string("§6+${getSpeedBonus()}⸕")
else -> return
}
}

companion object {
@JvmField
val defaultOption = listOf(
TITLE, TIMER, STREAK, SPEED
)
}
}

@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
displayDirty = true
if (!displayHibernating) timeSinceHibernation = SimpleTimeMark.now()
displayHibernating = true
createDisplay()
}

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

if (displayHibernating && config.autoHide > -1 && timeSinceHibernation.passedSince() > config.autoHide.seconds) return
if (display == null || streakEndTimer.isInFuture()) {
createDisplay()
}

display?.let {
config.position.renderRenderables(
it,
1,
"Flowstate Helper",
true
)
}
}

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

private fun getSpeedBonus(): Int {
val flowstateLevel = flowstateCache ?: 0
if (blockBreakStreak >= 200) return 200 * flowstateLevel
return blockBreakStreak * flowstateLevel
}

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

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

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

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")
}
}
Loading