diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-15 15:57:52 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-15 15:57:52 +0200 |
commit | 18e0b6fcaa1916d87ba176755d160c6d456292f1 (patch) | |
tree | 709cf6ac79fd04b2cc5febb7eca352f23f215301 /src/main/java/at/hannibal2/skyhanni/features | |
parent | 1097c46e471a81e41849287b64b0cb4b37a778c3 (diff) | |
download | skyhanni-18e0b6fcaa1916d87ba176755d160c6d456292f1.tar.gz skyhanni-18e0b6fcaa1916d87ba176755d160c6d456292f1.tar.bz2 skyhanni-18e0b6fcaa1916d87ba176755d160c6d456292f1.zip |
Added Contest Time Needed
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
4 files changed, 154 insertions, 35 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt index 64a2ecc46..1e027b6ab 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.features.garden.composter.ComposterAPI.getLevel import at.hannibal2.skyhanni.utils.* import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators @@ -273,24 +274,13 @@ class ComposterOverlay { val fuelItem = currentFuelItem if (organicMatterItem == "" || fuelItem == "") return - val clickableList = mutableListOf<Any>() - clickableList.add("§7Per ") - for (type in TimeType.values()) { - val display = type.display - if (type == currentTimeType) { - clickableList.add("§a[$display]") - } else { - clickableList.add("§e[") - clickableList.add(Renderable.link("§e$display") { - currentTimeType = type - update() - }) - clickableList.add("§e]") - } - clickableList.add(" ") - } - newList.add(clickableList) - + newList.addSelector("§7Per ", TimeType.values(), + getName = { type -> type.display }, + isCurrent = { it == currentTimeType }, + onChange = { + currentTimeType = it + update() + }) val list = mutableListOf<Any>() list.add("§7Using: ") diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt index 27a6d1515..3f943d037 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt @@ -1,10 +1,12 @@ package at.hannibal2.skyhanni.features.garden.contest import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import io.github.moulberry.notenoughupdates.util.SkyBlockTime import net.minecraft.item.ItemStack @@ -29,6 +31,11 @@ object FarmingContestAPI { inInventory = false } + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + inInventory = false + } + fun getSbTimeFor(text: String) = timePattern.matchMatcher(text) { val month = group("month") val monthNr = LorenzUtils.getSBMonthByName(month) @@ -62,4 +69,18 @@ object FarmingContestAPI { fun getContestAtTime(time: Long) = contests[time] fun getContestsOfType(crop: CropType) = contests.values.filter { it.crop == crop } + + fun calculateAverages(crop: CropType): Pair<Int, Map<ContestRank, Int>> { + var amount = 0 + val map = mutableMapOf<ContestRank, Int>() + for (contest in getContestsOfType(crop).associateWith { it.time }.sortedDesc().keys) { + amount++ + for ((rank, count) in contest.ranks) { + val old = map.getOrDefault(rank, 0) + map[rank] = count + old + } + if (amount == 10) break + } + return Pair(amount, map.mapValues { (_, counter) -> counter / amount }) + } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt index e7b356b63..7e45a9fe3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt @@ -12,7 +12,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.round -import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import net.minecraft.item.ItemStack @@ -65,7 +64,7 @@ class JacobContestFFNeededDisplay { } addAsSingletonList("") - val (size, averages) = calculateAverages(crop) + val (size, averages) = FarmingContestAPI.calculateAverages(crop) add(listOf("§7For the last §e$size ", crop.icon, "§7${crop.cropName} contests:")) for (rank in ContestRank.values()) { addAsSingletonList(getLine(rank, averages, crop)) @@ -116,26 +115,12 @@ class JacobContestFFNeededDisplay { return " ${rank.displayName}§f: §6$farmingFortune FF §7(${counter.addSeparators()} crops)" } - private fun calculateAverages(crop: CropType): Pair<Int, Map<ContestRank, Int>> { - var amount = 0 - val map = mutableMapOf<ContestRank, Int>() - for (contest in FarmingContestAPI.getContestsOfType(crop).associateWith { it.time }.sortedDesc().keys) { - amount++ - for ((rank, count) in contest.ranks) { - val old = map.getOrDefault(rank, 0) - map[rank] = count + old - } - if (amount == 10) break - } - return Pair(amount, map.mapValues { (_, counter) -> counter / amount }) - } - @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.ChestBackgroundRenderEvent) { if (!isEnabled()) return if (!FarmingContestAPI.inInventory) return if (System.currentTimeMillis() > lastToolTipTime + 200) return - config.farmingFortuneForContestPos.renderStringsAndItems(display, posLabel = "Estimated Item Value") + config.farmingFortuneForContestPos.renderStringsAndItems(display, posLabel = "Jacob Contest Crop Data") } fun isEnabled() = LorenzUtils.inSkyBlock && config.farmingFortuneForContest diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestTimeNeeded.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestTimeNeeded.kt new file mode 100644 index 000000000..94498ed69 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestTimeNeeded.kt @@ -0,0 +1,123 @@ +package at.hannibal2.skyhanni.features.garden.contest + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LateInventoryOpenEvent +import at.hannibal2.skyhanni.features.garden.CropType +import at.hannibal2.skyhanni.features.garden.FarmingFortuneDisplay.Companion.getLatestTrueFarmingFortune +import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getLatestBlocksPerSecond +import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.LorenzUtils.sorted +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.TimeUtils +import at.hannibal2.skyhanni.utils.renderables.Renderable +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class JacobContestTimeNeeded { + private val config get() = SkyHanniMod.feature.garden + private var display = listOf<List<Any>>() + private var currentBracket = ContestRank.GOLD + + @SubscribeEvent(priority = EventPriority.LOW) + fun onLateInventoryOpen(event: LateInventoryOpenEvent) { + if (FarmingContestAPI.inInventory) { + update() + } + } + + private fun update() { + val sorted = mutableMapOf<CropType, Double>() + val map = mutableMapOf<CropType, Renderable>() + for (crop in CropType.values()) { + val speed = crop.getSpeed() + if (speed == null) { + sorted[crop] = Double.MAX_VALUE + map[crop] = Renderable.hoverTips( + "§9${crop.cropName} §cNo speed data!", + listOf("§cFarm ${crop.cropName} to show data!") + ) + continue + } + + val averages = FarmingContestAPI.calculateAverages(crop).second + if (averages.isEmpty()) { + sorted[crop] = Double.MAX_VALUE - 2 + map[crop] = Renderable.hoverTips( + "§9${crop.cropName} §cNo contest data!", + listOf( + "§cOpen more pages or participate", + "§cin a ${crop.cropName} Contest to show data!" + ) + ) + continue + } + var showLine = "" + val brackets = mutableListOf<String>() + for ((bracket, amount) in averages) { + val timeInMinutes = amount.toDouble() / speed / 60 + val formatDuration = TimeUtils.formatDuration((timeInMinutes * 60 * 1000).toLong()) + val color = if (timeInMinutes < 20) "§b" else "§c" + if (bracket == currentBracket) { + sorted[crop] = timeInMinutes + } + var bracketText = "${bracket.displayName} $color$formatDuration" + if (timeInMinutes < 20) { + showLine = "§9${crop.cropName} §b$formatDuration" + } else { + showLine = + "§9${crop.cropName} §cNo ${currentBracket.displayName} §cMedal!" + + val cropFF = crop.getLatestTrueFarmingFortune() ?: 0.0 + val blocksPerSecond = crop.getLatestBlocksPerSecond() ?: 20.0 + val cropsPerSecond = amount.toDouble() / blocksPerSecond / 60 + val ffNeeded = cropsPerSecond * 100 / 20 / crop.baseDrops + val missing = (ffNeeded - cropFF).toInt() + bracketText += " §7(${missing.addSeparators()} more FF needed!)" + } + brackets.add(bracketText) + } + map[crop] = Renderable.hoverTips(showLine, buildList { + add("§7Time Needed for §9${crop.cropName} Medals§7:") + addAll(brackets) + add("") + val cropFF = crop.getLatestTrueFarmingFortune() ?: 0.0 + add("§7Current FF: §e${(cropFF).addSeparators()}") + val bps = crop.getLatestBlocksPerSecond()?.round(1) ?: 0 + add("§7Blocks/Second: §e${bps.addSeparators()}") + + }) + } + + this.display = buildList { + addAsSingletonList("§e§lTime Needed for ${currentBracket.displayName} §eMedal!") + + addSelector("§7Bracket: ", ContestRank.values(), + getName = { type -> type.name.lowercase() }, + isCurrent = { it == currentBracket }, + onChange = { + currentBracket = it + update() + }) + addAsSingletonList("") + for (crop in sorted.sorted().keys) { + val text = map[crop]!! + add(listOf(crop.icon, text)) + } + } + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.ChestBackgroundRenderEvent) { + if (!isEnabled()) return + if (!FarmingContestAPI.inInventory) return + config.jacobContextTimesPos.renderStringsAndItems(display, posLabel = "Jacob Contest Time Needed") + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.jacobContextTimes +}
\ No newline at end of file |