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 /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | 279127f1e23d66ed7e9b2bf63c81b1100f09c0ff (diff) | |
download | skyhanni-703b97a2b49cd68eef036e6965ca78547d460d93.tar.gz skyhanni-703b97a2b49cd68eef036e6965ca78547d460d93.tar.bz2 skyhanni-703b97a2b49cd68eef036e6965ca78547d460d93.zip |
Added Total Crop Milestone
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
2 files changed, 77 insertions, 45 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 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 |