aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-19 23:44:52 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-19 23:44:52 +0200
commit50dfb62bad66e9bdb04cca17a2dd32a69b108265 (patch)
tree6eddedf8783ba63d9a21e45adfa70c043470d0d3 /src/main/java/at/hannibal2/skyhanni
parentee84a09894c450c35ac619cd3870b3887059985d (diff)
downloadskyhanni-50dfb62bad66e9bdb04cca17a2dd32a69b108265.tar.gz
skyhanni-50dfb62bad66e9bdb04cca17a2dd32a69b108265.tar.bz2
skyhanni-50dfb62bad66e9bdb04cca17a2dd32a69b108265.zip
Reading tab list to load or fix crop milestone data
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt68
2 files changed, 69 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index 76633751e..056a6f9e7 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -271,6 +271,7 @@ public class SkyHanniMod {
loadModule(new AshfangMinisNametagHider());
loadModule(new GardenTeleportPadInventoryNumber());
loadModule(new ComposterOverlay());
+ loadModule(new GardenCropMilestoneFix());
Commands.INSTANCE.init();
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt
new file mode 100644
index 000000000..33a605379
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt
@@ -0,0 +1,68 @@
+package at.hannibal2.skyhanni.features.garden
+
+import at.hannibal2.skyhanni.data.GardenCropMilestones
+import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter
+import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.setCounter
+import at.hannibal2.skyhanni.events.TabListUpdateEvent
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class GardenCropMilestoneFix {
+ private val pattern = " Milestone: §r§a(?<crop>.*) (?<tier>.*): §r§3(?<percentage>.*)%".toPattern()
+
+ private val tabListCropProgress = mutableMapOf<CropType, Long>()
+
+ @SubscribeEvent
+ fun onTabListUpdate(event: TabListUpdateEvent) {
+ for (line in event.tabList) {
+ val matcher = pattern.matcher(line)
+ if (!matcher.matches()) continue
+
+ val tier = matcher.group("tier").toInt()
+ val percentage = matcher.group("percentage").toDouble()
+
+ check(matcher.group("crop"), tier, percentage)
+ return
+ }
+ }
+
+ private fun check(cropName: String, tier: Int, percentage: Double) {
+ val baseCrops = GardenCropMilestones.getCropsForTier(tier)
+ val next = GardenCropMilestones.getCropsForTier(tier + 1)
+ val progressCrops = next - baseCrops
+
+ val progress = progressCrops * (percentage / 100)
+ val smallestPercentage = progressCrops * 0.0005
+
+ val crop = CropType.getByName(cropName)
+ if (crop == null) {
+ LorenzUtils.debug("GardenCropMilestoneFix: crop is null: '$cropName'")
+ return
+ }
+
+ val tabListValue = baseCrops + progress - smallestPercentage
+
+ val long = tabListValue.toLong()
+
+ if (tabListCropProgress[crop] == long) return
+ if (tabListCropProgress.containsKey(crop)) {
+ changedValue(crop, long)
+ }
+
+ tabListCropProgress[crop] = long
+ }
+
+ private fun changedValue(crop: CropType, tabListValue: Long) {
+ val calculated = crop.getCounter()
+ val diff = calculated - tabListValue
+ if (diff < -5_000) {
+ crop.setCounter(tabListValue)
+ LorenzUtils.chat("§e[SkyHanni] Loaded ${crop.cropName} milestone data from tab list!")
+ }
+ if (diff > 5_000) {
+ LorenzUtils.debug("Fixed wrong ${crop.cropName} milestone data from tab list: ${diff.addSeparators()}")
+ crop.setCounter(tabListValue)
+ }
+ }
+} \ No newline at end of file