aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-01-20 20:01:45 +1100
committerGitHub <noreply@github.com>2024-01-20 10:01:45 +0100
commitcae50abbda2f5e2e53e81231b9f3a01215b0871e (patch)
treec14bbbc254044234ff839ce70ff4a7c630ce3a03 /src/main/java/at/hannibal2/skyhanni
parentba50ceb84f6992a4150b0f3afd6aad163dc2137f (diff)
downloadskyhanni-cae50abbda2f5e2e53e81231b9f3a01215b0871e.tar.gz
skyhanni-cae50abbda2f5e2e53e81231b9f3a01215b0871e.tar.bz2
skyhanni-cae50abbda2f5e2e53e81231b9f3a01215b0871e.zip
add crop milestone commands (#869)
Added /shcalccrop and /shcalccroptime #869
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt47
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt72
3 files changed, 108 insertions, 18 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 bb05b8aee..d6f3d2fbd 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -24,6 +24,7 @@ import at.hannibal2.skyhanni.features.fame.AccountUpgradeReminder
import at.hannibal2.skyhanni.features.fame.CityProjectFeatures
import at.hannibal2.skyhanni.features.fishing.tracker.FishingProfitTracker
import at.hannibal2.skyhanni.features.fishing.tracker.SeaCreatureTracker
+import at.hannibal2.skyhanni.features.garden.FarmingMilestoneCommand
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.features.garden.GardenCropTimeCommand
import at.hannibal2.skyhanni.features.garden.GardenCropsInCommand
@@ -230,6 +231,12 @@ object Commands {
"shresetseacreaturetracker",
"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), 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)
}
private fun usersBugFix() {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt
index 05abfe744..3a7226cc4 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt
@@ -12,28 +12,39 @@ enum class CropType(
val specialDropType: String,
val baseDrops: Double,
iconSupplier: () -> ItemStack,
+ val simpleName: String,
val replenish: Boolean = false,
) {
- WHEAT("Wheat", "THEORETICAL_HOE_WHEAT", "CROPIE", 1.0, { ItemStack(Items.wheat) }),
- CARROT("Carrot", "THEORETICAL_HOE_CARROT", "CROPIE", 3.0, { ItemStack(Items.carrot) }, replenish = true),
- POTATO("Potato", "THEORETICAL_HOE_POTATO", "CROPIE", 3.0, { ItemStack(Items.potato) }, replenish = true),
- NETHER_WART(
- "Nether Wart",
- "THEORETICAL_HOE_WARTS",
- "FERMENTO",
- 2.5,
- { ItemStack(Items.nether_wart) },
- replenish = true
+ WHEAT("Wheat", "THEORETICAL_HOE_WHEAT", "CROPIE", 1.0,
+ { ItemStack(Items.wheat) }, "wheat"
),
- PUMPKIN("Pumpkin", "PUMPKIN_DICER", "SQUASH", 1.0, { ItemStack(Blocks.pumpkin) }),
- MELON("Melon", "MELON_DICER", "SQUASH", 5.0, { ItemStack(Items.melon) }),
- COCOA_BEANS(
- "Cocoa Beans", "COCO_CHOPPER", "SQUASH",
- 3.0, { ItemStack(Items.dye, 1, EnumDyeColor.BROWN.dyeDamage) }, replenish = true
+ CARROT("Carrot", "THEORETICAL_HOE_CARROT", "CROPIE", 3.0,
+ { ItemStack(Items.carrot) }, "carrot", replenish = true
+ ),
+ POTATO("Potato", "THEORETICAL_HOE_POTATO", "CROPIE", 3.0,
+ { ItemStack(Items.potato) }, "potato", replenish = true
+ ),
+ NETHER_WART("Nether Wart", "THEORETICAL_HOE_WARTS", "FERMENTO", 2.5,
+ { ItemStack(Items.nether_wart) }, "wart", replenish = true
+ ),
+ PUMPKIN("Pumpkin", "PUMPKIN_DICER", "SQUASH", 1.0,
+ { ItemStack(Blocks.pumpkin) }, "pumpkin"
+ ),
+ MELON("Melon", "MELON_DICER", "SQUASH", 5.0,
+ { ItemStack(Items.melon) }, "melon"
+ ),
+ COCOA_BEANS("Cocoa Beans", "COCO_CHOPPER", "SQUASH", 3.0,
+ { ItemStack(Items.dye, 1, EnumDyeColor.BROWN.dyeDamage) }, "cocoa", replenish = true
+ ),
+ SUGAR_CANE("Sugar Cane", "THEORETICAL_HOE_CANE", "FERMENTO", 2.0,
+ { ItemStack(Items.reeds) }, "cane"
+ ),
+ CACTUS("Cactus", "CACTUS_KNIFE", "FERMENTO", 2.0,
+ { ItemStack(Blocks.cactus) }, "cactus"
+ ),
+ MUSHROOM("Mushroom", "FUNGI_CUTTER", "FERMENTO", 1.0,
+ { ItemStack(Blocks.red_mushroom_block) }, "mushroom"
),
- SUGAR_CANE("Sugar Cane", "THEORETICAL_HOE_CANE", "FERMENTO", 2.0, { ItemStack(Items.reeds) }),
- CACTUS("Cactus", "CACTUS_KNIFE", "FERMENTO", 2.0, { ItemStack(Blocks.cactus) }),
- MUSHROOM("Mushroom", "FUNGI_CUTTER", "FERMENTO", 1.0, { ItemStack(Blocks.red_mushroom_block) }),
;
val icon by lazy { iconSupplier() }
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt
new file mode 100644
index 000000000..cdfae78e8
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt
@@ -0,0 +1,72 @@
+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?, needsTime: Boolean) {
+ if (crop == null) {
+ LorenzUtils.userError("No crop type entered")
+ return
+ }
+
+ val enteredCrop = CropType.entries.firstOrNull { it.simpleName == crop.lowercase() } ?: run {
+ LorenzUtils.userError("Invalid crop type entered")
+ return
+ }
+
+ val currentMilestone = getValidNumber(current)
+ val targetMilestone = getValidNumber(target)
+
+ if (currentMilestone == null) {
+ val currentProgress = enteredCrop.getCounter()
+ val currentCropMilestone = GardenCropMilestones.getTierForCropCount(currentProgress, enteredCrop) + 1
+ val output = (GardenCropMilestones.getCropsForTier(currentCropMilestone, enteredCrop) - currentProgress).formatOutput(needsTime, enteredCrop)
+
+ LorenzUtils.chat("§7$output needed to reach the next milestone")
+ return
+ }
+
+ if (targetMilestone == null) {
+ val output = GardenCropMilestones.getCropsForTier(currentMilestone, enteredCrop).formatOutput(needsTime, enteredCrop)
+
+ LorenzUtils.chat("§7$output needed for milestone §7$currentMilestone")
+ return
+ }
+ if (currentMilestone >= targetMilestone) {
+ LorenzUtils.userError("Entered milestone is greater than or the same as target milestone")
+ return
+ }
+
+ val currentAmount = GardenCropMilestones.getCropsForTier(currentMilestone, enteredCrop)
+ val targetAmount = GardenCropMilestones.getCropsForTier(targetMilestone, enteredCrop)
+ val output = (targetAmount - currentAmount).formatOutput(needsTime, enteredCrop)
+
+ LorenzUtils.chat("§7$output needed for milestone §7$currentMilestone §a-> §7$targetMilestone")
+ }
+
+ fun onComplete(strings: Array<String>): List<String> {
+ return if (strings.size <= 1) {
+ CommandBase.getListOfStringsMatchingLastWord(
+ strings,
+ CropType.entries.map { it.simpleName }
+ )
+ }
+ else listOf()
+ }
+
+ private fun getValidNumber(entry: String?) = entry?.toIntOrNull()?.coerceIn(0, 46)
+
+ 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"
+ }
+}