diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt | 25 |
1 files changed, 14 insertions, 11 deletions
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 c9868d4e3..c7817066e 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,6 +14,7 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_old import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy import com.google.gson.JsonObject import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.concurrent.fixedRateTimer @@ -28,7 +29,7 @@ object GardenCropSpeed { var averageBlocksPerSecond = 0.0 - private val blocksSpeedList = mutableListOf<Int>() + private var blocksSpeedList = listOf<Int>() private var blocksBroken = 0 private var secondsStopped = 0 @@ -81,20 +82,22 @@ object GardenCropSpeed { this.blocksBroken = 0 if (blocksBroken == 0) { - if (blocksSpeedList.size == 0) return + if (blocksSpeedList.isEmpty()) return secondsStopped++ } else { if (secondsStopped >= config.blocksBrokenResetTime) { resetSpeed() } - while (secondsStopped > 0) { - blocksSpeedList.add(0) - secondsStopped -= 1 - } - blocksSpeedList.add(blocksBroken) - if (blocksSpeedList.size == 2) { - blocksSpeedList.removeFirst() - blocksSpeedList.add(blocksBroken) + blocksSpeedList = blocksSpeedList.editCopy { + while (secondsStopped > 0) { + this.add(0) + secondsStopped -= 1 + } + this.add(blocksBroken) + if (this.size == 2) { + this.removeFirst() + this.add(blocksBroken) + } } averageBlocksPerSecond = if (blocksSpeedList.size > 1) { blocksSpeedList.dropLast(1).average() @@ -170,7 +173,7 @@ object GardenCropSpeed { private fun resetSpeed() { averageBlocksPerSecond = 0.0 - blocksSpeedList.clear() + blocksSpeedList = emptyList() secondsStopped = 0 } |