diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-08-28 20:33:35 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-08-28 20:33:35 +0200 |
commit | 703b97a2b49cd68eef036e6965ca78547d460d93 (patch) | |
tree | f02385e346838e8775d9f6a8a0ce90cc7fac30d9 | |
parent | 279127f1e23d66ed7e9b2bf63c81b1100f09c0ff (diff) | |
download | skyhanni-703b97a2b49cd68eef036e6965ca78547d460d93.tar.gz skyhanni-703b97a2b49cd68eef036e6965ca78547d460d93.tar.bz2 skyhanni-703b97a2b49cd68eef036e6965ca78547d460d93.zip |
Added Total Crop Milestone
5 files changed, 102 insertions, 52 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 752d5a413..e428782df 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -163,7 +163,7 @@ class SkyHanniMod { loadModule(MayorElection()) loadModule(GardenComposterUpgradesData()) loadModule(ActionBarStatsData) - loadModule(GardenCropMilestoneAverage()) + loadModule(GardenCropMilestoneInventory()) loadModule(GardenCropSpeed) loadModule(ProfileStorageData) loadModule(TitleData()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java index 6285d1e44..0cc4c3f89 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java @@ -1222,6 +1222,15 @@ public class GardenConfig { public int cropTooltipFortune = 1; @Expose + @ConfigOption( + name = "Total Crop Milestone", + desc = "Shows the progress bar till maxed crop milestone in the crop milestone inventory." + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 20) + public boolean cropMilestoneTotalProgress = true; + + @Expose @ConfigOption(name = "Yaw and Pitch", desc = "") @Accordion public YawPitchDisplay yawPitchDisplay = new YawPitchDisplay(); 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 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 deleted file mode 100644 index 47589d66c..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenCropMilestoneAverage.kt +++ /dev/null @@ -1,45 +0,0 @@ -package at.hannibal2.skyhanni.features.garden.inventory - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.GardenCropMilestones -import at.hannibal2.skyhanni.data.GardenCropMilestones.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.entries) { - val counter = cropType.getCounter() - val tier = GardenCropMilestones.getTierForCropCount(counter, cropType) - tiers.add(tier.toDouble()) - } - average = (tiers.sum() / CropType.entries.size).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/GardenCropMilestoneInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenCropMilestoneInventory.kt new file mode 100644 index 000000000..2c545983c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenCropMilestoneInventory.kt @@ -0,0 +1,77 @@ +package at.hannibal2.skyhanni.features.garden.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.GardenCropMilestones +import at.hannibal2.skyhanni.data.GardenCropMilestones.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 +import at.hannibal2.skyhanni.utils.LorenzUtils.indexOfFirst +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.StringUtils +import net.minecraftforge.event.entity.player.ItemTooltipEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class GardenCropMilestoneInventory { + private var average = -1.0 + private val config get() = SkyHanniMod.feature.garden + + @SubscribeEvent + fun onCropMilestoneUpdate(event: CropMilestoneUpdateEvent) { + if (!config.numberAverageCropMilestone) return + + val tiers = mutableListOf<Double>() + for (cropType in CropType.entries) { + val counter = cropType.getCounter() + val tier = GardenCropMilestones.getTierForCropCount(counter, cropType) + tiers.add(tier.toDouble()) + } + average = (tiers.sum() / CropType.entries.size).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" + } + } + + @SubscribeEvent + fun onItemTooltipLow(event: ItemTooltipEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.cropMilestoneTotalProgress) return + + val itemStack = event.itemStack ?: return + val crop = GardenCropMilestones.getCropTypeByLore(itemStack) ?: return + + val maxTier = GardenCropMilestones.getMaxTier() + val maxCounter = GardenCropMilestones.getCropsForTier(maxTier, crop) + + val index = event.toolTip.indexOfFirst( + "§5§o§7Rewards:", + ) ?: return + + val counter = crop.getCounter().toDouble() + val percentage = counter / maxCounter + val percentageFormat = LorenzUtils.formatPercentage(percentage) + + event.toolTip.add(index, " ") + val progressBar = StringUtils.progressBar(percentage) + event.toolTip.add(index, "$progressBar §e${counter.addSeparators()}§6/§e${NumberUtil.format(maxCounter)}") + event.toolTip.add(index, "§7Progress to Tier $maxTier: §e$percentageFormat") + } +}
\ No newline at end of file |