diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2023-05-01 01:02:41 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-30 17:02:41 +0200 |
commit | eb24e00ab9bd16c7884fb23795ba9c7feaf85fe4 (patch) | |
tree | 3e1788263abe6f1a4d38af69f427a46ccada1c08 /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | 7597b8ccc1f863f38383aadd898adfaccdcb3349 (diff) | |
download | skyhanni-eb24e00ab9bd16c7884fb23795ba9c7feaf85fe4.tar.gz skyhanni-eb24e00ab9bd16c7884fb23795ba9c7feaf85fe4.tar.bz2 skyhanni-eb24e00ab9bd16c7884fb23795ba9c7feaf85fe4.zip |
Reworked the blocks/second feature (#81)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt | 2 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt | 28 |
2 files changed, 16 insertions, 14 deletions
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 688d08b19..b443acb93 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 @@ -186,7 +186,7 @@ object GardenCropMilestoneDisplay { val format = LorenzUtils.formatInteger(farmingFortuneSpeed * 60) lineMap[4] = Collections.singletonList("§7Crops/Minute§8: §e$format") - val formatBps = LorenzUtils.formatDouble(speed, 2) + val formatBps = LorenzUtils.formatDouble(speed, config.blocksBrokenPrecision) lineMap[5] = Collections.singletonList("§7Blocks/Second§8: §e$formatBps") } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt index 9cf1d20e5..0124d75ca 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt @@ -14,7 +14,6 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.concurrent.fixedRateTimer -import kotlin.math.abs object GardenCropSpeed { private val config get() = SkyHanniMod.feature.garden @@ -27,7 +26,7 @@ object GardenCropSpeed { private val blocksSpeedList = mutableListOf<Int>() private var blocksBroken = 0 - private var lastBlocksBroken = 0 + private var secondsStopped = 0 init { @@ -67,30 +66,33 @@ object GardenCropSpeed { val blocksBroken = blocksBroken.coerceAtMost(20) this.blocksBroken = 0 - // If the difference in speed between the current and the previous bps value is too high, disregard this value - if (abs(lastBlocksBroken - blocksBroken) > 4) { - if (blocksSpeedList.isNotEmpty()) { - blocksSpeedList.removeLast() + if (blocksBroken == 0) { + if (blocksSpeedList.size == 0) return + secondsStopped ++ + } else { + if (secondsStopped >= config.blocksBrokenResetTime) { + resetSpeed() + } + while (secondsStopped > 0) { + blocksSpeedList.add(0) + secondsStopped -= 1 } - } else if (blocksBroken >= 2) { blocksSpeedList.add(blocksBroken) - while (blocksSpeedList.size > 120) { + if (blocksSpeedList.size == 2) { blocksSpeedList.removeFirst() + blocksSpeedList.add(blocksBroken) } - averageBlocksPerSecond = blocksSpeedList.average() + averageBlocksPerSecond = blocksSpeedList.dropLast(1).average() GardenAPI.getCurrentlyFarmedCrop()?.let { latestBlocksPerSecond[it] = averageBlocksPerSecond } - - } - lastBlocksBroken = blocksBroken } private fun resetSpeed() { averageBlocksPerSecond = 0.0 - blocksBroken = 0 blocksSpeedList.clear() + secondsStopped = 0 } fun finneganPerkActive(): Boolean { |