Skip to content

Commit

Permalink
add crop milestone commands
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs committed Jan 1, 2024
1 parent b358279 commit 25a9876
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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.GardenNextJacobContest
Expand Down Expand Up @@ -223,6 +224,9 @@ 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))
}, FarmingMilestoneCommand::onComplete)
}

private fun usersBugFix() {
Expand Down
47 changes: 29 additions & 18 deletions src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package at.hannibal2.skyhanni.features.garden

import at.hannibal2.skyhanni.data.GardenCropMilestones
import at.hannibal2.skyhanni.data.GardenCropMilestones.getCounter
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import net.minecraft.command.CommandBase

object FarmingMilestoneCommand {

fun onCommand(crop: String?, current: String?, target: String?) {
if (crop == null) {
LorenzUtils.chat("No crop type entered")
return
}

val enteredCrop = CropType.entries.firstOrNull { it.simpleName == crop.lowercase() } ?: run {
LorenzUtils.chat("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 cropsNeeded = GardenCropMilestones.getCropsForTier(currentCropMilestone, enteredCrop) - currentProgress

LorenzUtils.chat("§a${enteredCrop.cropName} needed for you to reach the next milestone ($currentCropMilestone) is ${cropsNeeded.addSeparators()}")
return
}

if (targetMilestone == null) {
val cropsNeeded = GardenCropMilestones.getCropsForTier(currentMilestone, enteredCrop)

LorenzUtils.chat("§a${enteredCrop.cropName} needed to reach milestone $currentMilestone is ${cropsNeeded.addSeparators()}")
return
}
if (currentMilestone >= targetMilestone) {
LorenzUtils.chat("Entered milestone is greater than target milestone")
return
}

val currentAmount = GardenCropMilestones.getCropsForTier(currentMilestone, enteredCrop)
val targetAmount = GardenCropMilestones.getCropsForTier(targetMilestone, enteredCrop)
val cropsNeeded = targetAmount - currentAmount

LorenzUtils.chat("§a${enteredCrop.cropName} needed to reach milestone $targetMilestone from milestone $currentMilestone is ${cropsNeeded.addSeparators()}")
}

fun onComplete(strings: Array<String>): List<String> {
if (strings.size <= 1)
return CommandBase.getListOfStringsMatchingLastWord(
strings,
CropType.entries.map { it.simpleName }
)
return listOf()
}

private fun getValidNumber(entry: String?): Int? {
if (entry == null) return null
var result = try {
entry.toInt()
} catch (_: Exception) {
null
}
if (result == null) return null

if (result < 0) result = 0
if (result > 46) result = 46

return result
}
}

0 comments on commit 25a9876

Please sign in to comment.