aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-27 13:40:17 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-27 13:40:17 +0200
commited2ee24e8e3a0762fb2fc71a56b61cf4adb7a7e5 (patch)
treef13a78683f1b8d50d71e9cf68745392b8b989818 /src/main/java/at/hannibal2/skyhanni/features
parentfba63f009416c897aaddce36a27954cc0e54a878 (diff)
downloadskyhanni-ed2ee24e8e3a0762fb2fc71a56b61cf4adb7a7e5.tar.gz
skyhanni-ed2ee24e8e3a0762fb2fc71a56b61cf4adb7a7e5.tar.bz2
skyhanni-ed2ee24e8e3a0762fb2fc71a56b61cf4adb7a7e5.zip
Show the average crop milestone in the crop milestone inventory.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenCropMilestoneAverage.kt45
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt8
2 files changed, 50 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenCropMilestoneAverage.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenCropMilestoneAverage.kt
new file mode 100644
index 000000000..5faaac281
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenCropMilestoneAverage.kt
@@ -0,0 +1,45 @@
+package at.hannibal2.skyhanni.features.garden.inventory
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.GardenCropMilestones
+import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter
+import at.hannibal2.skyhanni.events.CropMilestoneUpdateEvent
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.RenderInventoryItemTipEvent
+import at.hannibal2.skyhanni.features.garden.CropType
+import at.hannibal2.skyhanni.utils.LorenzUtils.round
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class GardenCropMilestoneAverage {
+ private var average = -1.0
+
+ @SubscribeEvent
+ fun onCropMilestoneUpdate(event: CropMilestoneUpdateEvent) {
+ if (!SkyHanniMod.feature.garden.numberAverageCropMilestone) return
+
+ val tiers = mutableListOf<Double>()
+ for (cropType in CropType.values()) {
+ val counter = cropType.getCounter()
+ val tier = GardenCropMilestones.getTierForCrops(counter)
+ tiers.add(tier.toDouble())
+ }
+ average = tiers.average().round(2)
+ }
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ average = -1.0
+ }
+
+ @SubscribeEvent
+ fun onRenderItemTip(event: RenderInventoryItemTipEvent) {
+ if (average == -1.0) return
+
+ if (event.slot.slotNumber == 38) {
+ event.offsetY = -23
+ event.offsetX = -50
+ event.alignLeft = false
+ event.stackTip = "§6Average Crop Milestone: §e$average"
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt
index c2003186a..0bf7be4da 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt
@@ -11,6 +11,8 @@ import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class GardenInventoryNumbers {
+ private val config get() = SkyHanniMod.feature.garden
+
private var patternTierProgress = "§7Progress to Tier (.*): §e(?:.*)".toPattern()
private var patternUpgradeTier = "§7Current Tier: §[ea](.*)§7/§a.*".toPattern()
@@ -19,7 +21,7 @@ class GardenInventoryNumbers {
if (!GardenAPI.inGarden()) return
if (InventoryUtils.openInventoryName() == "Crop Milestones") {
- if (!SkyHanniMod.feature.garden.numberCropMilestone) return
+ if (!config.numberCropMilestone) return
event.stack.getLore()
.map { patternTierProgress.matcher(it) }
@@ -29,7 +31,7 @@ class GardenInventoryNumbers {
}
if (InventoryUtils.openInventoryName() == "Crop Upgrades") {
- if (!SkyHanniMod.feature.garden.numberCropUpgrades) return
+ if (!config.numberCropUpgrades) return
event.stack.getLore()
.map { patternUpgradeTier.matcher(it) }
@@ -39,7 +41,7 @@ class GardenInventoryNumbers {
}
if (InventoryUtils.openInventoryName() == "Composter Upgrades") {
- if (!SkyHanniMod.feature.garden.numberComposterUpgrades) return
+ if (!config.numberComposterUpgrades) return
event.stack.name?.let {
val matcher = ComposterUpgrade.regex.matcher(it)