aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt73
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt11
6 files changed, 90 insertions, 19 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 4c3bdc573..e1a4533e7 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.data.GuiEditManager
import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay
import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper
import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper
+import at.hannibal2.skyhanni.features.garden.GardenCropTimeCommand
import at.hannibal2.skyhanni.features.garden.farming.CropSpeedMeter
import at.hannibal2.skyhanni.features.misc.CollectionCounter
import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager
@@ -55,6 +56,7 @@ object Commands {
registerCommand("shtestgardenvisitors") { LorenzTest.testGardenVisitors() }
registerCommand("shtogglehypixelapierrors") { APIUtil.toggleApiErrorMessages() }
registerCommand("shcropspeedmeter") { CropSpeedMeter.toggle() }
+ registerCommand("shcroptime") { GardenCropTimeCommand.onCommand(it) }
}
private fun registerCommand(name: String, function: (Array<String>) -> Unit) {
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt
index 07b796b33..e5ece4acc 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.CropUpgradeUpdateEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.garden.CropType
+import at.hannibal2.skyhanni.features.garden.CropType.Companion.getByNameOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
@@ -17,7 +18,7 @@ class GardenCropUpgrades {
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
chatUpgradePattern.matchEntire(event.message)?.groups?.let { matches ->
- val crop = CropType.getByItemName(matches[1]!!.value) ?: return
+ val crop = getByNameOrNull(matches[1]!!.value) ?: return
val level = matches[2]!!.value.toInt()
crop.setUpgradeLevel(level)
}
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 df86b08d1..ed6138082 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt
@@ -33,18 +33,14 @@ enum class CropType(
val multiplier by lazy { if (this == SUGAR_CANE || this == CACTUS) 2 else 1 }
companion object {
- fun getByNameOrNull(cropName: String) = values().firstOrNull { it.cropName == cropName }
-
- fun getByName(name: String) = getByNameOrNull(name) ?: throw RuntimeException("No valid crop type '$name'")
-
-
- fun getByItemName(itemName: String): CropType? {
+ fun getByNameOrNull(itemName: String): CropType? {
if (itemName == "Red Mushroom" || itemName == "Brown Mushroom") return MUSHROOM
if (itemName == "Seeds") return WHEAT
-
- return getByNameOrNull(itemName)
+ return values().firstOrNull { it.cropName == itemName }
}
+ fun getByName(name: String) = getByNameOrNull(name) ?: throw RuntimeException("No valid crop type '$name'")
+
fun IBlockState.getCropType(): CropType? {
return when (block) {
Blocks.wheat -> WHEAT
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt
new file mode 100644
index 000000000..a598b6000
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt
@@ -0,0 +1,73 @@
+package at.hannibal2.skyhanni.features.garden
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.features.garden.GardenAPI.getSpeed
+import at.hannibal2.skyhanni.features.garden.farming.CropMoneyDisplay
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils.sorted
+import at.hannibal2.skyhanni.utils.NEUItems
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import at.hannibal2.skyhanni.utils.TimeUtils
+
+object GardenCropTimeCommand {
+ private val config get() = SkyHanniMod.feature.garden
+
+ fun onCommand(args: Array<String>) {
+ if (!config.moneyPerHourDisplay) {
+ LorenzUtils.chat("§c[SkyHanni] §cshcroptime requires 'Show money per Hour' feature to be enabled to work!")
+ return
+ }
+
+ if (args.size < 2) {
+ LorenzUtils.chat("§cUsage: /shcroptime <amount> <item>")
+ return
+ }
+
+ val rawAmount = args[0]
+ val amount = try {
+ rawAmount.toInt()
+ } catch (e: NumberFormatException) {
+ LorenzUtils.chat("§cNot a valid number: '$rawAmount'")
+ return
+ }
+
+ val rawSearchName = args.toMutableList().drop(1).joinToString(" ")
+ val searchName = rawSearchName.lowercase()
+
+ val map = mutableMapOf<String, Long>()
+ for (entry in CropMoneyDisplay.multipliers) {
+ val internalName = entry.key
+ val itemName = NEUItems.getItemStack(internalName).name!!
+ if (itemName.removeColor().lowercase().contains(searchName)) {
+ val (baseId, baseAmount) = NEUItems.getMultiplier(internalName)
+ val baseName = NEUItems.getItemStack(baseId).name!!
+ val crop = CropType.getByName(baseName.removeColor())
+ val speed = crop.getSpeed()
+
+ val fullAmount = baseAmount.toLong() * amount.toLong()
+ val text = if (baseAmount == 1) {
+ "§e${amount.addSeparators()}x $itemName"
+ } else {
+ "§e${amount.addSeparators()}x $itemName §7(§e${fullAmount.addSeparators()}x $baseName§7)"
+ }
+
+ if (speed == -1) {
+ map["$text §cNo speed data!"] = -1
+ } else {
+ val missingTimeSeconds = fullAmount / speed
+ val duration = TimeUtils.formatDuration(missingTimeSeconds * 1000)
+ map["$text §b$duration"] = missingTimeSeconds
+ }
+ }
+ }
+
+ if (map.isEmpty()) {
+ LorenzUtils.chat("§c[SkyHanni] §cNo crop item found for '$rawSearchName'")
+ return
+ }
+
+ LorenzUtils.chat("§e[SkyHanni] Crop Speed for ${map.size} items:\n" + map.sorted().keys.joinToString("\n"))
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt
index 599cd8ccb..1181170d0 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt
@@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.features.bazaar.BazaarApi
import at.hannibal2.skyhanni.features.bazaar.BazaarData
import at.hannibal2.skyhanni.features.garden.CropType
+import at.hannibal2.skyhanni.features.garden.CropType.Companion.getByNameOrNull
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.features.garden.GardenAPI.getSpeed
import at.hannibal2.skyhanni.features.garden.GardenNextJacobContest
@@ -25,12 +26,15 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
class CropMoneyDisplay {
+ companion object {
+ var multipliers = mapOf<String, Int>()
+ }
+
private var display = mutableListOf<List<Any>>()
private val config get() = SkyHanniMod.feature.garden
private var tick = 0
private var loaded = false
private var ready = false
- private var multipliers = mapOf<String, Int>()
private val cropNames = mutableMapOf<String, CropType>() // internalName -> cropName
private var hasCropInHand = false
private val toolHasBountiful: MutableMap<CropType, Boolean> get() = SkyHanniMod.feature.hidden.gardenToolHasBountiful
@@ -304,7 +308,7 @@ class CropMoneyDisplay {
val (newId, amount) = NEUItems.getMultiplier(internalName)
val itemName = NEUItems.getItemStack(newId).name?.removeColor() ?: continue
- val crop = CropType.getByItemName(itemName)
+ val crop = getByNameOrNull(itemName)
crop?.let {
map[internalName] = amount
cropNames[internalName] = it
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
index 1bababdb1..33c4b0e5a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
@@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.TitleUtils
import at.hannibal2.skyhanni.events.*
-import at.hannibal2.skyhanni.features.garden.CropType
+import at.hannibal2.skyhanni.features.garden.CropType.Companion.getByNameOrNull
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.features.garden.GardenAPI.getSpeed
import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper
@@ -313,7 +313,7 @@ class GardenVisitorFeatures {
if (config.visitorExactAmountAndTime) {
val multiplier = NEUItems.getMultiplier(internalName)
val rawName = NEUItems.getItemStack(multiplier.first).name?.removeColor() ?: continue
- CropType.getByItemName(rawName)?.let {
+ getByNameOrNull(rawName)?.let {
val speed = it.getSpeed()
val cropAmount = multiplier.second.toLong() * amount
val formatAmount = LorenzUtils.formatInteger(cropAmount)
@@ -481,12 +481,7 @@ class GardenVisitorFeatures {
if (name == "Spaceman") return false
if (name == "Beth") return false
- if (visitors.keys.any { it.removeColor() == name }) {
- println("blocked msg from '$name'")
- return true
- }
-
- return false
+ return visitors.keys.any { it.removeColor() == name }
}
private fun update() {