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 3 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
@@ -1,10 +1,12 @@
package at.hannibal2.skyhanni.config.features.mining;

import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.config.core.config.Position;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.Accordion;
import io.github.notenoughupdates.moulconfig.annotations.Category;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

public class MiningConfig {
Expand Down Expand Up @@ -102,4 +104,15 @@ public class MiningConfig {
@ConfigEditorBoolean
@FeatureToggle
public boolean forgeGfs = false;

@Expose
@ConfigOption(name = "Flowstate Helper", desc = "Shows stats for the Flowstate enchantment.")
@ConfigEditorBoolean
@FeatureToggle
public boolean flowstateHelper = false;

@Expose
@ConfigOption(name = "Flowstate Helper", desc = "Shows stats for the Flowstate enchantment.")
@ConfigLink(owner = MiningConfig.class, field = "flowstateHelper")
public Position flowstateHelperPosition = new Position();
}
123 changes: 123 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,123 @@
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.LorenzChatEvent
import at.hannibal2.skyhanni.events.mining.OreMinedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.ItemUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments
import at.hannibal2.skyhanni.utils.inPartialSeconds
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.seconds

@SkyHanniModule
object FlowstateHelper {
private val config get() = SkyHanniMod.feature.mining
private var timeSinceBreak = SimpleTimeMark.farPast()
private var display: List<Renderable>? = null

private var blockBreakStreak = 0

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

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

timeSinceBreak = SimpleTimeMark.now().plus(10.seconds)
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
blockBreakStreak += event.extraBlocks.values.sum()
createDisplay()
attemptClearDisplay()
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
}

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!MiningAPI.inCustomMiningIsland()) return
if (hasFlowstate() == null) return

pickobulusPattern.matchMatcher(event.message) {
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
timeSinceBreak = SimpleTimeMark.now().plus(10.seconds)
blockBreakStreak += group("amount").toInt()
createDisplay()
attemptClearDisplay()
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
}
}

private fun attemptClearDisplay() {
DelayedRun.runDelayed(10.seconds) {
if (timeSinceBreak.isInFuture()) return@runDelayed
blockBreakStreak = 0
createDisplay()
}
}
martimavocado marked this conversation as resolved.
Show resolved Hide resolved

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

if (display == null || timeSinceBreak.isInFuture()) createDisplay()
display?.let {
config.flowstateHelperPosition.renderRenderables(
listOf(Renderable.verticalContainer(it, 1)),
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
posLabel = "Flowstate Helper",
addToGuiManager = true
)
}
}

private fun createDisplay() {
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
val helperDisplay: MutableList<Renderable> = mutableListOf()
martimavocado marked this conversation as resolved.
Show resolved Hide resolved

helperDisplay.add(Renderable.string("§d§lFlowstate Helper"))
helperDisplay.add(createDisplayTimer())
helperDisplay.add(createDisplayBlock())
helperDisplay.add(Renderable.string("§6+${getSpeedBonus()}⸕"))
martimavocado marked this conversation as resolved.
Show resolved Hide resolved

display = helperDisplay.toList()
}

private fun createDisplayTimer(): Renderable {
var timeRemaining = timeSinceBreak.minus(SimpleTimeMark.now()).inPartialSeconds
if (timeRemaining < 0.0) timeRemaining = 0.0

val timerColor = when (timeRemaining) {
in 0.0..3.0 -> "§c"
in 3.0..6.0 -> "§e"
in 6.0..10.0 -> "§a"
else -> "§c"
}
return Renderable.string("Time Remaining: $timerColor$timeRemaining")
}

private fun createDisplayBlock(): Renderable {
val textColor = if (blockBreakStreak < 200) "§7" else "§f"
return Renderable.string("Streak: $textColor$blockBreakStreak")
}

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

private fun hasFlowstate(): Int? {
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
val enchantList = ItemUtils.getHeldItem()?.getEnchantments() ?: return null
if ("ultimate_flowstate" !in enchantList) return null
return enchantList.getValue("ultimate_flowstate")
}
}
5 changes: 5 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,9 @@ object ItemUtils {
true, true,
)
}

fun getHeldItem(): ItemStack? {
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
val player = Minecraft.getMinecraft().thePlayer ?: return null
return player.heldItem
}
}
Loading