diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-11 04:04:13 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-11 04:04:13 +0100 |
commit | 219d26a54a3740dd0d3addf34a79c84275854690 (patch) | |
tree | b54565b84350e623ef3c2d0152a015cc15d0463c /src/main/java/at/hannibal2/skyhanni | |
parent | b34633e180b467536a6540c2af470846bdc83004 (diff) | |
download | skyhanni-219d26a54a3740dd0d3addf34a79c84275854690.tar.gz skyhanni-219d26a54a3740dd0d3addf34a79c84275854690.tar.bz2 skyhanni-219d26a54a3740dd0d3addf34a79c84275854690.zip |
moved GardenBestCropTime into a own class
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
4 files changed, 115 insertions, 99 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index a8f8e84a8..9c4b46fb8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -1,12 +1,15 @@ package at.hannibal2.skyhanni.features.garden +import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.GardenCropMilestones import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.GardenToolChangeEvent +import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraft.client.Minecraft import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent @@ -27,6 +30,16 @@ class GardenAPI { } } + @SubscribeEvent(priority = EventPriority.LOW) + fun onProfileJoin(event: ProfileJoinEvent) { + if (cropsPerSecond.isEmpty()) { + // TODO use enum + for (key in GardenCropMilestones.cropCounter.keys) { + cropsPerSecond[key] = -1 + } + } + } + private fun loadCropInHand(): String? { val heldItem = Minecraft.getMinecraft().thePlayer.heldItem ?: return null if (readCounter(heldItem) == -1) return null @@ -38,6 +51,7 @@ class GardenAPI { fun inGarden() = LorenzUtils.inSkyBlock && LorenzUtils.skyBlockIsland == IslandType.GARDEN var cropInHand: String? = null + val cropsPerSecond: MutableMap<String, Int> get() = SkyHanniMod.feature.hidden.gardenCropsPerSecond fun getCropTypeFromItem(heldItem: ItemStack): String? { val name = heldItem.name ?: return null @@ -76,5 +90,13 @@ class GardenAPI { } return -1 } + + fun getCropsPerSecond(itemName: String): Int? { + if (itemName.endsWith(" Mushroom")) { + return cropsPerSecond["Mushroom"] + } + return cropsPerSecond[itemName] + } + } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt new file mode 100644 index 000000000..d5920658f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt @@ -0,0 +1,84 @@ +package at.hannibal2.skyhanni.features.garden + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.GardenCropMilestones +import at.hannibal2.skyhanni.utils.LorenzUtils.sorted +import at.hannibal2.skyhanni.utils.TimeUtils +import java.util.* + +class GardenBestCropTime { + val display = mutableListOf<List<Any>>() + val timeTillNextCrop = mutableMapOf<String, Long>() + private val config get() = SkyHanniMod.feature.garden + + fun drawBestDisplay(currentCrop: String?) { + if (timeTillNextCrop.size < GardenAPI.cropsPerSecond.size) { + updateTimeTillNextCrop() + } + + val gardenExp = config.cropMilestoneBestType == 0 + val sorted = if (gardenExp) { + val helpMap = mutableMapOf<String, Long>() + for ((cropName, time) in timeTillNextCrop) { + val crops = GardenCropMilestones.cropCounter[cropName]!! + val currentTier = GardenCropMilestones.getTierForCrops(crops) + val gardenExpForTier = getGardenExpForTier(currentTier + 1) + val fakeTime = time / gardenExpForTier + helpMap[cropName] = fakeTime + } + helpMap.sorted() + } else { + timeTillNextCrop.sorted() + } + + val title = if (gardenExp) "§2Garden Experience" else "§bSkyBlock Level" + display.add(Collections.singletonList("§eBest Crop Time §7($title§7)")) + + if (sorted.isEmpty()) { + display.add(Collections.singletonList("§cFarm crops to add them to this list!")) + } + + var number = 0 + for (cropName in sorted.keys) { + val millis = timeTillNextCrop[cropName]!! + val duration = TimeUtils.formatDuration(millis) + + val isCurrent = cropName == currentCrop + val color = if (isCurrent) "§e" else "" + number++ + if (number > config.cropMilestoneShowOnlyBest && !isCurrent) continue + val cropNameDisplay = "$number# $color$cropName" + if (gardenExp) { + val crops = GardenCropMilestones.cropCounter[cropName]!! + val currentTier = GardenCropMilestones.getTierForCrops(crops) + val gardenExpForTier = getGardenExpForTier(currentTier + 1) + display.add(Collections.singletonList(" $cropNameDisplay §b$duration §7(§2$gardenExpForTier §7Exp)")) + } else { + display.add(Collections.singletonList(" $cropNameDisplay §b$duration")) + } + } + } + + private fun getGardenExpForTier(gardenLevel: Int) = if (gardenLevel > 30) 300 else gardenLevel * 10 + + fun updateTimeTillNextCrop() { + for ((cropName, speed) in GardenAPI.cropsPerSecond) { + if (speed == -1) continue + + val crops = GardenCropMilestones.cropCounter[cropName]!! + val currentTier = GardenCropMilestones.getTierForCrops(crops) + + val cropsForCurrentTier = GardenCropMilestones.getCropsForTier(currentTier) + val nextTier = currentTier + 1 + val cropsForNextTier = GardenCropMilestones.getCropsForTier(nextTier) + + val have = crops - cropsForCurrentTier + val need = cropsForNextTier - cropsForCurrentTier + + val missing = need - have + val missingTimeSeconds = missing / speed + val millis = missingTimeSeconds * 1000 + timeTillNextCrop[cropName] = millis + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt index a3dcfd131..2854aec45 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt @@ -4,7 +4,6 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.GardenCropMilestones import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.sorted import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.TimeUtils @@ -14,22 +13,11 @@ import java.util.* class GardenCropMilestoneDisplay { private val progressDisplay = mutableListOf<List<Any>>() - private val bestCropDisplay = mutableListOf<List<Any>>() private var needsInventory = false private val cultivatingData = mutableMapOf<String, Int>() - private val timeTillNextCrop = mutableMapOf<String, Long>() private val config get() = SkyHanniMod.feature.garden - companion object { - fun getCropsPerSecond(crop: String): Int? { - if (crop.endsWith(" Mushroom")) { - return cropsPerSecond["Mushroom"] - } - return cropsPerSecond[crop] - } - - private val cropsPerSecond: MutableMap<String, Int> get() = SkyHanniMod.feature.hidden.gardenCropsPerSecond - } + private val bestCropTime = GardenBestCropTime() @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { @@ -37,7 +25,7 @@ class GardenCropMilestoneDisplay { config.cropMilestoneProgressDisplayPos.renderStringsAndItems(progressDisplay) if (config.cropMilestoneBestDisplay) { - config.cropMilestoneNextDisplayPos.renderStringsAndItems(bestCropDisplay) + config.cropMilestoneNextDisplayPos.renderStringsAndItems(bestCropTime.display) } } @@ -46,17 +34,12 @@ class GardenCropMilestoneDisplay { if (GardenCropMilestones.cropCounter.values.sum() == 0L) { needsInventory = true } - if (cropsPerSecond.isEmpty()) { - for (key in GardenCropMilestones.cropCounter.keys) { - cropsPerSecond[key] = -1 - } - } } @SubscribeEvent fun onCropMilestoneUpdate(event: CropMilestoneUpdateEvent) { needsInventory = false - updateTimeTillNextCrop() + bestCropTime.updateTimeTillNextCrop() update() } @@ -96,12 +79,10 @@ class GardenCropMilestoneDisplay { if (System.currentTimeMillis() > lastSecondStart + 1_000) { lastSecondStart = System.currentTimeMillis() if (countInLastSecond > 8) { -// println("currentSpeed: $currentSpeed") allCounters.add(currentSpeed) while (allCounters.size > 30) { allCounters.removeFirst() } -// println("allCounters: $allCounters") averageSpeedPerSecond = allCounters.average().toInt() } countInLastSecond = 0 @@ -121,7 +102,7 @@ class GardenCropMilestoneDisplay { private fun update() { progressDisplay.clear() - bestCropDisplay.clear() + bestCropTime.display.clear() GardenAPI.cropInHand?.let { val crops = GardenCropMilestones.cropCounter[it] if (crops == null) { @@ -131,87 +112,16 @@ class GardenCropMilestoneDisplay { drawProgressDisplay(it, crops) if (config.cropMilestoneBestDisplay) { - drawBestDisplay(it) + bestCropTime.drawBestDisplay(it) } } if (config.cropMilestoneBestAlwaysOn) { if (GardenAPI.cropInHand == null) { - drawBestDisplay(null) - } - } - } - - private fun drawBestDisplay(currentCrop: String?) { - if (timeTillNextCrop.size < cropsPerSecond.size) { - updateTimeTillNextCrop() - } - - val gardenExp = config.cropMilestoneBestType == 0 - val sorted = if (gardenExp) { - val helpMap = mutableMapOf<String, Long>() - for ((cropName, time) in timeTillNextCrop) { - val crops = GardenCropMilestones.cropCounter[cropName]!! - val currentTier = GardenCropMilestones.getTierForCrops(crops) - val gardenExpForTier = getGardenExpForTier(currentTier + 1) - val fakeTime = time / gardenExpForTier - helpMap[cropName] = fakeTime - } - helpMap.sorted() - } else { - timeTillNextCrop.sorted() - } - - val title = if (gardenExp) "§2Garden Experience" else "§bSkyBlock Level" - bestCropDisplay.add(Collections.singletonList("§eBest Crop Time §7($title§7)")) - - if (sorted.isEmpty()) { - bestCropDisplay.add(Collections.singletonList("§cFarm crops to add them to this list!")) - } - - var number = 0 - for (cropName in sorted.keys) { - val millis = timeTillNextCrop[cropName]!! - val duration = TimeUtils.formatDuration(millis) - - val isCurrent = cropName == currentCrop - val color = if (isCurrent) "§e" else "" - number++ - if (number > config.cropMilestoneShowOnlyBest && !isCurrent) continue - val cropNameDisplay = "$number# $color$cropName" - if (gardenExp) { - val crops = GardenCropMilestones.cropCounter[cropName]!! - val currentTier = GardenCropMilestones.getTierForCrops(crops) - val gardenExpForTier = getGardenExpForTier(currentTier + 1) - bestCropDisplay.add(Collections.singletonList(" $cropNameDisplay §b$duration §7(§2$gardenExpForTier §7Exp)")) - } else { - bestCropDisplay.add(Collections.singletonList(" $cropNameDisplay §b$duration")) + bestCropTime.drawBestDisplay(null) } } } - private fun updateTimeTillNextCrop() { - for ((cropName, speed) in cropsPerSecond) { - if (speed == -1) continue - - val crops = GardenCropMilestones.cropCounter[cropName]!! - val currentTier = GardenCropMilestones.getTierForCrops(crops) - - val cropsForCurrentTier = GardenCropMilestones.getCropsForTier(currentTier) - val nextTier = currentTier + 1 - val cropsForNextTier = GardenCropMilestones.getCropsForTier(nextTier) - - val have = crops - cropsForCurrentTier - val need = cropsForNextTier - cropsForCurrentTier - - val missing = need - have - val missingTimeSeconds = missing / speed - val millis = missingTimeSeconds * 1000 - timeTillNextCrop[cropName] = millis - } - } - - private fun getGardenExpForTier(gardenLevel: Int) = if (gardenLevel > 30) 300 else gardenLevel * 10 - private fun drawProgressDisplay(it: String, crops: Long) { progressDisplay.add(Collections.singletonList("§6Crop Milestones")) @@ -242,11 +152,11 @@ class GardenCropMilestoneDisplay { progressDisplay.add(Collections.singletonList("§e$haveFormat§8/§e$needFormat")) if (averageSpeedPerSecond != 0) { - cropsPerSecond[it] = averageSpeedPerSecond + GardenAPI.cropsPerSecond[it] = averageSpeedPerSecond val missing = need - have val missingTimeSeconds = missing / averageSpeedPerSecond val millis = missingTimeSeconds * 1000 - timeTillNextCrop[it] = millis + bestCropTime.timeTillNextCrop[it] = millis val duration = TimeUtils.formatDuration(millis) progressDisplay.add(Collections.singletonList("§7in §b$duration")) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt index b783e9093..ad1718ed6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt @@ -178,7 +178,7 @@ class GardenVisitorFeatures { val rawName = NEUItems.getItemStack(multiplier.first).name ?: continue val crop = rawName.removeColor() val cropAmount = multiplier.second.toLong() * amount - GardenCropMilestoneDisplay.getCropsPerSecond(crop)?.let { + GardenAPI.getCropsPerSecond(crop)?.let { val formatAmount = LorenzUtils.formatInteger(cropAmount) val formatName = "§e${formatAmount}§7x $crop " val formatSpeed = if (it != -1) { |