From e47a6c38ffd6f6238f828a5663a665c7d2b4f11d Mon Sep 17 00:00:00 2001 From: calmwolfs Date: Tue, 2 Jan 2024 09:14:18 -0500 Subject: [PATCH] reformat and add /shcalccroptime command --- .../skyhanni/config/commands/Commands.kt | 5 +++- .../garden/FarmingMilestoneCommand.kt | 23 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 99f92a19e574..e322bb01995e 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -225,7 +225,10 @@ object Commands { "Resets the Sea Creature Tracker" ) { SeaCreatureTracker.resetCommand(it) } registerCommand0("shcalccrop", "Calculate how many crops need to be farmed between different crop milestones.", { - FarmingMilestoneCommand.onCommand(it.getOrNull(0), it.getOrNull(1), it.getOrNull(2)) + FarmingMilestoneCommand.onCommand(it.getOrNull(0), it.getOrNull(1), it.getOrNull(2), false) + }, FarmingMilestoneCommand::onComplete) + registerCommand0("shcalccroptime", "Calculate how long you need to farm crops between different crop milestones.", { + FarmingMilestoneCommand.onCommand(it.getOrNull(0), it.getOrNull(1), it.getOrNull(2), true) }, FarmingMilestoneCommand::onComplete) } 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 130279e7b7e5..3be4e0f7d778 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt @@ -2,13 +2,15 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.data.GardenCropMilestones import at.hannibal2.skyhanni.data.GardenCropMilestones.getCounter +import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraft.command.CommandBase object FarmingMilestoneCommand { - fun onCommand(crop: String?, current: String?, target: String?) { + fun onCommand(crop: String?, current: String?, target: String?, needsTime: Boolean) { if (crop == null) { LorenzUtils.chat("No crop type entered") return @@ -25,16 +27,16 @@ object FarmingMilestoneCommand { if (currentMilestone == null) { val currentProgress = enteredCrop.getCounter() val currentCropMilestone = GardenCropMilestones.getTierForCropCount(currentProgress, enteredCrop) + 1 - val cropsNeeded = GardenCropMilestones.getCropsForTier(currentCropMilestone, enteredCrop) - currentProgress + val output = (GardenCropMilestones.getCropsForTier(currentCropMilestone, enteredCrop) - currentProgress).formatOutput(needsTime, enteredCrop) - LorenzUtils.chat("§a${enteredCrop.cropName} needed for you to reach the next milestone ($currentCropMilestone) is ${cropsNeeded.addSeparators()}") + LorenzUtils.chat("§7$output needed for you to reach the next milestone") return } if (targetMilestone == null) { - val cropsNeeded = GardenCropMilestones.getCropsForTier(currentMilestone, enteredCrop) + val output = GardenCropMilestones.getCropsForTier(currentMilestone, enteredCrop).formatOutput(needsTime, enteredCrop) - LorenzUtils.chat("§a${enteredCrop.cropName} needed to reach milestone $currentMilestone is ${cropsNeeded.addSeparators()}") + LorenzUtils.chat("§7$output needed for milestone §7$currentMilestone") return } if (currentMilestone >= targetMilestone) { @@ -44,9 +46,9 @@ object FarmingMilestoneCommand { val currentAmount = GardenCropMilestones.getCropsForTier(currentMilestone, enteredCrop) val targetAmount = GardenCropMilestones.getCropsForTier(targetMilestone, enteredCrop) - val cropsNeeded = targetAmount - currentAmount + val output = (targetAmount - currentAmount).formatOutput(needsTime, enteredCrop) - LorenzUtils.chat("§a${enteredCrop.cropName} needed to reach milestone $targetMilestone from milestone $currentMilestone is ${cropsNeeded.addSeparators()}") + LorenzUtils.chat("§7$output needed for milestone §7$currentMilestone §a-> §7$targetMilestone") } fun onComplete(strings: Array): List { @@ -72,4 +74,11 @@ object FarmingMilestoneCommand { return result } + + 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" + } }