aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-28 20:33:35 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-28 20:33:35 +0200
commit703b97a2b49cd68eef036e6965ca78547d460d93 (patch)
treef02385e346838e8775d9f6a8a0ce90cc7fac30d9 /src/main/java/at/hannibal2/skyhanni/data
parent279127f1e23d66ed7e9b2bf63c81b1100f09c0ff (diff)
downloadskyhanni-703b97a2b49cd68eef036e6965ca78547d460d93.tar.gz
skyhanni-703b97a2b49cd68eef036e6965ca78547d460d93.tar.bz2
skyhanni-703b97a2b49cd68eef036e6965ca78547d460d93.zip
Added Total Crop Milestone
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
index da2caac0c..277fdb56c 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
@@ -8,26 +8,33 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.jsonobjects.GardenJson
+import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object GardenCropMilestones {
private val cropPattern = "§7Harvest §f(?<name>.*) §7on .*".toPattern()
private val totalPattern = "§7Total: §a(?<name>.*)".toPattern()
+ fun getCropTypeByLore(itemStack: ItemStack): CropType? {
+ for (line in itemStack.getLore()) {
+ cropPattern.matchMatcher(line) {
+ val name = group("name")
+ return CropType.getByNameOrNull(name)
+ }
+ }
+ return null
+ }
+
@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (event.inventoryName != "Crop Milestones") return
for ((_, stack) in event.inventoryItems) {
- var crop: CropType? = null
+ val crop = getCropTypeByLore(stack) ?: continue
for (line in stack.getLore()) {
- cropPattern.matchMatcher(line) {
- val name = group("name")
- crop = CropType.getByNameOrNull(name)
- }
totalPattern.matchMatcher(line) {
val amount = group("name").replace(",", "").toLong()
- crop?.setCounter(amount)
+ crop.setCounter(amount)
}
}
}
@@ -65,6 +72,8 @@ object GardenCropMilestones {
return tier
}
+ fun getMaxTier() = cropMilestoneData?.values?.firstOrNull()?.size ?: 0
+
fun getCropsForTier(requestedTier: Int, crop: CropType): Long {
var totalCrops = 0L
var tier = 0