aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBestCropTime.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/KingTalismanHelper.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt33
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangNextResetCooldown.kt20
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt80
9 files changed, 89 insertions, 100 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt
index 160619096..106b72679 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt
@@ -7,8 +7,9 @@ import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatIntOrUserError
-import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import net.minecraft.command.CommandBase
+import kotlin.time.Duration.Companion.seconds
object FarmingMilestoneCommand {
@@ -18,7 +19,7 @@ object FarmingMilestoneCommand {
return
}
- val enteredCrop = CropType.getByName(crop) ?: run {
+ val enteredCrop = CropType.getByNameOrNull(crop) ?: run {
ChatUtils.userError("Invalid crop type entered")
return
}
@@ -93,7 +94,7 @@ object FarmingMilestoneCommand {
private fun Long.formatOutput(needsTime: Boolean, crop: CropType): String {
if (!needsTime) return "${this.addSeparators()} §a${crop.cropName}"
val speed = crop.getSpeed() ?: -1
- val missingTimeSeconds = this / speed
- return "${TimeUtils.formatDuration(missingTimeSeconds * 1000)}§a"
+ val missingTime = (this / speed).seconds
+ return "${missingTime.format()}§a"
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt
index 6423e00ae..38c2353d9 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt
@@ -9,7 +9,8 @@ import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatLongOrUserError
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
-import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
+import kotlin.time.Duration.Companion.seconds
object GardenCropTimeCommand {
@@ -56,9 +57,9 @@ object GardenCropTimeCommand {
if (speed == null) {
map["$text §cNo speed data!"] = -1
} else {
- val missingTimeSeconds = fullAmount / speed
- val duration = TimeUtils.formatDuration(missingTimeSeconds * 1000)
- map["$text §b$duration"] = missingTimeSeconds
+ val missingTime = (fullAmount / speed).seconds
+ val duration = missingTime.format()
+ map["$text §b$duration"] = missingTime.inWholeSeconds
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
index 03c35ce27..2ee0e9bb9 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
@@ -29,7 +29,7 @@ import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils
-import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.json.BaseGsonBuilder
import at.hannibal2.skyhanni.utils.json.SkyHanniTypeAdapters
import at.hannibal2.skyhanni.utils.json.fromJson
@@ -306,8 +306,8 @@ object FarmingWeightDisplay {
}
val timeFormat = if (weightPerSecond != -1.0) {
- val timeTillOvertake = (weightUntilOvertake / weightPerSecond) * 1000
- val format = TimeUtils.formatDuration(timeTillOvertake.toLong())
+ val timeTillOvertake = (weightUntilOvertake / weightPerSecond).minutes
+ val format = timeTillOvertake.format()
" §7(§b$format§7)"
} else ""
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBestCropTime.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBestCropTime.kt
index 2412c7596..e8ca52ac8 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBestCropTime.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBestCropTime.kt
@@ -16,8 +16,9 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.CollectionUtils.sorted
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.TimeUnit
-import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.milliseconds
@SkyHanniModule
object GardenBestCropTime {
@@ -101,10 +102,10 @@ object GardenBestCropTime {
var number = 0
for (crop in sorted.keys) {
if (crop.isMaxed(useOverflow)) continue
- val millis = timeTillNextCrop[crop]!!
+ val millis = timeTillNextCrop[crop]?.milliseconds ?: continue
// TODO, change functionality to use enum rather than ordinals
val biggestUnit = TimeUnit.entries[config.highestTimeFormat.get().ordinal]
- val duration = TimeUtils.formatDuration(millis, biggestUnit, maxUnits = 2)
+ val duration = millis.format(biggestUnit, maxUnits = 2)
val isCurrent = crop == currentCrop
number++
if (number > config.next.showOnlyBest && (!config.next.showCurrent || !isCurrent)) continue
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
index f782b1b37..ba7651d03 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
@@ -33,7 +33,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.TimeUnit
-import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -199,12 +199,12 @@ object GardenCropMilestoneDisplay {
crop.setSpeed(farmingFortuneSpeed)
if (!crop.isMaxed(overflowDisplay) || overflowDisplay) {
val missing = need - have
- val missingTimeSeconds = missing / farmingFortuneSpeed
- val millis = missingTimeSeconds * 1000
+ val missingTime = (missing / farmingFortuneSpeed).seconds
+ val millis = missingTime.inWholeMilliseconds
GardenBestCropTime.timeTillNextCrop[crop] = millis
// TODO, change functionality to use enum rather than ordinals
val biggestUnit = TimeUnit.entries[config.highestTimeFormat.get().ordinal]
- val duration = TimeUtils.formatDuration(millis, biggestUnit)
+ val duration = missingTime.format(biggestUnit)
tryWarn(millis, "§b${crop.cropName} $nextTier in $duration")
val speedText = "§7In §b$duration"
@@ -328,11 +328,10 @@ object GardenCropMilestoneDisplay {
if (speed != 0.0) {
val blocksPerSecond = speed * (GardenAPI.getCurrentlyFarmedCrop()?.multiplier ?: 1)
- val missingTimeSeconds = missing / blocksPerSecond
- val millis = missingTimeSeconds * 1000
+ val missingTime = (missing / blocksPerSecond).seconds
// TODO, change functionality to use enum rather than ordinals
val biggestUnit = TimeUnit.entries[config.highestTimeFormat.get().ordinal]
- val duration = TimeUtils.formatDuration(millis.toLong(), biggestUnit)
+ val duration = missingTime.format(biggestUnit)
lineMap[MushroomTextEntry.TIME] = Renderable.string("§7In §b$duration")
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/KingTalismanHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/KingTalismanHelper.kt
index 14999c107..94b292fdf 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/mining/KingTalismanHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/KingTalismanHelper.kt
@@ -18,11 +18,12 @@ import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
import at.hannibal2.skyhanni.utils.SkyBlockTime
-import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.Collections
+import kotlin.time.Duration.Companion.milliseconds
@SkyHanniModule
object KingTalismanHelper {
@@ -91,7 +92,7 @@ object KingTalismanHelper {
private fun checkOffset() {
val king = EntityUtils.getEntitiesNearby<EntityArmorStand>(LorenzVec(129.6, 196.0, 196.7), 2.0)
- .filter { it.name.startsWith("§6§lKing ") }.firstOrNull() ?: return
+ .firstOrNull { it.name.startsWith("§6§lKing ") } ?: return
val foundKing = kingPattern.matchMatcher(king.name) {
group("name")
} ?: return
@@ -140,10 +141,11 @@ object KingTalismanHelper {
val current = king == currentKing
val missingTimeFormat = if (current) {
- val time = TimeUtils.formatDuration(timeUntil - 1000 * 60 * 20 * (kingCircles.size - 1))
+ val changedTime = timeUntil - 1000 * 60 * 20 * (kingCircles.size - 1)
+ val time = changedTime.milliseconds.format(maxUnits = 2)
"§7(§b$time remaining§7)"
} else {
- val time = TimeUtils.formatDuration(timeUntil, maxUnits = 2)
+ val time = timeUntil.milliseconds.format(maxUnits = 2)
"§7(§bin $time§7)"
}
@@ -164,7 +166,7 @@ object KingTalismanHelper {
val storage = storage ?: error("profileSpecific is null")
val kingsTalkedTo = storage.kingsTalkedTo
val (nextKing, until) = getKingTimes().filter { it.key !in kingsTalkedTo }.sorted().firstNotNullOf { it }
- val time = TimeUtils.formatDuration(until, maxUnits = 2)
+ val time = until.milliseconds.format(maxUnits = 2)
return "§cNext missing king: §7$nextKing §7(§bin $time§7)"
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt
index 42de82cd8..2ccaba2e5 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt
@@ -45,8 +45,9 @@ import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.drawString
import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SpecialColour
-import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.getLorenzVec
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import at.hannibal2.skyhanni.utils.toLorenzVec
@@ -90,6 +91,19 @@ object MinionFeatures {
"^§aCollect All$"
)
+ var lastMinion: LorenzVec? = null
+ private var lastStorage: LorenzVec? = null
+ var minionInventoryOpen = false
+ var minionStorageInventoryOpen = false
+
+ private var minions: Map<LorenzVec, ProfileSpecificStorage.MinionConfig>?
+ get() {
+ return ProfileStorageData.profileSpecific?.minions
+ }
+ set(value) {
+ ProfileStorageData.profileSpecific?.minions = value
+ }
+
@SubscribeEvent
fun onPlayerInteract(event: PlayerInteractEvent) {
if (!isEnabled()) return
@@ -361,8 +375,8 @@ object MinionFeatures {
}
if (config.emptiedTime.display && lastEmptied != 0L) {
- val duration = System.currentTimeMillis() - lastEmptied
- val format = TimeUtils.formatDuration(duration, longName = true) + " ago"
+ val passedSince = SimpleTimeMark(lastEmptied).passedSince()
+ val format = passedSince.format(longName = true) + " ago"
val text = "§eHopper Emptied: $format"
event.drawString(location.add(y = 1.15), text, true)
}
@@ -402,19 +416,6 @@ object MinionFeatures {
}
}
- var lastMinion: LorenzVec? = null
- var lastStorage: LorenzVec? = null
- var minionInventoryOpen = false
- var minionStorageInventoryOpen = false
-
- private var minions: Map<LorenzVec, ProfileSpecificStorage.MinionConfig>?
- get() {
- return ProfileStorageData.profileSpecific?.minions
- }
- set(value) {
- ProfileStorageData.profileSpecific?.minions = value
- }
-
@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(3, "minions.lastClickedMinionDisplay", "minions.lastClickedMinion.display")
diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangNextResetCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangNextResetCooldown.kt
index f4061033a..98b2d52a0 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangNextResetCooldown.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangNextResetCooldown.kt
@@ -11,16 +11,18 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.TimeUnit
-import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.seconds
@SkyHanniModule
object AshfangNextResetCooldown {
private val config get() = SkyHanniMod.feature.crimsonIsle.ashfang
- private var spawnTime = 1L
+ private var spawnTime = SimpleTimeMark.farPast()
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
@@ -29,30 +31,30 @@ object AshfangNextResetCooldown {
if (EntityUtils.getEntities<EntityArmorStand>().any {
it.posY > 145 && (it.name.contains("§c§9Ashfang Acolyte§r") || it.name.contains("§c§cAshfang Underling§r"))
}) {
- spawnTime = System.currentTimeMillis()
+ spawnTime = SimpleTimeMark.now()
}
}
@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
if (!isEnabled()) return
- if (spawnTime == -1L) return
+ if (spawnTime.isFarPast()) return
- val remainingTime = spawnTime + 46_100 - System.currentTimeMillis()
- if (remainingTime > 0) {
- val format = TimeUtils.formatDuration(remainingTime, TimeUnit.SECOND, showMilliSeconds = true)
+ val passedSince = spawnTime.passedSince()
+ if (passedSince < 46.1.seconds) {
+ val format = passedSince.format(TimeUnit.SECOND, showMilliSeconds = true)
config.nextResetCooldownPos.renderString(
"§cAshfang next reset in: §a$format",
posLabel = "Ashfang Reset Cooldown"
)
} else {
- spawnTime = -1
+ spawnTime = SimpleTimeMark.farPast()
}
}
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
- spawnTime = -1
+ spawnTime = SimpleTimeMark.farPast()
}
@SubscribeEvent
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
index 78213df56..43cd46906 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
@@ -19,66 +19,42 @@ object TimeUtils {
showMilliSeconds: Boolean = false,
longName: Boolean = false,
maxUnits: Int = -1,
- ): String = formatDuration(
- inWholeMilliseconds - 999, biggestUnit, showMilliSeconds, longName, maxUnits
- )
-
- fun Duration.timerColor(default: String = "§f") = when (this) {
- in 0.seconds..60.seconds -> "§c"
- in 60.seconds..3.minutes -> "§6"
- in 3.minutes..10.minutes -> "§e"
- else -> default
- }
-
- @Deprecated(
- "Has an offset of one second",
- ReplaceWith("millis.toDuration(DurationUnit.MILLISECONDS).format(biggestUnit, showMilliSeconds, longName, maxUnits)")
- )
- fun formatDuration(
- millis: Long,
- biggestUnit: TimeUnit = TimeUnit.YEAR,
- showMilliSeconds: Boolean = false,
- longName: Boolean = false,
- maxUnits: Int = -1,
): String {
- // TODO: if this weird offset gets removed, also remove that subtraction from formatDuration(kotlin.time.Duration)
- var milliseconds = millis + 999
- val map = mutableMapOf<TimeUnit, Int>()
+ var millis = inWholeMilliseconds
+ val parts = mutableMapOf<TimeUnit, Int>()
+
for (unit in TimeUnit.entries) {
if (unit.ordinal >= biggestUnit.ordinal) {
val factor = unit.factor
- map[unit] = (milliseconds / factor).toInt()
- milliseconds %= factor
+ parts[unit] = (millis / factor).toInt()
+ millis %= factor
}
}
- val builder = StringBuilder()
- var count = 0
- for ((unit, value) in map.entries) {
- if (value > 0 || builder.isNotEmpty() || unit == TimeUnit.SECOND) {
- builder.append(value.addSeparators())
- val name = if (longName) {
- " " + unit.longName + if (value > 1) "s" else ""
- } else {
- unit.shortName
- }
-
- if (unit == TimeUnit.SECOND) {
- if (showMilliSeconds) {
- val formatMillis = milliseconds / 100
- builder.append(".")
- builder.append(formatMillis)
+ var currentUnits = 0
+ val result = buildString {
+ for ((unit, value) in parts) {
+ if (value != 0) {
+ val formatted = unit.format(value, longName)
+ append(formatted)
+ if (unit == TimeUnit.SECOND && showMilliSeconds) {
+ val formattedMillis = (millis / 100).toInt()
+ append(".$formattedMillis")
}
- builder.append(name)
- } else {
- builder.append("$name ")
- }
- count++
- if (maxUnits != -1 && count == maxUnits) break
+ append(" ")
+ if (maxUnits != -1 && ++currentUnits == maxUnits) break
+ }
}
}
- return builder.toString().trim()
+ return result.trim()
+ }
+
+ fun Duration.timerColor(default: String = "§f") = when (this) {
+ in 0.seconds..60.seconds -> "§c"
+ in 60.seconds..3.minutes -> "§6"
+ in 3.minutes..10.minutes -> "§e"
+ else -> default
}
val Duration.inWholeTicks: Int
@@ -182,4 +158,10 @@ enum class TimeUnit(val factor: Long, val shortName: String, val longName: Strin
MINUTE(FACTOR_MINUTES, "m", "Minute"),
SECOND(FACTOR_SECONDS, "s", "Second"),
;
+
+ fun format(value: Int, longFormat: Boolean = false) = if (longFormat) {
+ "${value.addSeparators()} $longName" + if (value > 1) "s" else ""
+ } else {
+ "${value.addSeparators()}$shortName"
+ }
}