Fix drill ability cooldown resetting on world swap
This commit is contained in:
7
src/main/kotlin/events/ProfileSwitchEvent.kt
Normal file
7
src/main/kotlin/events/ProfileSwitchEvent.kt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package moe.nea.firmament.events
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
data class ProfileSwitchEvent(val oldProfile: UUID?, val newProfile: UUID?) : FirmamentEvent() {
|
||||||
|
companion object : FirmamentEventBus<ProfileSwitchEvent>()
|
||||||
|
}
|
||||||
@@ -11,13 +11,16 @@ import net.minecraft.util.Identifier
|
|||||||
import moe.nea.firmament.annotations.Subscribe
|
import moe.nea.firmament.annotations.Subscribe
|
||||||
import moe.nea.firmament.events.HudRenderEvent
|
import moe.nea.firmament.events.HudRenderEvent
|
||||||
import moe.nea.firmament.events.ProcessChatEvent
|
import moe.nea.firmament.events.ProcessChatEvent
|
||||||
|
import moe.nea.firmament.events.ProfileSwitchEvent
|
||||||
import moe.nea.firmament.events.SlotClickEvent
|
import moe.nea.firmament.events.SlotClickEvent
|
||||||
import moe.nea.firmament.events.WorldReadyEvent
|
import moe.nea.firmament.events.WorldReadyEvent
|
||||||
import moe.nea.firmament.features.FirmamentFeature
|
import moe.nea.firmament.features.FirmamentFeature
|
||||||
import moe.nea.firmament.gui.config.ManagedConfig
|
import moe.nea.firmament.gui.config.ManagedConfig
|
||||||
import moe.nea.firmament.util.DurabilityBarEvent
|
import moe.nea.firmament.util.DurabilityBarEvent
|
||||||
import moe.nea.firmament.util.MC
|
import moe.nea.firmament.util.MC
|
||||||
|
import moe.nea.firmament.util.SBData
|
||||||
import moe.nea.firmament.util.SHORT_NUMBER_FORMAT
|
import moe.nea.firmament.util.SHORT_NUMBER_FORMAT
|
||||||
|
import moe.nea.firmament.util.SkyBlockIsland
|
||||||
import moe.nea.firmament.util.TIME_PATTERN
|
import moe.nea.firmament.util.TIME_PATTERN
|
||||||
import moe.nea.firmament.util.TimeMark
|
import moe.nea.firmament.util.TimeMark
|
||||||
import moe.nea.firmament.util.extraAttributes
|
import moe.nea.firmament.util.extraAttributes
|
||||||
@@ -59,13 +62,14 @@ object PickaxeAbility : FirmamentFeature {
|
|||||||
|
|
||||||
fun getCooldownPercentage(name: String, cooldown: Duration): Double {
|
fun getCooldownPercentage(name: String, cooldown: Duration): Double {
|
||||||
val sinceLastUsage = lastUsage[name]?.passedTime() ?: Duration.INFINITE
|
val sinceLastUsage = lastUsage[name]?.passedTime() ?: Duration.INFINITE
|
||||||
|
val sinceLobbyJoin = lobbyJoinTime.passedTime()
|
||||||
|
if (SBData.skyblockLocation == SkyBlockIsland.MINESHAFT) {
|
||||||
|
if (sinceLobbyJoin < sinceLastUsage) {
|
||||||
|
return 1.0
|
||||||
|
}
|
||||||
|
}
|
||||||
if (sinceLastUsage < cooldown)
|
if (sinceLastUsage < cooldown)
|
||||||
return sinceLastUsage / cooldown
|
return sinceLastUsage / cooldown
|
||||||
val sinceLobbyJoin = lobbyJoinTime.passedTime()
|
|
||||||
val halfCooldown = cooldown / 2
|
|
||||||
if (sinceLobbyJoin < halfCooldown) {
|
|
||||||
return (sinceLobbyJoin / halfCooldown)
|
|
||||||
}
|
|
||||||
return 1.0
|
return 1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,11 +121,15 @@ object PickaxeAbility : FirmamentFeature {
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
fun onWorldReady(event: WorldReadyEvent) {
|
fun onWorldReady(event: WorldReadyEvent) {
|
||||||
lastUsage.clear()
|
|
||||||
lobbyJoinTime = TimeMark.now()
|
lobbyJoinTime = TimeMark.now()
|
||||||
abilityOverride = null
|
abilityOverride = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
fun onProfileSwitch(event: ProfileSwitchEvent) {
|
||||||
|
lastUsage.clear()
|
||||||
|
}
|
||||||
|
|
||||||
val abilityUsePattern = Pattern.compile("You used your (?<name>.*) Pickaxe Ability!")
|
val abilityUsePattern = Pattern.compile("You used your (?<name>.*) Pickaxe Ability!")
|
||||||
val fuelPattern = Pattern.compile("Fuel: .*/(?<maxFuel>$SHORT_NUMBER_FORMAT)")
|
val fuelPattern = Pattern.compile("Fuel: .*/(?<maxFuel>$SHORT_NUMBER_FORMAT)")
|
||||||
|
|
||||||
@@ -132,7 +140,7 @@ object PickaxeAbility : FirmamentFeature {
|
|||||||
|
|
||||||
fun getCooldownFromLore(itemStack: ItemStack): PickaxeAbilityData? {
|
fun getCooldownFromLore(itemStack: ItemStack): PickaxeAbilityData? {
|
||||||
val lore = itemStack.loreAccordingToNbt
|
val lore = itemStack.loreAccordingToNbt
|
||||||
if (!lore.any { it.unformattedString.contains("Breaking Power") == true })
|
if (!lore.any { it.unformattedString.contains("Breaking Power") })
|
||||||
return null
|
return null
|
||||||
val cooldown = lore.firstNotNullOfOrNull {
|
val cooldown = lore.firstNotNullOfOrNull {
|
||||||
cooldownPattern.useMatch(it.unformattedString) {
|
cooldownPattern.useMatch(it.unformattedString) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import kotlin.jvm.optionals.getOrNull
|
|||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
import moe.nea.firmament.events.AllowChatEvent
|
import moe.nea.firmament.events.AllowChatEvent
|
||||||
import moe.nea.firmament.events.ProcessChatEvent
|
import moe.nea.firmament.events.ProcessChatEvent
|
||||||
|
import moe.nea.firmament.events.ProfileSwitchEvent
|
||||||
import moe.nea.firmament.events.ServerConnectedEvent
|
import moe.nea.firmament.events.ServerConnectedEvent
|
||||||
import moe.nea.firmament.events.SkyblockServerUpdateEvent
|
import moe.nea.firmament.events.SkyblockServerUpdateEvent
|
||||||
import moe.nea.firmament.events.WorldReadyEvent
|
import moe.nea.firmament.events.WorldReadyEvent
|
||||||
@@ -54,6 +55,7 @@ object SBData {
|
|||||||
ProcessChatEvent.subscribe(receivesCancelled = true, "SBData:loadProfile") { event ->
|
ProcessChatEvent.subscribe(receivesCancelled = true, "SBData:loadProfile") { event ->
|
||||||
val profileMatch = profileRegex.matchEntire(event.unformattedString)
|
val profileMatch = profileRegex.matchEntire(event.unformattedString)
|
||||||
if (profileMatch != null) {
|
if (profileMatch != null) {
|
||||||
|
val oldProfile = profileId
|
||||||
try {
|
try {
|
||||||
profileId = UUID.fromString(profileMatch.groupValues[1])
|
profileId = UUID.fromString(profileMatch.groupValues[1])
|
||||||
hasReceivedProfile = true
|
hasReceivedProfile = true
|
||||||
@@ -61,6 +63,9 @@ object SBData {
|
|||||||
profileId = null
|
profileId = null
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
if (oldProfile != profileId) {
|
||||||
|
ProfileSwitchEvent.publish(ProfileSwitchEvent(oldProfile, profileId))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ private constructor(
|
|||||||
val HUB = forMode("hub")
|
val HUB = forMode("hub")
|
||||||
val PRIVATE_ISLAND = forMode("dynamic")
|
val PRIVATE_ISLAND = forMode("dynamic")
|
||||||
val RIFT = forMode("rift")
|
val RIFT = forMode("rift")
|
||||||
|
val MINESHAFT = forMode("mineshaft")
|
||||||
}
|
}
|
||||||
|
|
||||||
val userFriendlyName
|
val userFriendlyName
|
||||||
|
|||||||
Reference in New Issue
Block a user